Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Seddik Yengui <seddik.yengui@rte-france.com>
  • Loading branch information
Seddik Yengui committed Oct 15, 2024
1 parent c6c069d commit 6c863e7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ private void moveElementDirectory(DirectoryElementEntity element, UUID newDirect
repositoryService.reindexElements(descendents);

// if it has a parent, we notify it.
// otherwise, which means it is a root, we send a notification that a root has been deleted (in this case, it is moved under a new directory)
// otherwise, which means it is a root, we send a notification that a root has been deleted (in this case, it moved under a new directory)
if (oldDirectory != null) {
notifyDirectoryHasChanged(oldDirectory.getId(), userId, element.getName(), isDirectory);
} else {
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/org/gridsuite/directory/server/DirectoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ public void testMoveDirectory() throws Exception {
assertEquals(rootDir20Uuid, headers.get(HEADER_DIRECTORY_UUID));
assertEquals(true, headers.get(HEADER_IS_ROOT_DIRECTORY));
assertEquals(true, headers.get(HEADER_IS_PUBLIC_DIRECTORY));
assertEquals(true, headers.get(HEADER_IS_DIRECTORY_MOVING));
assertEquals(NotificationType.UPDATE_DIRECTORY, headers.get(HEADER_NOTIFICATION_TYPE));
assertEquals(UPDATE_TYPE_DIRECTORIES, headers.get(HEADER_UPDATE_TYPE));

Expand All @@ -612,8 +613,40 @@ public void testMoveDirectory() throws Exception {
assertEquals(rootDir10Uuid, headers.get(HEADER_DIRECTORY_UUID));
assertEquals(true, headers.get(HEADER_IS_ROOT_DIRECTORY));
assertEquals(true, headers.get(HEADER_IS_PUBLIC_DIRECTORY));
assertEquals(true, headers.get(HEADER_IS_DIRECTORY_MOVING));
assertEquals(NotificationType.UPDATE_DIRECTORY, headers.get(HEADER_NOTIFICATION_TYPE));
assertEquals(UPDATE_TYPE_DIRECTORIES, headers.get(HEADER_UPDATE_TYPE));

// test move root directory
mockMvc.perform(put("/v1/elements?targetDirectoryUuid=" + rootDir10Uuid)
.header("userId", "Doe")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(List.of(rootDir20Uuid))))
.andExpect(status().isOk());

message = output.receive(TIMEOUT, directoryUpdateDestination);
assertEquals("", new String(message.getPayload()));
headers = message.getHeaders();
assertEquals("Doe", headers.get(HEADER_USER_ID));
assertEquals(rootDir20Uuid, headers.get(HEADER_DIRECTORY_UUID));
assertEquals(true, headers.get(HEADER_IS_ROOT_DIRECTORY));
assertEquals(true, headers.get(HEADER_IS_PUBLIC_DIRECTORY));
assertEquals(true, headers.get(HEADER_IS_DIRECTORY_MOVING));
assertEquals(NotificationType.DELETE_DIRECTORY, headers.get(HEADER_NOTIFICATION_TYPE));
assertEquals(UPDATE_TYPE_DIRECTORIES, headers.get(HEADER_UPDATE_TYPE));

message = output.receive(TIMEOUT, directoryUpdateDestination);
assertEquals("", new String(message.getPayload()));
headers = message.getHeaders();
assertEquals("Doe", headers.get(HEADER_USER_ID));
assertEquals(rootDir10Uuid, headers.get(HEADER_DIRECTORY_UUID));
assertEquals(true, headers.get(HEADER_IS_ROOT_DIRECTORY));
assertEquals(true, headers.get(HEADER_IS_PUBLIC_DIRECTORY));
assertEquals(true, headers.get(HEADER_IS_DIRECTORY_MOVING));
assertEquals(NotificationType.UPDATE_DIRECTORY, headers.get(HEADER_NOTIFICATION_TYPE));
assertEquals(UPDATE_TYPE_DIRECTORIES, headers.get(HEADER_UPDATE_TYPE));

assertNbElementsInRepositories(5);
}

@Test
Expand Down Expand Up @@ -645,6 +678,7 @@ public void testElementMove() throws Exception {
assertEquals(rootDir20Uuid, headers.get(HEADER_DIRECTORY_UUID));
assertEquals(true, headers.get(HEADER_IS_ROOT_DIRECTORY));
assertEquals(true, headers.get(HEADER_IS_PUBLIC_DIRECTORY));
assertEquals(false, headers.get(HEADER_IS_DIRECTORY_MOVING));
assertEquals(NotificationType.UPDATE_DIRECTORY, headers.get(HEADER_NOTIFICATION_TYPE));
assertEquals(UPDATE_TYPE_DIRECTORIES, headers.get(HEADER_UPDATE_TYPE));

Expand All @@ -655,6 +689,7 @@ public void testElementMove() throws Exception {
assertEquals(rootDir10Uuid, headers.get(HEADER_DIRECTORY_UUID));
assertEquals(true, headers.get(HEADER_IS_ROOT_DIRECTORY));
assertEquals(true, headers.get(HEADER_IS_PUBLIC_DIRECTORY));
assertEquals(false, headers.get(HEADER_IS_DIRECTORY_MOVING));
assertEquals(NotificationType.UPDATE_DIRECTORY, headers.get(HEADER_NOTIFICATION_TYPE));
assertEquals(UPDATE_TYPE_DIRECTORIES, headers.get(HEADER_UPDATE_TYPE));
}
Expand Down

0 comments on commit 6c863e7

Please sign in to comment.