forked from gooddata/gooddata-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttributeTest.java
More file actions
104 lines (84 loc) · 4.85 KB
/
Copy pathAttributeTest.java
File metadata and controls
104 lines (84 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* Copyright (C) 2004-2016, GoodData(R) Corporation. All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
package com.gooddata.md;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.hamcrest.Matchers;
import org.testng.annotations.Test;
import java.io.InputStream;
import java.util.Collection;
import static com.gooddata.JsonMatchers.serializesToJson;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.MatcherAssert.assertThat;
public class AttributeTest {
public static final String TITLE = "Person ID";
@SuppressWarnings("deprecation")
@Test
public void shouldDeserialize() throws Exception {
final InputStream stream = getClass().getResourceAsStream("/md/attribute.json");
final Attribute attribute = new ObjectMapper().readValue(stream, Attribute.class);
assertThat(attribute, is(notNullValue()));
final Collection<DisplayForm> displayForms = attribute.getDisplayForms();
assertThat(displayForms, is(notNullValue()));
assertThat(displayForms, hasSize(1));
final DisplayForm displayForm = displayForms.iterator().next();
assertThat(displayForm, is(notNullValue()));
assertThat(displayForm.getFormOf(), is("/gdc/md/PROJECT_ID/obj/DF_FORM_OF_ID"));
assertThat(displayForm.getExpression(), is("[/gdc/md/PROJECT_ID/obj/DF_EXPRESSION_ID]"));
assertThat(displayForm.getLdmExpression(), is("[/gdc/md/PROJECT_ID/obj/DF_LDM_EXPRESSION_ID]"));
final DisplayForm defaultDisplayForm = attribute.getDefaultDisplayForm();
assertThat(defaultDisplayForm, is(notNullValue()));
assertThat(defaultDisplayForm.getFormOf(), is("/gdc/md/PROJECT_ID/obj/DF_FORM_OF_ID"));
assertThat(defaultDisplayForm.getExpression(), is("[/gdc/md/PROJECT_ID/obj/DF_EXPRESSION_ID]"));
assertThat(defaultDisplayForm.getLdmExpression(), is("[/gdc/md/PROJECT_ID/obj/DF_LDM_EXPRESSION_ID]"));
final Collection<Key> primaryKeys = attribute.getPrimaryKeys();
assertThat(primaryKeys, is(Matchers.notNullValue()));
assertThat(primaryKeys, hasSize(1));
assertThat(primaryKeys.iterator().next(), is(Matchers.notNullValue()));
final Collection<Key> foreignKeys = attribute.getForeignKeys();
assertThat(foreignKeys, is(Matchers.notNullValue()));
assertThat(foreignKeys, hasSize(1));
assertThat(foreignKeys.iterator().next(), is(Matchers.notNullValue()));
assertThat(attribute.hasDimension(), is(true));
assertThat(attribute.getDimensionLink(), is("/gdc/md/PROJECT_ID/obj/DIM_ID"));
assertThat(attribute.getDimensionUri(), is("/gdc/md/PROJECT_ID/obj/DIM_ID"));
assertThat(attribute.getDirection(), is("asc"));
assertThat(attribute.getSort(), is("pk"));
assertThat(attribute.isSortedByPk(), is(true));
assertThat(attribute.isSortedByUsedDf(), is(false));
assertThat(attribute.isSortedByLinkedDf(), is(false));
assertThat(attribute.getType(), is("GDC.time.date"));
assertThat(attribute.getLinkedDisplayFormLink(), is("/gdc/md/PROJECT_ID/obj/DF_LINK"));
assertThat(attribute.getLinkedDisplayFormUri(), is("/gdc/md/PROJECT_ID/obj/DF_LINK"));
assertThat(attribute.getCompositeAttribute(), hasSize(0));
assertThat(attribute.getCompositeAttributePk(), hasSize(0));
assertThat(attribute.getFolders(), hasSize(0));
assertThat(attribute.getGrain(), hasSize(0));
assertThat(attribute.getRelations(), hasSize(0));
}
@Test
public void testSerialization() throws Exception {
final Attribute attribute = new Attribute(TITLE, new Key("/gdc/md/PROJECT_ID/obj/PK_ID", "col"),
new Key("/gdc/md/PROJECT_ID/obj/FK_ID", "col"));
assertThat(attribute, serializesToJson("/md/attribute-input.json"));
}
@Test
public void shouldSerializeSameAsDeserializationInput() throws Exception {
final InputStream stream = getClass().getResourceAsStream("/md/attribute.json");
final Attribute attribute = new ObjectMapper().readValue(stream, Attribute.class);
assertThat(attribute, serializesToJson("/md/attribute-inputOrig.json"));
}
@Test
public void shouldDeserializeAttributeWithSort() throws Exception {
final InputStream stream = getClass().getResourceAsStream("/md/attribute-sortDf.json");
final Attribute attribute = new ObjectMapper().readValue(stream, Attribute.class);
assertThat(attribute.getSort(), is("/gdc/md/PROJECT_ID/obj/1806"));
assertThat(attribute.isSortedByLinkedDf(), is(true));
assertThat(attribute.isSortedByUsedDf(), is(false));
assertThat(attribute.isSortedByPk(), is(false));
}
}