Skip to content

Commit

Permalink
server: Add unit tests for BookmarkManagerService
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
kavehshahedi authored and bhufmann committed Nov 27, 2024
1 parent b3e3509 commit 888c438
Show file tree
Hide file tree
Showing 8 changed files with 550 additions and 123 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*******************************************************************************
* 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.nio.charset.Charset;
import java.util.Objects;
import java.util.UUID;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* A Stub class for the bookmark model. It matches the trace server protocol's
* <code>BookmarkModel</code> schema
*
* @author Kaveh Shahedi
* @since 10.1
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class BookmarkModelStub implements Serializable {
private static final long serialVersionUID = -1945923534635091200L;

private final UUID fUUID;
private final String fName;
private final long fStart;
private final long fEnd;

/**
* {@link JsonCreator} Constructor for final fields
*
* @param uuid
* The bookmark's UUID
* @param name
* The bookmark name
* @param start
* The start time
* @param end
* The end time
*/
@JsonCreator
public BookmarkModelStub(
@JsonProperty("uuid") UUID uuid,
@JsonProperty("name") String name,
@JsonProperty("start") long start,
@JsonProperty("end") long end) {
fUUID = Objects.requireNonNull(uuid, "The 'UUID' json field was not set");
fName = Objects.requireNonNull(name, "The 'name' json field was not set");
fStart = start;
fEnd = end;
}

/**
* Constructor for comparing equality
*
* @param name
* bookmark name
* @param start
* start time
* @param end
* end time
*/
public BookmarkModelStub(String name, long start, long end) {
this(getUUID(name), name, start, end);
}

private static UUID getUUID(String name) {
return UUID.nameUUIDFromBytes(Objects.requireNonNull(name.getBytes(Charset.defaultCharset())));
}

/**
* Get the UUID
*
* @return The UUID
*/
public UUID getUUID() {
return fUUID;
}

/**
* Get the bookmark name
*
* @return The bookmark name
*/
public String getName() {
return fName;
}

/**
* Get the start time
*
* @return The start time
*/
public long getStart() {
return fStart;
}

/**
* Get the end time
*
* @return The end time
*/
public long getEnd() {
return fEnd;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
BookmarkModelStub other = (BookmarkModelStub) obj;
if (fEnd != other.fEnd) {
return false;
}
if (fName == null) {
if (other.fName != null) {
return false;
}
} else if (!fName.equals(other.fName)) {
return false;
}
if (fStart != other.fStart) {
return false;
}
if (fUUID == null) {
if (other.fUUID != null) {
return false;
}
} else if (!fUUID.equals(other.fUUID)) {
return false;
}
return true;
}


@Override
public String toString() {
return "BookmarkModelStub [fUUID=" + fUUID + ", fName=" + fName + ", fStart=" + fStart + ", fEnd=" + fEnd + "]";
}

@Override
public int hashCode() {
return super.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

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

import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.BookmarkManagerService;
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.ConfigurationManagerService;
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.ExperimentManagerService;
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.FilterService;
Expand Down Expand Up @@ -52,5 +53,6 @@ protected void registerResourcesAndMappers(ResourceConfig rc) {
rc.register(CORSFilter.class);
rc.register(JacksonObjectMapperProvider.class);
rc.register(OpenApiResource.class);
rc.register(BookmarkManagerService.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public abstract class RestServerTest {
* Experiments endpoint path (relative to application).
*/
public static final String EXPERIMENTS = "experiments";
/**
* Bookmarks endpoint path (relative to application).
*/
public static final String BOOKMARKS = "bookmarks";

/**
* Outputs path segment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface Bookmark {
/**
* @return The bookmark UUID.
*/
@JsonProperty("UUID")
@JsonProperty("uuid")
@Schema(description = "The bookmark's unique identifier")
UUID getUUID();

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

/**
* @return The experiment ID.
*/
@NonNull
@Schema(description = "The experiment's unique identifier this bookmark belongs to")
String getExperimentId();

/**
* @return The start time.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
/*******************************************************************************
* 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.internal.trace.server.jersey.rest.core.services;

import java.io.Serializable;
import java.util.UUID;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
* Bookmark model for TSP
Expand All @@ -14,15 +22,13 @@
* @since 10.1
*/
public class Bookmark implements Serializable {
private static final long serialVersionUID = -3626414315455912960L;
private static final ObjectMapper MAPPER = new ObjectMapper();

private static final long serialVersionUID = 6126770413230064175L;

private final UUID fUUID;
private final String fName;
private final String fExperimentId;
private final long fStart;
private final long fEnd;
private final JsonNode fPayload;

/**
* {@link JsonCreator} Constructor for final fields
Expand All @@ -31,47 +37,21 @@ public class Bookmark implements Serializable {
* the stub's UUID
* @param name
* bookmark name
* @param experimentId
* experiment id
* @param start
* start time
* @param end
* end time
* @param payload
* additional JSON data associated with the bookmark (optional)
*/
@JsonCreator
public Bookmark(
@JsonProperty("UUID") UUID uuid,
@JsonProperty("uuid") UUID uuid,
@JsonProperty("name") String name,
@JsonProperty("experimentId") String experimentId,
@JsonProperty("start") long start,
@JsonProperty("end") long end,
@JsonProperty(value = "payload", required = false) JsonNode payload) {
@JsonProperty("end") long end) {
fUUID = uuid;
fName = name;
fExperimentId = experimentId;
fStart = start;
fEnd = end;
fPayload = (payload != null) ? payload : MAPPER.createObjectNode();
}

/**
* Constructor without payload
*
* @param uuid
* the stub's UUID
* @param name
* bookmark name
* @param experimentId
* experiment id
* @param start
* start time
* @param end
* end time
*/
public Bookmark(UUID uuid, String name, String experimentId, long start, long end) {
this(uuid, name, experimentId, start, end, MAPPER.createObjectNode());
}

/**
Expand All @@ -92,15 +72,6 @@ public String getName() {
return fName;
}

/**
* Get the experiment id
*
* @return the experiment id
*/
public String getExperimentId() {
return fExperimentId;
}

/**
* Get the start time
*
Expand All @@ -119,18 +90,9 @@ public long getEnd() {
return fEnd;
}

/**
* Get the payload
*
* @return the JSON payload, empty JSON object if no payload was set
*/
public JsonNode getPayload() {
return fPayload;
}

@Override
public String toString() {
return "Bookmark [fUUID=" + fUUID + ", fName=" + fName + ", fExperimentId=" + fExperimentId //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ", fStart=" + fStart + ", fEnd=" + fEnd + ", fPayload=" + fPayload + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
return "Bookmark [fUUID=" + fUUID + ", fName=" + fName //$NON-NLS-1$ //$NON-NLS-2$
+ ", fStart=" + fStart + ", fEnd=" + fEnd + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}
Loading

0 comments on commit 888c438

Please sign in to comment.