From adcf1a485326c0c88614a1bf2be9eaf710e6b585 Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Mon, 19 Jan 2026 17:19:33 +0100 Subject: [PATCH 1/3] Add support for workspace elements Signed-off-by: Ayoub LABIDI --- .../explore/server/ExploreController.java | 37 ++++++++ .../server/services/DirectoryService.java | 3 +- .../server/services/ExploreService.java | 20 +++++ .../server/services/WorkspaceService.java | 89 +++++++++++++++++++ 4 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/gridsuite/explore/server/services/WorkspaceService.java diff --git a/src/main/java/org/gridsuite/explore/server/ExploreController.java b/src/main/java/org/gridsuite/explore/server/ExploreController.java index 1a3d04c..c787cd5 100644 --- a/src/main/java/org/gridsuite/explore/server/ExploreController.java +++ b/src/main/java/org/gridsuite/explore/server/ExploreController.java @@ -425,6 +425,43 @@ public ResponseEntity duplicateSpreadsheetConfig(@RequestParam("duplicateF return ResponseEntity.status(HttpStatus.CREATED).build(); } + @PostMapping(value = "/explore/workspaces", params = "workspaceId") + @Operation(summary = "Create a workspace by duplicating an existing workspace") + @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Workspace created")}) + @PreAuthorize("@authorizationService.isAuthorized(#userId, #parentDirectoryUuid, null, T(org.gridsuite.explore.server.dto.PermissionType).WRITE)") + public ResponseEntity createWorkspace(@RequestParam("workspaceId") UUID workspaceId, + @RequestParam("name") String workspaceName, + @RequestParam(QUERY_PARAM_DESCRIPTION) String description, + @RequestParam(QUERY_PARAM_PARENT_DIRECTORY_ID) UUID parentDirectoryUuid, + @RequestHeader(QUERY_PARAM_USER_ID) String userId) { + exploreService.createWorkspace(workspaceId, workspaceName, description, parentDirectoryUuid, userId); + return ResponseEntity.status(HttpStatus.CREATED).build(); + } + + @PutMapping(value = "/explore/workspaces/{id}", params = "workspaceId") + @Operation(summary = "Replace a workspace with another workspace") + @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Workspace has been successfully replaced")}) + @PreAuthorize("@authorizationService.isAuthorized(#userId, #id, null, T(org.gridsuite.explore.server.dto.PermissionType).WRITE)") + public ResponseEntity replaceWorkspace(@PathVariable UUID id, + @RequestParam("workspaceId") UUID workspaceId, + @RequestHeader(QUERY_PARAM_USER_ID) String userId, + @RequestParam(QUERY_PARAM_NAME) String name, + @RequestParam(QUERY_PARAM_DESCRIPTION) String description) { + exploreService.replaceWorkspace(id, workspaceId, userId, name, description); + return ResponseEntity.noContent().build(); + } + + @PostMapping(value = "/explore/workspaces", params = "duplicateFrom") + @Operation(summary = "Duplicate a workspace") + @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Workspace has been successfully duplicated")}) + @PreAuthorize("@authorizationService.isAuthorizedForDuplication(#userId, #sourceId, #targetDirectoryId)") + public ResponseEntity duplicateWorkspace(@RequestParam("duplicateFrom") UUID sourceId, + @RequestParam(name = QUERY_PARAM_PARENT_DIRECTORY_ID, required = false) UUID targetDirectoryId, + @RequestHeader(QUERY_PARAM_USER_ID) String userId) { + exploreService.duplicateWorkspace(sourceId, targetDirectoryId, userId); + return ResponseEntity.status(HttpStatus.CREATED).build(); + } + @PostMapping(value = "/explore/spreadsheet-config-collections", params = "duplicateFrom") @Operation(summary = "Duplicate a spreadsheet configuration collection") @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Spreadsheet config collection has been successfully duplicated")}) diff --git a/src/main/java/org/gridsuite/explore/server/services/DirectoryService.java b/src/main/java/org/gridsuite/explore/server/services/DirectoryService.java index 1b140dc..ff933f2 100644 --- a/src/main/java/org/gridsuite/explore/server/services/DirectoryService.java +++ b/src/main/java/org/gridsuite/explore/server/services/DirectoryService.java @@ -66,7 +66,7 @@ public class DirectoryService implements IDirectoryElementsService { public DirectoryService( FilterService filterService, ContingencyListService contingencyListService, StudyService studyService, NetworkModificationService networkModificationService, CaseService caseService, SpreadsheetConfigService spreadsheetConfigService, SpreadsheetConfigCollectionService spreadsheetConfigCollectionService, ParametersService parametersService, - SingleLineDiagramService singleLineDiagramService, RestTemplate restTemplate, RemoteServicesProperties remoteServicesProperties) { + SingleLineDiagramService singleLineDiagramService, WorkspaceService workspaceService, RestTemplate restTemplate, RemoteServicesProperties remoteServicesProperties) { this.directoryServerBaseUri = remoteServicesProperties.getServiceUri("directory-server"); this.restTemplate = restTemplate; this.genericServices = Map.ofEntries( @@ -79,6 +79,7 @@ public DirectoryService( Map.entry(SPREADSHEET_CONFIG, spreadsheetConfigService), Map.entry(SPREADSHEET_CONFIG_COLLECTION, spreadsheetConfigCollectionService), Map.entry(DIAGRAM_CONFIG, singleLineDiagramService), + Map.entry(WORKSPACE, workspaceService), Map.entry(ParametersType.VOLTAGE_INIT_PARAMETERS.name(), parametersService), Map.entry(ParametersType.SECURITY_ANALYSIS_PARAMETERS.name(), parametersService), Map.entry(ParametersType.LOADFLOW_PARAMETERS.name(), parametersService), diff --git a/src/main/java/org/gridsuite/explore/server/services/ExploreService.java b/src/main/java/org/gridsuite/explore/server/services/ExploreService.java index 9f2d37c..8000431 100644 --- a/src/main/java/org/gridsuite/explore/server/services/ExploreService.java +++ b/src/main/java/org/gridsuite/explore/server/services/ExploreService.java @@ -41,6 +41,7 @@ public class ExploreService { static final String SPREADSHEET_CONFIG = "SPREADSHEET_CONFIG"; static final String SPREADSHEET_CONFIG_COLLECTION = "SPREADSHEET_CONFIG_COLLECTION"; static final String DIAGRAM_CONFIG = "DIAGRAM_CONFIG"; + static final String WORKSPACE = "WORKSPACE"; private final DirectoryService directoryService; private final StudyService studyService; @@ -51,6 +52,7 @@ public class ExploreService { private final ParametersService parametersService; private final SpreadsheetConfigService spreadsheetConfigService; private final SpreadsheetConfigCollectionService spreadsheetConfigCollectionService; + private final WorkspaceService workspaceService; private final UserIdentityService userIdentityService; private final NotificationService notificationService; @@ -69,6 +71,7 @@ public ExploreService( UserAdminService userAdminService, SpreadsheetConfigService spreadsheetConfigService, SpreadsheetConfigCollectionService spreadsheetConfigCollectionService, + WorkspaceService workspaceService, UserIdentityService userIdentityService, NotificationService notificationService, SingleLineDiagramService singleLineDiagramService) { @@ -83,6 +86,7 @@ public ExploreService( this.userAdminService = userAdminService; this.spreadsheetConfigService = spreadsheetConfigService; this.spreadsheetConfigCollectionService = spreadsheetConfigCollectionService; + this.workspaceService = workspaceService; this.userIdentityService = userIdentityService; this.notificationService = notificationService; this.singleLineDiagramService = singleLineDiagramService; @@ -319,6 +323,22 @@ public void duplicateSpreadsheetConfigCollection(UUID sourceId, UUID targetDirec directoryService.duplicateElement(sourceId, newSpreadsheetConfigUuid, targetDirectoryId, userId); } + public void createWorkspace(UUID workspaceId, String workspaceName, String description, UUID parentDirectoryUuid, String userId) { + UUID newWorkspaceId = workspaceService.duplicateWorkspace(workspaceId); + ElementAttributes elementAttributes = new ElementAttributes(newWorkspaceId, workspaceName, WORKSPACE, userId, 0, description); + directoryService.createElement(elementAttributes, parentDirectoryUuid, userId); + } + + public void replaceWorkspace(UUID id, UUID workspaceId, String userId, String name, String description) { + workspaceService.replaceWorkspace(id, workspaceId); + updateElementNameAndDescription(id, name, description, userId); + } + + public void duplicateWorkspace(UUID sourceId, UUID targetDirectoryId, String userId) { + UUID newWorkspaceId = workspaceService.duplicateWorkspace(sourceId); + directoryService.duplicateElement(sourceId, newWorkspaceId, targetDirectoryId, userId); + } + public void createCompositeModification(List modificationUuids, String userId, String name, String description, UUID parentDirectoryUuid) { diff --git a/src/main/java/org/gridsuite/explore/server/services/WorkspaceService.java b/src/main/java/org/gridsuite/explore/server/services/WorkspaceService.java new file mode 100644 index 0000000..9e7b957 --- /dev/null +++ b/src/main/java/org/gridsuite/explore/server/services/WorkspaceService.java @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2026, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.explore.server.services; + +import lombok.Setter; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; + +import java.util.Objects; +import java.util.UUID; + +/** + * @author Ayoub LABIDI + */ +@Service +public class WorkspaceService implements IDirectoryElementsService { + + private static final String WORKSPACES_API_VERSION = "v1"; + private static final String DELIMITER = "/"; + private static final String WORKSPACES_PATH = DELIMITER + WORKSPACES_API_VERSION + DELIMITER + "workspaces"; + private static final String DUPLICATE_FROM_PARAMETER = "duplicateFrom"; + + private final RestTemplate restTemplate; + + @Setter + private String studyConfigServerBaseUri; + + public WorkspaceService(RestTemplate restTemplate, RemoteServicesProperties remoteServicesProperties) { + this.studyConfigServerBaseUri = remoteServicesProperties.getServiceUri("study-config-server"); + this.restTemplate = restTemplate; + } + + public UUID duplicateWorkspace(UUID sourceWorkspaceId) { + Objects.requireNonNull(sourceWorkspaceId); + + var path = UriComponentsBuilder + .fromPath(WORKSPACES_PATH) + .queryParam(DUPLICATE_FROM_PARAMETER, sourceWorkspaceId) + .buildAndExpand() + .toUriString(); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity httpEntity = new HttpEntity<>(headers); + + return restTemplate.exchange(studyConfigServerBaseUri + path, HttpMethod.POST, httpEntity, UUID.class).getBody(); + } + + public void replaceWorkspace(UUID workspaceId, UUID sourceWorkspaceId) { + Objects.requireNonNull(workspaceId); + Objects.requireNonNull(sourceWorkspaceId); + + var path = UriComponentsBuilder + .fromPath(WORKSPACES_PATH + DELIMITER + workspaceId + "/replace") + .queryParam(DUPLICATE_FROM_PARAMETER, sourceWorkspaceId) + .buildAndExpand() + .toUriString(); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity httpEntity = new HttpEntity<>(headers); + + restTemplate.exchange(studyConfigServerBaseUri + path, HttpMethod.PUT, httpEntity, Void.class); + } + + @Override + public void delete(UUID workspaceUuid, String userId) { + Objects.requireNonNull(workspaceUuid); + + var path = UriComponentsBuilder + .fromPath(WORKSPACES_PATH + DELIMITER + workspaceUuid) + .buildAndExpand() + .toUriString(); + + HttpHeaders headers = new HttpHeaders(); + headers.add(HEADER_USER_ID, userId); + + restTemplate.exchange(studyConfigServerBaseUri + path, HttpMethod.DELETE, new HttpEntity<>(headers), Void.class); + } +} From caadb95b47f08bf12c26690d72081243c95131d4 Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Thu, 22 Jan 2026 02:24:30 +0100 Subject: [PATCH 2/3] Add tests Signed-off-by: Ayoub LABIDI --- .../explore/server/WorkspaceTest.java | 217 ++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 src/test/java/org/gridsuite/explore/server/WorkspaceTest.java diff --git a/src/test/java/org/gridsuite/explore/server/WorkspaceTest.java b/src/test/java/org/gridsuite/explore/server/WorkspaceTest.java new file mode 100644 index 0000000..19c64ed --- /dev/null +++ b/src/test/java/org/gridsuite/explore/server/WorkspaceTest.java @@ -0,0 +1,217 @@ +/** + * Copyright (c) 2026, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.explore.server; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.tomakehurst.wiremock.WireMockServer; +import com.github.tomakehurst.wiremock.client.WireMock; +import org.gridsuite.explore.server.dto.ElementAttributes; +import org.gridsuite.explore.server.dto.PermissionResponse; +import org.gridsuite.explore.server.dto.PermissionType; +import org.gridsuite.explore.server.services.DirectoryService; +import org.gridsuite.explore.server.services.WorkspaceService; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.test.context.bean.override.mockito.MockitoBean; +import org.springframework.test.web.servlet.MockMvc; + +import java.util.List; +import java.util.UUID; + +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +/** + * @author Ayoub LABIDI + */ +@SpringBootTest +@AutoConfigureMockMvc +class WorkspaceTest { + + @Autowired + private MockMvc mockMvc; + + @Autowired + private ObjectMapper objectMapper; + + @Autowired + private WorkspaceService workspaceService; + + @MockitoBean + private DirectoryService directoryService; + + @Captor + private ArgumentCaptor elementAttributesCaptor; + + private WireMockServer wireMockServer; + + private static final String BASE_URL = "/v1/explore/workspaces"; + private static final String STUDY_CONFIG_SERVER_BASE_URL = "/v1/workspaces"; + private static final UUID WORKSPACE_UUID = UUID.randomUUID(); + private static final UUID SOURCE_WORKSPACE_UUID = UUID.randomUUID(); + private static final UUID PARENT_DIRECTORY_UUID = UUID.randomUUID(); + private static final String USER_ID = "testUser"; + private static final String WORKSPACE_NAME = "Test Workspace"; + + private static final PermissionResponse ALLOWED_PERMISSION = new PermissionResponse(true, null); + + @BeforeEach + void setUp() throws JsonProcessingException { + wireMockServer = new WireMockServer(wireMockConfig().dynamicPort()); + wireMockServer.start(); + workspaceService.setStudyConfigServerBaseUri(wireMockServer.baseUrl()); + + wireMockServer.stubFor(WireMock.post(WireMock.urlPathEqualTo(STUDY_CONFIG_SERVER_BASE_URL)) + .willReturn(WireMock.aResponse() + .withStatus(201) + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .withBody(objectMapper.writeValueAsString(WORKSPACE_UUID)))); + + wireMockServer.stubFor(WireMock.put(WireMock.urlPathMatching(STUDY_CONFIG_SERVER_BASE_URL + "/.*/replace")) + .willReturn(WireMock.noContent())); + + wireMockServer.stubFor(WireMock.delete(WireMock.urlPathMatching(STUDY_CONFIG_SERVER_BASE_URL + "/.*")) + .willReturn(WireMock.noContent())); + } + + @AfterEach + void tearDown() { + wireMockServer.stop(); + } + + @Test + void testCreateWorkspace() throws Exception { + when(directoryService.checkPermission(List.of(PARENT_DIRECTORY_UUID), null, USER_ID, PermissionType.WRITE)).thenReturn(ALLOWED_PERMISSION); + + mockMvc.perform(post(BASE_URL) + .param("workspaceId", SOURCE_WORKSPACE_UUID.toString()) + .param("name", WORKSPACE_NAME) + .param("description", "Test workspace description") + .param("parentDirectoryUuid", PARENT_DIRECTORY_UUID.toString()) + .header("userId", USER_ID)) + .andExpect(status().isCreated()); + + verify(directoryService, times(1)).createElement(elementAttributesCaptor.capture(), eq(PARENT_DIRECTORY_UUID), eq(USER_ID)); + verify(directoryService, times(1)).checkPermission(List.of(PARENT_DIRECTORY_UUID), null, USER_ID, PermissionType.WRITE); + assertEquals(WORKSPACE_UUID, elementAttributesCaptor.getValue().getElementUuid()); + } + + @Test + void testReplaceWorkspace() throws Exception { + when(directoryService.checkPermission(List.of(WORKSPACE_UUID), null, USER_ID, PermissionType.WRITE)).thenReturn(ALLOWED_PERMISSION); + + mockMvc.perform(put(BASE_URL + "/{id}", WORKSPACE_UUID) + .param("workspaceId", SOURCE_WORKSPACE_UUID.toString()) + .param("name", WORKSPACE_NAME) + .param("description", "Updated description") + .header("userId", USER_ID)) + .andExpect(status().isNoContent()); + + verify(directoryService, times(1)).updateElement(eq(WORKSPACE_UUID), elementAttributesCaptor.capture(), eq(USER_ID)); + verify(directoryService, times(1)).checkPermission(List.of(WORKSPACE_UUID), null, USER_ID, PermissionType.WRITE); + } + + @Test + void testDuplicateWorkspace() throws Exception { + when(directoryService.checkPermission(List.of(PARENT_DIRECTORY_UUID), null, USER_ID, PermissionType.WRITE)).thenReturn(ALLOWED_PERMISSION); + when(directoryService.checkPermission(List.of(SOURCE_WORKSPACE_UUID), null, USER_ID, PermissionType.READ)).thenReturn(ALLOWED_PERMISSION); + + mockMvc.perform(post(BASE_URL) + .param("duplicateFrom", SOURCE_WORKSPACE_UUID.toString()) + .param("parentDirectoryUuid", PARENT_DIRECTORY_UUID.toString()) + .header("userId", USER_ID)) + .andExpect(status().isCreated()); + + verify(directoryService, times(1)).duplicateElement(SOURCE_WORKSPACE_UUID, WORKSPACE_UUID, PARENT_DIRECTORY_UUID, USER_ID); + verify(directoryService, times(1)).checkPermission(List.of(PARENT_DIRECTORY_UUID), null, USER_ID, PermissionType.WRITE); + verify(directoryService, times(1)).checkPermission(List.of(SOURCE_WORKSPACE_UUID), null, USER_ID, PermissionType.READ); + } + + @Test + void testDuplicateWorkspaceInSameDirectory() throws Exception { + when(directoryService.checkPermission(List.of(SOURCE_WORKSPACE_UUID), null, USER_ID, PermissionType.READ)).thenReturn(ALLOWED_PERMISSION); + when(directoryService.checkPermission(List.of(SOURCE_WORKSPACE_UUID), null, USER_ID, PermissionType.WRITE)).thenReturn(ALLOWED_PERMISSION); + + mockMvc.perform(post(BASE_URL) + .param("duplicateFrom", SOURCE_WORKSPACE_UUID.toString()) + .header("userId", USER_ID)) + .andExpect(status().isCreated()); + + verify(directoryService, times(1)).duplicateElement(SOURCE_WORKSPACE_UUID, WORKSPACE_UUID, null, USER_ID); + } + + @Test + void testDuplicateWorkspaceWithInvalidUUID() throws Exception { + mockMvc.perform(post(BASE_URL) + .param("duplicateFrom", "invalid-uuid") + .param("parentDirectoryUuid", PARENT_DIRECTORY_UUID.toString()) + .header("userId", USER_ID)) + .andExpect(status().isInternalServerError()); + } + + @Test + void testCreateWorkspaceServiceError() throws Exception { + when(directoryService.checkPermission(List.of(PARENT_DIRECTORY_UUID), null, USER_ID, PermissionType.WRITE)).thenReturn(ALLOWED_PERMISSION); + + wireMockServer.resetAll(); + wireMockServer.stubFor(WireMock.post(WireMock.urlPathEqualTo(STUDY_CONFIG_SERVER_BASE_URL)) + .willReturn(WireMock.serverError())); + + mockMvc.perform(post(BASE_URL) + .param("workspaceId", SOURCE_WORKSPACE_UUID.toString()) + .param("name", WORKSPACE_NAME) + .param("description", "Test workspace description") + .param("parentDirectoryUuid", PARENT_DIRECTORY_UUID.toString()) + .header("userId", USER_ID)) + .andExpect(status().isInternalServerError()); + } + + @Test + void testReplaceWorkspaceServiceError() throws Exception { + when(directoryService.checkPermission(List.of(WORKSPACE_UUID), null, USER_ID, PermissionType.WRITE)).thenReturn(ALLOWED_PERMISSION); + + wireMockServer.resetAll(); + wireMockServer.stubFor(WireMock.put(WireMock.urlPathMatching(STUDY_CONFIG_SERVER_BASE_URL + "/.*/replace")) + .willReturn(WireMock.serverError())); + + mockMvc.perform(put(BASE_URL + "/{id}", WORKSPACE_UUID) + .param("workspaceId", SOURCE_WORKSPACE_UUID.toString()) + .param("name", WORKSPACE_NAME) + .param("description", "Updated description") + .header("userId", USER_ID)) + .andExpect(status().isInternalServerError()); + } + + @Test + void testDuplicateWorkspaceServiceError() throws Exception { + when(directoryService.checkPermission(List.of(PARENT_DIRECTORY_UUID), null, USER_ID, PermissionType.WRITE)).thenReturn(ALLOWED_PERMISSION); + when(directoryService.checkPermission(List.of(SOURCE_WORKSPACE_UUID), null, USER_ID, PermissionType.READ)).thenReturn(ALLOWED_PERMISSION); + + wireMockServer.resetAll(); + wireMockServer.stubFor(WireMock.post(WireMock.urlPathEqualTo(STUDY_CONFIG_SERVER_BASE_URL)) + .willReturn(WireMock.serverError())); + + mockMvc.perform(post(BASE_URL) + .param("duplicateFrom", SOURCE_WORKSPACE_UUID.toString()) + .param("parentDirectoryUuid", PARENT_DIRECTORY_UUID.toString()) + .header("userId", USER_ID)) + .andExpect(status().isInternalServerError()); + } +} From 4b5cc28ccdf00200431ff90dc969d54708f2d69e Mon Sep 17 00:00:00 2001 From: Ayoub LABIDI Date: Mon, 26 Jan 2026 17:35:41 +0100 Subject: [PATCH 3/3] Fix merge Signed-off-by: Ayoub LABIDI --- .../explore/server/WorkspaceTest.java | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/src/test/java/org/gridsuite/explore/server/WorkspaceTest.java b/src/test/java/org/gridsuite/explore/server/WorkspaceTest.java index 19c64ed..549b9c1 100644 --- a/src/test/java/org/gridsuite/explore/server/WorkspaceTest.java +++ b/src/test/java/org/gridsuite/explore/server/WorkspaceTest.java @@ -11,7 +11,6 @@ import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.client.WireMock; import org.gridsuite.explore.server.dto.ElementAttributes; -import org.gridsuite.explore.server.dto.PermissionResponse; import org.gridsuite.explore.server.dto.PermissionType; import org.gridsuite.explore.server.services.DirectoryService; import org.gridsuite.explore.server.services.WorkspaceService; @@ -70,8 +69,6 @@ class WorkspaceTest { private static final String USER_ID = "testUser"; private static final String WORKSPACE_NAME = "Test Workspace"; - private static final PermissionResponse ALLOWED_PERMISSION = new PermissionResponse(true, null); - @BeforeEach void setUp() throws JsonProcessingException { wireMockServer = new WireMockServer(wireMockConfig().dynamicPort()); @@ -98,8 +95,6 @@ void tearDown() { @Test void testCreateWorkspace() throws Exception { - when(directoryService.checkPermission(List.of(PARENT_DIRECTORY_UUID), null, USER_ID, PermissionType.WRITE)).thenReturn(ALLOWED_PERMISSION); - mockMvc.perform(post(BASE_URL) .param("workspaceId", SOURCE_WORKSPACE_UUID.toString()) .param("name", WORKSPACE_NAME) @@ -115,8 +110,6 @@ void testCreateWorkspace() throws Exception { @Test void testReplaceWorkspace() throws Exception { - when(directoryService.checkPermission(List.of(WORKSPACE_UUID), null, USER_ID, PermissionType.WRITE)).thenReturn(ALLOWED_PERMISSION); - mockMvc.perform(put(BASE_URL + "/{id}", WORKSPACE_UUID) .param("workspaceId", SOURCE_WORKSPACE_UUID.toString()) .param("name", WORKSPACE_NAME) @@ -130,9 +123,6 @@ void testReplaceWorkspace() throws Exception { @Test void testDuplicateWorkspace() throws Exception { - when(directoryService.checkPermission(List.of(PARENT_DIRECTORY_UUID), null, USER_ID, PermissionType.WRITE)).thenReturn(ALLOWED_PERMISSION); - when(directoryService.checkPermission(List.of(SOURCE_WORKSPACE_UUID), null, USER_ID, PermissionType.READ)).thenReturn(ALLOWED_PERMISSION); - mockMvc.perform(post(BASE_URL) .param("duplicateFrom", SOURCE_WORKSPACE_UUID.toString()) .param("parentDirectoryUuid", PARENT_DIRECTORY_UUID.toString()) @@ -146,9 +136,6 @@ void testDuplicateWorkspace() throws Exception { @Test void testDuplicateWorkspaceInSameDirectory() throws Exception { - when(directoryService.checkPermission(List.of(SOURCE_WORKSPACE_UUID), null, USER_ID, PermissionType.READ)).thenReturn(ALLOWED_PERMISSION); - when(directoryService.checkPermission(List.of(SOURCE_WORKSPACE_UUID), null, USER_ID, PermissionType.WRITE)).thenReturn(ALLOWED_PERMISSION); - mockMvc.perform(post(BASE_URL) .param("duplicateFrom", SOURCE_WORKSPACE_UUID.toString()) .header("userId", USER_ID)) @@ -168,8 +155,6 @@ void testDuplicateWorkspaceWithInvalidUUID() throws Exception { @Test void testCreateWorkspaceServiceError() throws Exception { - when(directoryService.checkPermission(List.of(PARENT_DIRECTORY_UUID), null, USER_ID, PermissionType.WRITE)).thenReturn(ALLOWED_PERMISSION); - wireMockServer.resetAll(); wireMockServer.stubFor(WireMock.post(WireMock.urlPathEqualTo(STUDY_CONFIG_SERVER_BASE_URL)) .willReturn(WireMock.serverError())); @@ -185,8 +170,6 @@ void testCreateWorkspaceServiceError() throws Exception { @Test void testReplaceWorkspaceServiceError() throws Exception { - when(directoryService.checkPermission(List.of(WORKSPACE_UUID), null, USER_ID, PermissionType.WRITE)).thenReturn(ALLOWED_PERMISSION); - wireMockServer.resetAll(); wireMockServer.stubFor(WireMock.put(WireMock.urlPathMatching(STUDY_CONFIG_SERVER_BASE_URL + "/.*/replace")) .willReturn(WireMock.serverError())); @@ -201,9 +184,6 @@ void testReplaceWorkspaceServiceError() throws Exception { @Test void testDuplicateWorkspaceServiceError() throws Exception { - when(directoryService.checkPermission(List.of(PARENT_DIRECTORY_UUID), null, USER_ID, PermissionType.WRITE)).thenReturn(ALLOWED_PERMISSION); - when(directoryService.checkPermission(List.of(SOURCE_WORKSPACE_UUID), null, USER_ID, PermissionType.READ)).thenReturn(ALLOWED_PERMISSION); - wireMockServer.resetAll(); wireMockServer.stubFor(WireMock.post(WireMock.urlPathEqualTo(STUDY_CONFIG_SERVER_BASE_URL)) .willReturn(WireMock.serverError()));