Skip to content

Commit

Permalink
server: Separate setup and tear down methods in Bookmarks unit tests
Browse files Browse the repository at this point in the history
Until now, before running each individual unit tests, a new experiment would've been
created and all its previous (if any) bookmarks were deleted. Now, using Before annotation, a new
experiment will be created upon running each individual test, and then, using After annotation, all
the data related to the bookmarks will be deleted.

Signed-off-by: Kaveh Shahedi <[email protected]>
  • Loading branch information
kavehshahedi committed Nov 18, 2024
1 parent c46b124 commit f548645
Showing 1 changed file with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.BookmarkModelStub;
import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.ExperimentModelStub;
import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.utils.RestServerTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -46,8 +47,7 @@ public class BookmarkManagerServiceTest extends RestServerTest {
private static final String END = "end";

/**
* Setup method to run before each test. Creates a clean experiment and removes all
* existing bookmarks.
* Setup method to run before each test
*/
@Before
public void setUp() {
Expand All @@ -56,8 +56,14 @@ public void setUp() {
CONTEXT_SWITCHES_UST_NOT_INITIALIZED_STUB);
assertNotNull("Experiment should not be null", experiment);
assertNotNull("Experiment UUID should not be null", experiment.getUUID());
}

// Get all existing bookmarks and delete them
/**
* Tear down method to run after each test
*/
@After
public void tearDown() {
// Remove all bookmarks
WebTarget application = getApplicationEndpoint();
WebTarget bookmarkTarget = application.path(EXPERIMENTS)
.path(experiment.getUUID().toString())
Expand Down Expand Up @@ -141,6 +147,32 @@ public void testCreateBookmark() {
assertNotNull("UUID should not be null", expStub.getUUID());
}

/*
* Test the creation of a bookmark with no end time (i.e., just start time).
*/
@Test
public void testCreateBookmarkNoEndTime() {
WebTarget application = getApplicationEndpoint();
WebTarget bookmarkTarget = application.path(EXPERIMENTS)
.path(experiment.getUUID().toString())
.path(BOOKMARKS);

Map<String, Object> parameters = new HashMap<>();
parameters.put(NAME, BOOKMARK.getName());
parameters.put(START, START_TIME);
parameters.put(END, START_TIME);

Response response = bookmarkTarget.request().post(Entity.json(new QueryParameters(parameters, Collections.emptyList())));
assertEquals("Response status should be 200", 200, response.getStatus());

BookmarkModelStub expStub = response.readEntity(BookmarkModelStub.class);
assertNotNull("Response body should not be null", expStub);
assertEquals("Bookmark name should match", BOOKMARK.getName(), expStub.getName());
assertEquals("Start time should match", BOOKMARK.getStart(), expStub.getStart());
assertEquals("End time should match", BOOKMARK.getStart(), expStub.getEnd());
assertNotNull("UUID should not be null", expStub.getUUID());
}

/**
* Test the creation of a bookmark with a repetitive name.
*/
Expand Down

0 comments on commit f548645

Please sign in to comment.