forked from gooddata/gooddata-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetricTest.java
More file actions
41 lines (35 loc) · 1.68 KB
/
Copy pathMetricTest.java
File metadata and controls
41 lines (35 loc) · 1.68 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
/*
* Copyright (C) 2007-2014, GoodData(R) Corporation. All rights reserved.
*/
package com.gooddata.md;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.testng.annotations.Test;
import static com.gooddata.JsonMatchers.serializesToJson;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
public class MetricTest {
@Test
public void testDeserialization() throws Exception {
final Metric metric = new ObjectMapper()
.readValue(getClass().getResourceAsStream("/md/metric-out.json"), Metric.class);
assertThat(metric, is(notNullValue()));
assertThat(metric.getExpression(), is("SELECT AVG([/gdc/md/PROJECT_ID/obj/EXPR_ID])"));
assertThat(metric.getFormat(), is("#,##0"));
assertThat(metric.getMaqlAst().getPosition().getLine(), is(2));
assertThat(metric.getMaqlAst().getPosition().getColumn(), is(1));
assertThat(metric.getMaqlAst().getType(), is("metric"));
assertThat(metric.getMaqlAst().getContent().length, is(1));
}
@Test
public void testSerialization() throws Exception {
final Metric metric = new Metric("Person Name", "SELECT SUM([/gdc/md/PROJECT_ID/obj/EXPR_ID])", "FORMAT");
assertThat(metric, serializesToJson("/md/metric-new.json"));
}
@Test
public void fullJsonShouldStayTheSameAfterDeserializationAndSerializationBack() throws Exception {
final Metric metric = new ObjectMapper()
.readValue(getClass().getResourceAsStream("/md/metric-out.json"), Metric.class);
assertThat(metric, serializesToJson("/md/metric-out.json"));
}
}