Skip to content

Commit 62d80f7

Browse files
committed
server: Add junit tests to verify SeriesModelSerializer
Signed-off-by: Bernd Hufmann <[email protected]>
1 parent c7c4588 commit 62d80f7

File tree

2 files changed

+96
-1
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
    • org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/webapp

2 files changed

+96
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Ericsson and others
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License 2.0 which
6+
* accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*******************************************************************************/
11+
12+
package org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.webapp;
13+
14+
import static org.junit.Assert.assertEquals;
15+
import static org.junit.Assert.assertNotNull;
16+
import static org.junit.Assert.assertNull;
17+
import static org.junit.Assert.assertTrue;
18+
19+
import java.util.List;
20+
21+
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.webapp.OutputElementStyleSerializer;
22+
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.webapp.SeriesModelSerializer;
23+
import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.OutputElementStyleStub;
24+
import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.XySeriesStub;
25+
import org.eclipse.tracecompass.tmf.core.model.OutputElementStyle;
26+
import org.eclipse.tracecompass.tmf.core.model.SeriesModel.SeriesModelBuilder;
27+
import org.eclipse.tracecompass.tmf.core.model.StyleProperties;
28+
import org.eclipse.tracecompass.tmf.core.model.xy.ISeriesModel;
29+
import org.eclipse.tracecompass.tmf.core.model.xy.ISeriesModel.DisplayType;
30+
import org.junit.Test;
31+
32+
import com.fasterxml.jackson.core.JsonProcessingException;
33+
import com.fasterxml.jackson.databind.module.SimpleModule;
34+
35+
/**
36+
* Test the {@link SeriesModelSerializer}
37+
*
38+
* @author Bernd Hufmann
39+
*/
40+
public class SeriesModelSerializerTest extends AbstractSerializerTest {
41+
42+
private static final long ID = 0;
43+
private static final String TITLE = "valid-styles";
44+
private static final long[] times = { 0, 1, 2, 3 };
45+
private static final double[] fValues = { 0.1, 0.2, 0.3, 0.4 };
46+
47+
/**
48+
* Verify that series models are serialized properly
49+
*
50+
* @throws JsonProcessingException
51+
* if an error occurs
52+
*/
53+
@SuppressWarnings("null")
54+
@Test
55+
public void testValidStyles() throws JsonProcessingException {
56+
57+
SeriesModelBuilder builder = new SeriesModelBuilder(ID, TITLE, times, fValues);
58+
ISeriesModel lineModel = builder.build();
59+
builder.seriesDisplayType(DisplayType.SCATTER);
60+
ISeriesModel scatterModel = builder.build();
61+
62+
SimpleModule module = new SimpleModule();
63+
module.addSerializer(ISeriesModel.class, new SeriesModelSerializer());
64+
module.addSerializer(OutputElementStyle.class, new OutputElementStyleSerializer());
65+
fMapper.registerModule(module);
66+
67+
String json = fMapper.writeValueAsString(lineModel);
68+
XySeriesStub deserialized = fMapper.readValue(json, XySeriesStub.class);
69+
assertNotNull(deserialized);
70+
assertEquals(TITLE, deserialized.getName());
71+
assertEquals(ID, deserialized.getId());
72+
List<Long> xValues = deserialized.getXValues();
73+
assertTrue(times.length == xValues.size());
74+
for (int i = 0; i < times.length; i++) {
75+
assertEquals(i, times[i], xValues.get(i));
76+
}
77+
List<Double> yValues = deserialized.getYValues();
78+
assertTrue(fValues.length == yValues.size());
79+
for (int i = 0; i < fValues.length; i++) {
80+
assertEquals(fValues[i], yValues.get(i), 0.000001);
81+
}
82+
OutputElementStyleStub style = deserialized.getStyle();
83+
assertNotNull(style);
84+
assertNull(style.getParentKey());
85+
assertEquals(StyleProperties.SeriesType.LINE, style.getStyleValues().get(StyleProperties.SERIES_TYPE));
86+
87+
json = fMapper.writeValueAsString(scatterModel);
88+
deserialized = fMapper.readValue(json, XySeriesStub.class);
89+
assertNotNull(deserialized);
90+
style = deserialized.getStyle();
91+
assertNotNull(style);
92+
assertNull(style.getParentKey());
93+
assertEquals(StyleProperties.SeriesType.SCATTER, style.getStyleValues().get(StyleProperties.SERIES_TYPE));
94+
}
95+
}

trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/webapp/SeriesModelSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class SeriesModelSerializer extends StdSerializer<@NonNull ISeriesModel>
3838
/**
3939
* Constructor.
4040
*/
41-
protected SeriesModelSerializer() {
41+
public SeriesModelSerializer() {
4242
super(ISeriesModel.class);
4343
}
4444

0 commit comments

Comments
 (0)