Skip to content

Commit 2654ee7

Browse files
committed
server: Add unit tests for BookmarkManagerService
Required unit tests have been implemented for BookmarkServiceManager class. In the tests, various aspects of bookmarking functionality (e.g., creating, updating, deleting, etc.) are checked. [Added] Required unit tests for bookmarking functionality Signed-off-by: Kaveh Shahedi <kaveh.shahedi@ericsson.com>
1 parent 22b052c commit 2654ee7

File tree

8 files changed

+550
-123
lines changed

8 files changed

+550
-123
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/services/BookmarkManagerServiceTest.java

Lines changed: 352 additions & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Ericsson
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.stubs;
13+
14+
import java.io.Serializable;
15+
import java.nio.charset.Charset;
16+
import java.util.Objects;
17+
import java.util.UUID;
18+
19+
import com.fasterxml.jackson.annotation.JsonCreator;
20+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
21+
import com.fasterxml.jackson.annotation.JsonProperty;
22+
23+
/**
24+
* A Stub class for the bookmark model. It matches the trace server protocol's
25+
* <code>BookmarkModel</code> schema
26+
*
27+
* @author Kaveh Shahedi
28+
* @since 10.1
29+
*/
30+
@JsonIgnoreProperties(ignoreUnknown = true)
31+
public class BookmarkModelStub implements Serializable {
32+
private static final long serialVersionUID = -1945923534635091200L;
33+
34+
private final UUID fUUID;
35+
private final String fName;
36+
private final long fStart;
37+
private final long fEnd;
38+
39+
/**
40+
* {@link JsonCreator} Constructor for final fields
41+
*
42+
* @param uuid
43+
* The bookmark's UUID
44+
* @param name
45+
* The bookmark name
46+
* @param start
47+
* The start time
48+
* @param end
49+
* The end time
50+
*/
51+
@JsonCreator
52+
public BookmarkModelStub(
53+
@JsonProperty("uuid") UUID uuid,
54+
@JsonProperty("name") String name,
55+
@JsonProperty("start") long start,
56+
@JsonProperty("end") long end) {
57+
fUUID = Objects.requireNonNull(uuid, "The 'UUID' json field was not set");
58+
fName = Objects.requireNonNull(name, "The 'name' json field was not set");
59+
fStart = start;
60+
fEnd = end;
61+
}
62+
63+
/**
64+
* Constructor for comparing equality
65+
*
66+
* @param name
67+
* bookmark name
68+
* @param start
69+
* start time
70+
* @param end
71+
* end time
72+
*/
73+
public BookmarkModelStub(String name, long start, long end) {
74+
this(getUUID(name), name, start, end);
75+
}
76+
77+
private static UUID getUUID(String name) {
78+
return UUID.nameUUIDFromBytes(Objects.requireNonNull(name.getBytes(Charset.defaultCharset())));
79+
}
80+
81+
/**
82+
* Get the UUID
83+
*
84+
* @return The UUID
85+
*/
86+
public UUID getUUID() {
87+
return fUUID;
88+
}
89+
90+
/**
91+
* Get the bookmark name
92+
*
93+
* @return The bookmark name
94+
*/
95+
public String getName() {
96+
return fName;
97+
}
98+
99+
/**
100+
* Get the start time
101+
*
102+
* @return The start time
103+
*/
104+
public long getStart() {
105+
return fStart;
106+
}
107+
108+
/**
109+
* Get the end time
110+
*
111+
* @return The end time
112+
*/
113+
public long getEnd() {
114+
return fEnd;
115+
}
116+
117+
@Override
118+
public boolean equals(Object obj) {
119+
if (this == obj) {
120+
return true;
121+
}
122+
if (obj == null) {
123+
return false;
124+
}
125+
if (getClass() != obj.getClass()) {
126+
return false;
127+
}
128+
BookmarkModelStub other = (BookmarkModelStub) obj;
129+
if (fEnd != other.fEnd) {
130+
return false;
131+
}
132+
if (fName == null) {
133+
if (other.fName != null) {
134+
return false;
135+
}
136+
} else if (!fName.equals(other.fName)) {
137+
return false;
138+
}
139+
if (fStart != other.fStart) {
140+
return false;
141+
}
142+
if (fUUID == null) {
143+
if (other.fUUID != null) {
144+
return false;
145+
}
146+
} else if (!fUUID.equals(other.fUUID)) {
147+
return false;
148+
}
149+
return true;
150+
}
151+
152+
153+
@Override
154+
public String toString() {
155+
return "BookmarkModelStub [fUUID=" + fUUID + ", fName=" + fName + ", fStart=" + fStart + ", fEnd=" + fEnd + "]";
156+
}
157+
158+
@Override
159+
public int hashCode() {
160+
return super.hashCode();
161+
}
162+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
package org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.webapp;
1313

14+
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.BookmarkManagerService;
1415
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.ConfigurationManagerService;
1516
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.ExperimentManagerService;
1617
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.FilterService;
@@ -52,5 +53,6 @@ protected void registerResourcesAndMappers(ResourceConfig rc) {
5253
rc.register(CORSFilter.class);
5354
rc.register(JacksonObjectMapperProvider.class);
5455
rc.register(OpenApiResource.class);
56+
rc.register(BookmarkManagerService.class);
5557
}
5658
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ public abstract class RestServerTest {
7979
* Experiments endpoint path (relative to application).
8080
*/
8181
public static final String EXPERIMENTS = "experiments";
82+
/**
83+
* Bookmarks endpoint path (relative to application).
84+
*/
85+
public static final String BOOKMARKS = "bookmarks";
8286

8387
/**
8488
* Outputs path segment

trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/model/Bookmark.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public interface Bookmark {
3030
/**
3131
* @return The bookmark UUID.
3232
*/
33-
@JsonProperty("UUID")
33+
@JsonProperty("uuid")
3434
@Schema(description = "The bookmark's unique identifier")
3535
UUID getUUID();
3636

@@ -41,13 +41,6 @@ public interface Bookmark {
4141
@Schema(description = "User defined name for the bookmark")
4242
String getName();
4343

44-
/**
45-
* @return The experiment ID.
46-
*/
47-
@NonNull
48-
@Schema(description = "The experiment's unique identifier this bookmark belongs to")
49-
String getExperimentId();
50-
5144
/**
5245
* @return The start time.
5346
*/
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Ericsson
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+
*******************************************************************************/
111
package org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services;
212

313
import java.io.Serializable;
414
import java.util.UUID;
515
import com.fasterxml.jackson.annotation.JsonCreator;
616
import com.fasterxml.jackson.annotation.JsonProperty;
7-
import com.fasterxml.jackson.databind.JsonNode;
8-
import com.fasterxml.jackson.databind.ObjectMapper;
917

1018
/**
1119
* Bookmark model for TSP
@@ -14,15 +22,13 @@
1422
* @since 10.1
1523
*/
1624
public class Bookmark implements Serializable {
17-
private static final long serialVersionUID = -3626414315455912960L;
18-
private static final ObjectMapper MAPPER = new ObjectMapper();
25+
26+
private static final long serialVersionUID = 6126770413230064175L;
1927

2028
private final UUID fUUID;
2129
private final String fName;
22-
private final String fExperimentId;
2330
private final long fStart;
2431
private final long fEnd;
25-
private final JsonNode fPayload;
2632

2733
/**
2834
* {@link JsonCreator} Constructor for final fields
@@ -31,47 +37,21 @@ public class Bookmark implements Serializable {
3137
* the stub's UUID
3238
* @param name
3339
* bookmark name
34-
* @param experimentId
35-
* experiment id
3640
* @param start
3741
* start time
3842
* @param end
3943
* end time
40-
* @param payload
41-
* additional JSON data associated with the bookmark (optional)
4244
*/
4345
@JsonCreator
4446
public Bookmark(
45-
@JsonProperty("UUID") UUID uuid,
47+
@JsonProperty("uuid") UUID uuid,
4648
@JsonProperty("name") String name,
47-
@JsonProperty("experimentId") String experimentId,
4849
@JsonProperty("start") long start,
49-
@JsonProperty("end") long end,
50-
@JsonProperty(value = "payload", required = false) JsonNode payload) {
50+
@JsonProperty("end") long end) {
5151
fUUID = uuid;
5252
fName = name;
53-
fExperimentId = experimentId;
5453
fStart = start;
5554
fEnd = end;
56-
fPayload = (payload != null) ? payload : MAPPER.createObjectNode();
57-
}
58-
59-
/**
60-
* Constructor without payload
61-
*
62-
* @param uuid
63-
* the stub's UUID
64-
* @param name
65-
* bookmark name
66-
* @param experimentId
67-
* experiment id
68-
* @param start
69-
* start time
70-
* @param end
71-
* end time
72-
*/
73-
public Bookmark(UUID uuid, String name, String experimentId, long start, long end) {
74-
this(uuid, name, experimentId, start, end, MAPPER.createObjectNode());
7555
}
7656

7757
/**
@@ -92,15 +72,6 @@ public String getName() {
9272
return fName;
9373
}
9474

95-
/**
96-
* Get the experiment id
97-
*
98-
* @return the experiment id
99-
*/
100-
public String getExperimentId() {
101-
return fExperimentId;
102-
}
103-
10475
/**
10576
* Get the start time
10677
*
@@ -119,18 +90,9 @@ public long getEnd() {
11990
return fEnd;
12091
}
12192

122-
/**
123-
* Get the payload
124-
*
125-
* @return the JSON payload, empty JSON object if no payload was set
126-
*/
127-
public JsonNode getPayload() {
128-
return fPayload;
129-
}
130-
13193
@Override
13294
public String toString() {
133-
return "Bookmark [fUUID=" + fUUID + ", fName=" + fName + ", fExperimentId=" + fExperimentId //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
134-
+ ", fStart=" + fStart + ", fEnd=" + fEnd + ", fPayload=" + fPayload + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
95+
return "Bookmark [fUUID=" + fUUID + ", fName=" + fName //$NON-NLS-1$ //$NON-NLS-2$
96+
+ ", fStart=" + fStart + ", fEnd=" + fEnd + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
13597
}
13698
}

0 commit comments

Comments
 (0)