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
56 lines (42 loc) · 2.21 KB
/
Copy pathAttributeTest.java
File metadata and controls
56 lines (42 loc) · 2.21 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
package com.gooddata.md;
import org.codehaus.jackson.map.ObjectMapper;
import org.hamcrest.Matchers;
import org.junit.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.junit.Assert.assertThat;
public class AttributeTest {
public static final String TITLE = "Person ID";
@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 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()));
}
@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"));
}
}