From 8379bc5bef4568b9fb950c074bde272d44690180 Mon Sep 17 00:00:00 2001 From: Bernd Hufmann Date: Tue, 17 Dec 2024 13:02:21 -0500 Subject: [PATCH] server.tests: Add tests for querying marker sets and annotations Signed-off-by: Bernd Hufmann --- .../config/markers.xml | 17 ++ .../plugin.xml | 6 + .../services/DataProviderServiceTest.java | 22 +++ .../TimeGraphDataProviderServiceTest.java | 146 +++++++++++++++++- .../stubs/AnnotationCategoriesModelStub.java | 47 ++++++ ...nnotationCategoriesOutputResponseStub.java | 53 +++++++ .../core/tests/stubs/AnnotationModelStub.java | 48 ++++++ .../tests/stubs/AnnotationResponseStub.java | 53 +++++++ .../rest/core/tests/stubs/AnnotationStub.java | 120 ++++++++++++++ .../rest/core/tests/stubs/MarkerSetStub.java | 98 ++++++++++++ .../stubs/MarkerSetsOutputResponseStub.java | 55 +++++++ .../rest/core/tests/utils/RestServerTest.java | 80 ++++++++++ 12 files changed, 744 insertions(+), 1 deletion(-) create mode 100644 trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/config/markers.xml create mode 100644 trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationCategoriesModelStub.java create mode 100644 trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationCategoriesOutputResponseStub.java create mode 100644 trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationModelStub.java create mode 100644 trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationResponseStub.java create mode 100644 trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationStub.java create mode 100644 trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/MarkerSetStub.java create mode 100644 trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/MarkerSetsOutputResponseStub.java diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/config/markers.xml b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/config/markers.xml new file mode 100644 index 000000000..ab5063ab4 --- /dev/null +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/config/markers.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/plugin.xml b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/plugin.xml index cbf808d03..42b23877c 100644 --- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/plugin.xml +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/plugin.xml @@ -15,4 +15,10 @@ id="org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.TestDataProviderFactory"> + + + + diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/services/DataProviderServiceTest.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/services/DataProviderServiceTest.java index 065caecb0..c40a54ce4 100644 --- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/services/DataProviderServiceTest.java +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/services/DataProviderServiceTest.java @@ -12,9 +12,11 @@ package org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.services; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.util.List; import java.util.Set; import javax.ws.rs.client.WebTarget; @@ -23,6 +25,8 @@ import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.DataProviderService; import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.DataProviderDescriptorStub; import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.ExperimentModelStub; +import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.MarkerSetStub; +import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.MarkerSetsOutputResponseStub; import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.utils.RestServerTest; import org.junit.Test; @@ -69,4 +73,22 @@ public void testProvider() { assertEquals(EXPECTED_CALLSTACK_PROVIDER_DESCRIPTOR, descriptor); } + + /** + * Test of getting marker sets + * + * Note: For this test a marker set extension is defined in the plugin.xml + * of this test plug-in. + */ + @Test + public void testGetMarkerSets() { + ExperimentModelStub exp = assertPostExperiment(sfContextSwitchesUstNotInitializedStub.getName(), sfContextSwitchesUstNotInitializedStub); + + MarkerSetsOutputResponseStub outputResponseStub = getMarkerSetsEndpoint(exp.getUUID().toString()).request(MediaType.APPLICATION_JSON).get(MarkerSetsOutputResponseStub.class); + assertNotNull(outputResponseStub); + List markerSets = outputResponseStub.getModel(); + assertFalse(markerSets.isEmpty()); + assertEquals("Example", markerSets.get(0).getName()); + assertEquals("example.id", markerSets.get(0).getId()); + } } diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/services/TimeGraphDataProviderServiceTest.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/services/TimeGraphDataProviderServiceTest.java index 22c938d28..1e15d63d7 100644 --- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/services/TimeGraphDataProviderServiceTest.java +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/services/TimeGraphDataProviderServiceTest.java @@ -33,6 +33,7 @@ import javax.ws.rs.ProcessingException; import javax.ws.rs.client.Entity; import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; @@ -41,6 +42,10 @@ import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.model.views.QueryParameters; import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.DataProviderService; import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants; +import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.AnnotationCategoriesOutputResponseStub; +import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.AnnotationModelStub; +import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.AnnotationResponseStub; +import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.AnnotationStub; import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.ExperimentModelStub; import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.OutputElementStyleStub; import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.OutputStyleModelStub; @@ -58,6 +63,7 @@ import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.webapp.TestDataProviderService; import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.utils.RestServerTest; import org.eclipse.tracecompass.internal.tmf.core.model.filters.FetchParametersUtils; +import org.eclipse.tracecompass.tmf.core.model.annotations.IAnnotation.AnnotationType; import org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter; import org.junit.Test; @@ -74,11 +80,16 @@ @SuppressWarnings({"null", "restriction"}) public class TimeGraphDataProviderServiceTest extends RestServerTest { + private static final String UST_CATEGORY_NAME = "ust"; + private static final String SLOT_CATEGORY_NAME = "Slot"; + private static final String CTX_SWITCH_EXPERIMENT = "ctxSwitchExperiment"; private static final String THREAD_STATUS_DP_ID = "org.eclipse.tracecompass.internal.analysis.os.linux.core.threadstatus.ThreadStatusDataProvider"; private static final String DATA_PROVIDER_RESPONSE_FAILED_MSG = "There should be a positive response for the data provider"; private static final String MODEL_NULL_MSG = "The model is null, maybe the analysis did not run long enough?"; private static final int MAX_ITER = 40; private static final String REQUESTED_TIMERANGE_KEY = "requested_timerange"; + private static final String REQUESTED_CATAGORIES_KEY = "requested_marker_categories"; + private static final String REQUESTED_MARKERSET_ID_KEY = "requested_marker_set"; private static final String REQUESTED_ITEMS_KEY = "requested_items"; private static final String REQUESTED_ELEMENT_KEY = "requested_element"; private static final String ELEMENT_TYPE = "elementType"; @@ -209,6 +220,140 @@ public void testArrowsErrors() { executePostErrorTests(exp, RestServerTest::getArrowsEndpoint, THREAD_STATUS_DP_ID, true); } + /** + * Tests querying annotation categories for a time graph data provider + */ + @Test + public void testAnnotationCategories() { + ExperimentModelStub exp = assertPostExperiment(CTX_SWITCH_EXPERIMENT, sfContextSwitchesKernelNotInitializedStub, sfContextSwitchesUstNotInitializedStub); + + // Get ust category + WebTarget categoriesEndpoint = getAnnotationCategoriesEndpoint(exp.getUUID().toString(), THREAD_STATUS_DP_ID, "unknown.annotation.cat.id"); + AnnotationCategoriesOutputResponseStub annotationCategoriesModel = categoriesEndpoint.request(MediaType.APPLICATION_JSON).get(AnnotationCategoriesOutputResponseStub.class); + assertNotNull(annotationCategoriesModel); + assertFalse(annotationCategoriesModel.getModel().getAnnotationCategories().isEmpty()); + List categories = annotationCategoriesModel.getModel().getAnnotationCategories(); + assertFalse(categories.isEmpty()); + assertTrue(categories.contains(UST_CATEGORY_NAME)); + + // get category from marker set + categoriesEndpoint = getAnnotationCategoriesEndpoint(exp.getUUID().toString(), THREAD_STATUS_DP_ID, "example.id"); + annotationCategoriesModel = categoriesEndpoint.request(MediaType.APPLICATION_JSON).get(AnnotationCategoriesOutputResponseStub.class); + + assertNotNull(annotationCategoriesModel); + categories = annotationCategoriesModel.getModel().getAnnotationCategories(); + assertFalse(categories.isEmpty()); + List expectedCategories = List.of("Frame", "Subframe", SLOT_CATEGORY_NAME); + assertTrue(categories.containsAll(expectedCategories)); + } + + /** + * Tests error cases when querying annotation categories for a time graph data provider + */ + @Test + public void testAnnotationCategoriesErrors() { + ExperimentModelStub exp = assertPostExperiment(sfContextSwitchesKernelNotInitializedStub.getName(), sfContextSwitchesKernelNotInitializedStub); + // Invalid UUID string + WebTarget endpoint = getAnnotationCategoriesEndpoint(INVALID_EXP_UUID, THREAD_STATUS_DP_ID); + try (Response response = endpoint.request(MediaType.APPLICATION_JSON).get()) { + assertNotNull(response); + assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); + } + + // Unknown experiment + endpoint = getAnnotationCategoriesEndpoint(UUID.randomUUID().toString(), THREAD_STATUS_DP_ID); + try (Response response = endpoint.request(MediaType.APPLICATION_JSON).get()) { + assertNotNull(response); + assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); + assertEquals(EndpointConstants.NO_SUCH_TRACE, response.readEntity(String.class)); + } + + // Unknown data provider + endpoint = getAnnotationCategoriesEndpoint(exp.getUUID().toString(), UNKNOWN_DP_ID); + try (Response response = endpoint.request(MediaType.APPLICATION_JSON).get()) { + assertNotNull(response); + assertEquals(Status.METHOD_NOT_ALLOWED.getStatusCode(), response.getStatus()); + assertEquals(EndpointConstants.NO_PROVIDER, response.readEntity(String.class)); + } + } + + /** + * Tests querying annotation for a time graph data provider + * + * @throws InterruptedException + * if such exception occurred + */ + @Test + public void testAnnotations() throws InterruptedException { + ExperimentModelStub exp = assertPostExperiment(CTX_SWITCH_EXPERIMENT, sfContextSwitchesKernelNotInitializedStub, sfContextSwitchesUstNotInitializedStub); + Set entries = loadDataProvider(exp, THREAD_STATUS_DP_ID); + + Map parameters = new HashMap<>(); + parameters.remove(REQUESTED_TIMES_KEY); + parameters.put(REQUESTED_TIMERANGE_KEY, ImmutableMap.of(START, 1450193722866679365L, END, 1450193722881450790L, NB_TIMES, 500)); + parameters.put(REQUESTED_MARKERSET_ID_KEY, "example.id"); + List categories = List.of("Frame", "Subframe", SLOT_CATEGORY_NAME, UST_CATEGORY_NAME); + parameters.put(REQUESTED_CATAGORIES_KEY, categories); + + // Find specific thread entry + final String threadNameForTooltip = "lemon_server"; + Optional threadOptional = entries.stream().filter( + entry -> threadNameForTooltip.equals(entry.getLabels().get(0)) && entry.getLabels().get(1).equals("592")).findFirst(); + assertTrue(threadOptional.isPresent()); + parameters.put(REQUESTED_ITEMS_KEY, List.of(threadOptional.get().getId())); + + WebTarget annoationEndpoint = getAnnotationEndpoint(exp.getUUID().toString(), THREAD_STATUS_DP_ID); + try (Response response = annoationEndpoint.request().post(Entity.json(new QueryParameters(parameters, Collections.emptyList())))) { + assertNotNull(response); + assertEquals(Status.OK.getStatusCode(), response.getStatus()); + AnnotationResponseStub modelResponse = response.readEntity(AnnotationResponseStub.class); + assertNotNull(modelResponse); + + AnnotationModelStub annotationModel = modelResponse.getModel(); + assertNotNull(annotationModel); + Map> annotationsMap = annotationModel.getAnnotations(); + assertFalse(annotationsMap.isEmpty()); + for (String category : categories) { + assertTrue(annotationsMap.containsKey(category)); + Collection annotations = annotationsMap.get(category); + assertNotNull(annotations); + assertFalse(annotations.isEmpty()); + } + + Collection annotations = annotationsMap.get(SLOT_CATEGORY_NAME); + assertNotNull(annotations); + AnnotationStub annotation = annotations.iterator().next(); + + // Verify first annotation created from marker set and category Slot + assertEquals(1450193722866500000L, annotation.getTime()); + assertEquals(500000, annotation.getDuration()); + assertEquals(-1, annotation.getEntryId()); + assertEquals("1", annotation.getLabel()); + assertEquals(AnnotationType.CHART.name(), annotation.getType()); + assertNotNull(annotation.getStyle()); + + // Verify first annotation created from category ust for specific thread + annotations = annotationsMap.get(UST_CATEGORY_NAME); + assertNotNull(annotations); + annotation = annotations.iterator().next(); + assertEquals(1450193722867264709L, annotation.getTime()); + assertEquals(0, annotation.getDuration()); + assertEquals(threadOptional.get().getId(), annotation.getEntryId()); + assertEquals("lttng_ust_tracef:event", annotation.getLabel()); + assertEquals(AnnotationType.CHART.name(), annotation.getType()); + assertNotNull(annotation.getStyle()); + } + } + + /** + * Tests error cases when querying annotation for a time graph data provider + */ + @Test + public void testAnnotationErrors() { + ExperimentModelStub exp = assertPostExperiment(sfContextSwitchesKernelNotInitializedStub.getName(), sfContextSwitchesKernelNotInitializedStub); + executePostErrorTests(exp, RestServerTest::getAnnotationEndpoint, THREAD_STATUS_DP_ID, true); + } + private static void testGetStates(String filterStrategy) throws InterruptedException { try { ExperimentModelStub exp = assertPostExperiment(sfContextSwitchesUstNotInitializedStub.getName(), sfContextSwitchesUstNotInitializedStub); @@ -503,5 +648,4 @@ private static void executePostErrorTests (ExperimentModelStub exp, IEndpointRes assertEquals(EndpointConstants.NO_PROVIDER, response.readEntity(String.class)); } } - } diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationCategoriesModelStub.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationCategoriesModelStub.java new file mode 100644 index 000000000..b137f38cf --- /dev/null +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationCategoriesModelStub.java @@ -0,0 +1,47 @@ +/********************************************************************** + * Copyright (c) 2024 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License 2.0 which + * accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + **********************************************************************/ + +package org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs; + +import java.io.Serializable; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Basic Implementation of the serialized annotation category used by clients. + * + * @author Bernd Hufmann + */ +public class AnnotationCategoriesModelStub implements Serializable{ + + private static final long serialVersionUID = -7146696718088222398L; + private final List fAnnotationCategories; + + /** + * Constructor + * + * @param annotationCategories + * List of categories + */ + public AnnotationCategoriesModelStub(@JsonProperty("annotationCategories") List annotationCategories) { + fAnnotationCategories = annotationCategories; + } + + /** + * Annotation categories for the model + * + * @return List of categories + */ + public List getAnnotationCategories() { + return fAnnotationCategories; + } +} diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationCategoriesOutputResponseStub.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationCategoriesOutputResponseStub.java new file mode 100644 index 000000000..f49d618e3 --- /dev/null +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationCategoriesOutputResponseStub.java @@ -0,0 +1,53 @@ +/********************************************************************** + * Copyright (c) 2024 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License 2.0 which + * accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + **********************************************************************/ +package org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * A stub class for the response to a Annotation Categories' request. It contains + * the generic response, as well as an lsit of {@link AnnotationCategoriesModelStub} + * + * @author Bernd Hufmann + */ +public class AnnotationCategoriesOutputResponseStub extends OutputResponseStub { + + private static final long serialVersionUID = -2547573713331714274L; + private final AnnotationCategoriesModelStub fModel; + + /** + * {@link JsonCreator} Constructor from json + * + * @param model + * The model for this response + * @param status + * The status of the response + * @param statusMessage + * The custom status message of the response + */ + public AnnotationCategoriesOutputResponseStub(@JsonProperty("model") AnnotationCategoriesModelStub model, + @JsonProperty("status") String status, + @JsonProperty("statusMessage") String statusMessage) { + super(status, statusMessage); + fModel = model; + } + + /** + * Get the model for this response + * + * @return The model for the response + */ + public AnnotationCategoriesModelStub getModel() { + return fModel; + } + +} diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationModelStub.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationModelStub.java new file mode 100644 index 000000000..4ae16b7ce --- /dev/null +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationModelStub.java @@ -0,0 +1,48 @@ +/********************************************************************** + * Copyright (c) 2024 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License 2.0 which + * accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + **********************************************************************/ + +package org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs; + +import java.io.Serializable; +import java.util.Collection; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Basic Implementation of the serialized annotation model used by clients. + * + * @author Bernd Hufmann + */ +public class AnnotationModelStub implements Serializable{ + + private static final long serialVersionUID = -8294862755091478069L; + + private final Map> fAnnotations; + + /** + * Constructor + * + * @param annotations + * Map of annotations per category + */ + public AnnotationModelStub(@JsonProperty("annotations") Map> annotations) { + fAnnotations = annotations; + } + + /** + * Annotations for the model + * + * @return Map of annotations per category + */ + public Map> getAnnotations() { + return fAnnotations; + }} diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationResponseStub.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationResponseStub.java new file mode 100644 index 000000000..8e431261b --- /dev/null +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationResponseStub.java @@ -0,0 +1,53 @@ +/********************************************************************** + * Copyright (c) 2024 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License 2.0 which + * accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + **********************************************************************/ +package org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * A stub class for the response to a Annotation Model's request. It contains + * the generic response, as well as an lsit of {@link AnnotationCategoriesModelStub} + * + * @author Bernd Hufmann + */ +public class AnnotationResponseStub extends OutputResponseStub { + + private static final long serialVersionUID = -2547573713331714274L; + private final AnnotationModelStub fModel; + + /** + * {@link JsonCreator} Constructor from json + * + * @param model + * The model for this response + * @param status + * The status of the response + * @param statusMessage + * The custom status message of the response + */ + public AnnotationResponseStub(@JsonProperty("model") AnnotationModelStub model, + @JsonProperty("status") String status, + @JsonProperty("statusMessage") String statusMessage) { + super(status, statusMessage); + fModel = model; + } + + /** + * Get the model for this response + * + * @return The model for the response + */ + public AnnotationModelStub getModel() { + return fModel; + } + +} diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationStub.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationStub.java new file mode 100644 index 000000000..1ce2349e1 --- /dev/null +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/AnnotationStub.java @@ -0,0 +1,120 @@ +/********************************************************************** + * Copyright (c) 2024 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License 2.0 which + * accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + **********************************************************************/ + +package org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs; + +import java.io.Serializable; + +import org.eclipse.jdt.annotation.Nullable; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Basic Implementation of the serialized annotation used by clients. + * + * @author Bernd Hufmann + */ +public class AnnotationStub implements Serializable{ + + private static final long serialVersionUID = -1493443168095328737L; + private final @Nullable String fLabel; + private final long fTime; + private final long fDuration; + private final long fEntryId; + private final String fType; + private final OutputElementStyleStub fStyle; + + /** + * Constructor + * + * @param time + * Annotation start time + * @param duration + * Annotation duration + * @param entryId + * EntryId to position the annotation or -1 if it is not attached + * to a single entry + * @param type + * Annotation type + * @param label + * Annotation label for display purposes + * @param style + * Style to use for this annotation + */ + public AnnotationStub(@JsonProperty("time") long time, + @JsonProperty("duration") long duration, + @JsonProperty("entryId") long entryId, + @JsonProperty("type") String type, + @JsonProperty("label") @Nullable String label, + @JsonProperty("style") OutputElementStyleStub style) { + fTime = time; + fDuration = duration; + fEntryId = entryId; + fType = type; + fLabel = label; + fStyle = style; + } + + /** + * Get the annotation time, for chart annotations. + * + * @return Annotation time + */ + public long getTime() { + return fTime; + } + + /** + * Get the duration + * + * @return Duration + */ + public long getDuration() { + return fDuration; + } + + /** + * Get the entry model ID. + * + * @return Entry model ID associated to this annotation or -1 if this + * annotation is not attached to a single entry + */ + public long getEntryId() { + return fEntryId; + } + + /** + * Get the annotation type. + * + * @return Annotation type + */ + public String getType() { + return fType; + } + + /** + * Get the annotation label. + * + * @return Annotation label or null + */ + public @Nullable String getLabel() { + return fLabel; + } + + /** + * Get the style associated with this element + * + * @return {@link OutputElementStyleStub} describing the style of this element + */ + public @Nullable OutputElementStyleStub getStyle() { + return fStyle; + } +} diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/MarkerSetStub.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/MarkerSetStub.java new file mode 100644 index 000000000..cb3317c87 --- /dev/null +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/MarkerSetStub.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2023 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License 2.0 which + * accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ + +package org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs; + +import java.io.Serializable; +import java.util.Objects; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Basic Implementation of the serialized marker set model used by clients. + * + * @author Bernd Hufmann + */ +public class MarkerSetStub implements Serializable { + + private static final long serialVersionUID = 1L; + /** + * Generated Serial Version UID + */ + private final String fId; + private final String fName; + + /** + * {@link JsonCreator} Constructor for final fields + * + * @param id + * the id + * @param name + * the name + */ + @JsonCreator + public MarkerSetStub(@JsonProperty("id") String id, + @JsonProperty("name") String name) { + fId = id; + fName = name; + } + + /** + * Gets the ID + * + * @return the ID + */ + public String getId() { + return fId; + } + + /** + * Gets the name + * + * @return the name + */ + public String getName() { + return fName; + } + + @Override + public String toString() { + return "MarkerSetStub[fId=" + getId() + ", fName=" + fName + "]"; + } + + @Override + public int hashCode() { + return Objects.hash(fId, fName); + } + + @Override + public boolean equals(Object obj) { + + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + + if (obj instanceof MarkerSetStub) { + MarkerSetStub other = (MarkerSetStub) obj; + if (!Objects.equals(fId, other.fId)) { + return false; + } + if (!Objects.equals(fName, other.fName)) { + return false; + } + } + return false; + } +} diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/MarkerSetsOutputResponseStub.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/MarkerSetsOutputResponseStub.java new file mode 100644 index 000000000..1b147afda --- /dev/null +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/MarkerSetsOutputResponseStub.java @@ -0,0 +1,55 @@ +/********************************************************************** + * Copyright (c) 2024 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License 2.0 which + * accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + **********************************************************************/ +package org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * A stub class for the response to a Marker Sets' request. It contains + * the generic response, as well as an lsit of {@link MarkerSetStub} + * + * @author Bernd Hufmann + */ +public class MarkerSetsOutputResponseStub extends OutputResponseStub { + + private static final long serialVersionUID = -2103307674960234620L; + private final List fModel; + + /** + * {@link JsonCreator} Constructor from json + * + * @param model + * The model for this response + * @param status + * The status of the response + * @param statusMessage + * The custom status message of the response + */ + public MarkerSetsOutputResponseStub(@JsonProperty("model") List model, + @JsonProperty("status") String status, + @JsonProperty("statusMessage") String statusMessage) { + super(status, statusMessage); + fModel = model; + } + + /** + * Get the model for this response + * + * @return The model for the response + */ + public List getModel() { + return fModel; + } + +} diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/utils/RestServerTest.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/utils/RestServerTest.java index 8a40e94b0..63499fbbb 100644 --- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/utils/RestServerTest.java +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/utils/RestServerTest.java @@ -137,6 +137,11 @@ public abstract class RestServerTest { */ public static final String OUTPUTS_PATH = "outputs"; + /** + * Marker sets path segment + */ + public static final String MARKER_SETS = "markerSets"; + /** * Tree path segment */ @@ -187,6 +192,11 @@ public abstract class RestServerTest { */ public static final String STYLES_PATH = "style"; + /** + * Annotation path segment + */ + public static final String ANNOTATIONS_PATH = "annotations"; + /** * Column path segment */ @@ -628,6 +638,8 @@ public static WebTarget getDpCreationEndpoint(String expUUID, String dataProvide .path(dataProviderId); } + + /** * Get the traces currently open on the server. * @@ -661,6 +673,19 @@ public static Set getDataProviderDescriptors(WebTarg return outputs.request(MediaType.APPLICATION_JSON).get(DATAPROVIDER_DESCR_MODEL_SET_TYPE); } + /** + * Get the {@link WebTarget} for the experiment's marker sets + * + * @param expUUID + * Experiment UUID + * @return marker sets model + */ + public static WebTarget getMarkerSetsEndpoint(String expUUID) { + return getApplicationEndpoint().path(EXPERIMENTS) + .path(expUUID) + .path(OUTPUTS_PATH) + .path(MARKER_SETS); + } /** * Get the {@link WebTarget} for the data provider styles tree endpoint. @@ -679,6 +704,61 @@ public static WebTarget getStylesEndpoint(String expUUID, String dataProviderId) .path(STYLES_PATH); } + + /** + * Get the {@link WebTarget} for the time graph data provider annotation categories endpoint. + * + * @param expUUID + * Experiment UUID + * @param dataProviderId + * Data provider ID + * @param markerSetId + * The marker set ID + * @return The time graph tree endpoint + */ + public static WebTarget getAnnotationCategoriesEndpoint(String expUUID, String dataProviderId, String markerSetId) { + WebTarget webTarget = getApplicationEndpoint() + .path(EXPERIMENTS) + .path(expUUID) + .path(OUTPUTS_PATH) + .path(dataProviderId) + .path(ANNOTATIONS_PATH); + if (markerSetId != null) { + webTarget = webTarget.queryParam("markerSetId", markerSetId); + } + return webTarget; + } + + /** + * Get the {@link WebTarget} for the time graph data provider annotation categories endpoint. + * + * @param expUUID + * Experiment UUID + * @param dataProviderId + * Data provider ID + * @return The time graph tree endpoint + */ + public static WebTarget getAnnotationCategoriesEndpoint(String expUUID, String dataProviderId) { + return getAnnotationCategoriesEndpoint(expUUID, dataProviderId, null); + } + + /** + * Get the {@link WebTarget} for the time graph data provider annotation endpoint. + * + * @param expUUID + * Experiment UUID + * @param dataProviderId + * Data provider ID + * @return The time graph tree endpoint + */ + public static WebTarget getAnnotationEndpoint(String expUUID, String dataProviderId) { + return getApplicationEndpoint().path(EXPERIMENTS) + .path(expUUID) + .path(OUTPUTS_PATH) + .path(dataProviderId) + .path(ANNOTATIONS_PATH); + } + /** * Post the trace from an expected {@link TraceModelStub}, ensure that the post * returned correctly and that the returned model was that of the expected stub.