Skip to content

Commit 009be31

Browse files
committed
server.tests: Use TSP client in OutputElementStyleSerializerTest
Disable MapperFeature.ALLOW_COERCION_OF_SCALARS so that StateValue.deserialize() only tries to deserialize the received type and not the others, which would cause a parse exception. Signed-off-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
1 parent 2ad3d94 commit 009be31

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/webapp/AbstractSerializerTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
import org.junit.Before;
1515

16+
import com.fasterxml.jackson.databind.MapperFeature;
1617
import com.fasterxml.jackson.databind.ObjectMapper;
18+
import com.fasterxml.jackson.databind.json.JsonMapper;
1719

1820
/**
1921
* Abstract test class for testing serializers
@@ -33,6 +35,6 @@ public class AbstractSerializerTest {
3335
*/
3436
@Before
3537
public void setup() {
36-
fMapper = new ObjectMapper();
38+
fMapper = JsonMapper.builder().configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, false).build();
3739
}
3840
}

trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/webapp/OutputElementStyleSerializerTest.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.util.Map.Entry;
2121

2222
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.webapp.OutputElementStyleSerializer;
23-
import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.OutputElementStyleStub;
23+
import org.eclipse.tracecompass.incubator.tsp.client.core.model.StyleValue;
2424
import org.eclipse.tracecompass.tmf.core.model.OutputElementStyle;
2525
import org.eclipse.tracecompass.tmf.core.model.StyleProperties;
2626
import org.junit.Test;
@@ -61,7 +61,7 @@ public void testValidStyles() throws JsonProcessingException {
6161
OutputElementStyle testStyle = new OutputElementStyle(VALID_STYLE_NAME, validStyles);
6262
String json = fMapper.writeValueAsString(testStyle);
6363

64-
OutputElementStyleStub deserialized = fMapper.readValue(json, OutputElementStyleStub.class);
64+
org.eclipse.tracecompass.incubator.tsp.client.core.model.OutputElementStyle deserialized = fMapper.readValue(json, org.eclipse.tracecompass.incubator.tsp.client.core.model.OutputElementStyle.class);
6565
assertEquals(testStyle.getParentKey(), deserialized.getParentKey());
6666

6767
verifyStyles(testStyle, deserialized);
@@ -90,7 +90,7 @@ public void testMappedStyles() throws JsonProcessingException {
9090
OutputElementStyle testStyle = new OutputElementStyle(MAPPED_STYLE_NAME, mappedStyles);
9191
String json = fMapper.writeValueAsString(testStyle);
9292

93-
OutputElementStyleStub deserialized = fMapper.readValue(json, OutputElementStyleStub.class);
93+
org.eclipse.tracecompass.incubator.tsp.client.core.model.OutputElementStyle deserialized = fMapper.readValue(json, org.eclipse.tracecompass.incubator.tsp.client.core.model.OutputElementStyle.class);
9494
assertEquals(testStyle.getParentKey(), deserialized.getParentKey());
9595

9696
verifyStyles(testStyle, deserialized);
@@ -117,24 +117,26 @@ public void testInvalidStyles() throws JsonProcessingException {
117117
OutputElementStyle testStyle = new OutputElementStyle(INVALID_STYLE_NAME, invalidStyles);
118118
String json = fMapper.writeValueAsString(testStyle);
119119

120-
OutputElementStyleStub deserialized = fMapper.readValue(json, OutputElementStyleStub.class);
120+
org.eclipse.tracecompass.incubator.tsp.client.core.model.OutputElementStyle deserialized = fMapper.readValue(json, org.eclipse.tracecompass.incubator.tsp.client.core.model.OutputElementStyle.class);
121121
assertEquals(testStyle.getParentKey(), deserialized.getParentKey());
122-
assertTrue(deserialized.getStyleValues().isEmpty());
122+
assertTrue(deserialized.getValues().isEmpty());
123123
}
124124

125-
private static void verifyStyles(OutputElementStyle testStyle, OutputElementStyleStub deserialized) {
125+
private static void verifyStyles(OutputElementStyle testStyle, org.eclipse.tracecompass.incubator.tsp.client.core.model.OutputElementStyle deserialized) {
126126
for (Entry<String, Object> entry : testStyle.getStyleValues().entrySet()) {
127-
Map<String, Object> styleValues = deserialized.getStyleValues();
127+
Map<String, StyleValue> styleValues = deserialized.getValues();
128128
assertNotNull(styleValues);
129129
String key = entry.getKey();
130130
Object entryValue = entry.getValue();
131131
assertTrue(key, styleValues.containsKey(key));
132+
StyleValue val = styleValues.get(key);
133+
assertNotNull(val);
132134
if (entryValue instanceof Float || entryValue instanceof Double) {
133-
assertEquals(key, Double.valueOf(entryValue.toString()), styleValues.get(key));
135+
assertEquals(key, Double.valueOf(entryValue.toString()), val.getDouble());
134136
} else if (entryValue instanceof Number longValue) {
135-
assertEquals(key, longValue.intValue(), styleValues.get(key));
137+
assertEquals(key, longValue.intValue(), (val.getInteger().intValue()));
136138
} else {
137-
assertEquals(key, entryValue, styleValues.get(key));
139+
assertEquals(key, entryValue, val.getString());
138140
}
139141
}
140142
}

0 commit comments

Comments
 (0)