diff --git a/src/test/java/org/gridsuite/study/server/StudyTest.java b/src/test/java/org/gridsuite/study/server/StudyTest.java index 21a90cc04..9e16739ec 100644 --- a/src/test/java/org/gridsuite/study/server/StudyTest.java +++ b/src/test/java/org/gridsuite/study/server/StudyTest.java @@ -397,8 +397,7 @@ public MockResponse dispatch(RecordedRequest request) { return new MockResponse().setResponseCode(200) .addHeader("Content-Type", "application/json; charset=utf-8"); } else if (path.matches("/v1/network-modifications.*") && POST.equals(request.getMethod())) { - ModificationInfos modificationInfos = mapper.readValue(body.readUtf8(), new TypeReference() { - }); + ModificationInfos modificationInfos = mapper.readValue(body.readUtf8(), new TypeReference() { }); modificationInfos.setSubstationIds(Set.of("s2")); return new MockResponse().setResponseCode(200) .setBody("[" + mapper.writeValueAsString(modificationInfos) + "]") @@ -693,48 +692,42 @@ public void testSearch() throws Exception { UUID studyUuid = createStudy("userId", CASE_UUID); UUID rootNodeId = getRootNodeUuid(studyUuid); - mvcResult = mockMvc - .perform(get("/v1/search?q={request}", String.format("userId:%s", "userId")).header(USER_ID_HEADER, "userId")) - .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + mvcResult = mockMvc.perform(get("/v1/search?q={request}", String.format("userId:%s", "userId")) + .header(USER_ID_HEADER, "userId")) + .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) + .andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); - List createdStudyBasicInfosList = mapper.readValue(resultAsString, - new TypeReference>() { - }); + List createdStudyBasicInfosList = mapper.readValue(resultAsString, new TypeReference>() { }); assertThat(createdStudyBasicInfosList, new MatcherJson<>(mapper, studiesInfos)); - mvcResult = mockMvc - .perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/search?userInput={request}&fieldSelector=NAME", - studyUuid, rootNodeId, "B").header(USER_ID_HEADER, "userId")) - .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/search?userInput={request}&fieldSelector=NAME", + studyUuid, rootNodeId, "B").header(USER_ID_HEADER, "userId")) + .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) + .andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); - List equipmentInfos = mapper.readValue(resultAsString, - new TypeReference>() { - }); + List equipmentInfos = mapper.readValue(resultAsString, new TypeReference>() { }); assertThat(equipmentInfos, new MatcherJson<>(mapper, linesInfos)); - mvcResult = mockMvc - .perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/search?userInput={request}&fieldSelector=NAME", - studyUuid, rootNodeId, "B").header(USER_ID_HEADER, "userId")) - .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/search?userInput={request}&fieldSelector=NAME", + studyUuid, rootNodeId, "B").header(USER_ID_HEADER, "userId")) + .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) + .andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); - equipmentInfos = mapper.readValue(resultAsString, new TypeReference>() { - }); + equipmentInfos = mapper.readValue(resultAsString, new TypeReference>() { }); assertThat(equipmentInfos, new MatcherJson<>(mapper, linesInfos)); - mvcResult = mockMvc - .perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/search?userInput={request}&fieldSelector=ID", - studyUuid, rootNodeId, "B").header(USER_ID_HEADER, "userId")) - .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/search?userInput={request}&fieldSelector=ID", + studyUuid, rootNodeId, "B").header(USER_ID_HEADER, "userId")) + .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) + .andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); - equipmentInfos = mapper.readValue(resultAsString, new TypeReference>() { - }); + equipmentInfos = mapper.readValue(resultAsString, new TypeReference>() { }); assertThat(equipmentInfos, new MatcherJson<>(mapper, linesInfos)); mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/search?userInput={request}&fieldSelector=bogus", - studyUuid, rootNodeId, "B").header(USER_ID_HEADER, "userId")) - .andExpectAll(status().isBadRequest(), - content().string("Enum unknown entry 'bogus' should be among NAME, ID")) - .andReturn(); + studyUuid, rootNodeId, "B").header(USER_ID_HEADER, "userId")) + .andExpectAll(status().isBadRequest(), content().string("Enum unknown entry 'bogus' should be among NAME, ID")) + .andReturn(); } @Test @@ -744,19 +737,20 @@ public void test() throws Exception { String userId = "userId"; //empty list - mockMvc.perform(get("/v1/studies").header(USER_ID_HEADER, "userId")).andExpectAll(status().isOk(), - content().contentType(MediaType.APPLICATION_JSON), content().string("[]")); + mockMvc.perform(get("/v1/studies").header(USER_ID_HEADER, "userId")) + .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON), content().string("[]")); //empty list - mockMvc.perform(get("/v1/study_creation_requests").header(USER_ID_HEADER, "userId")).andExpectAll(status().isOk(), - content().contentType(MediaType.APPLICATION_JSON), content().string("[]")); + mockMvc.perform(get("/v1/study_creation_requests").header(USER_ID_HEADER, "userId")) + .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON), content().string("[]")); //insert a study UUID studyUuid = createStudy("userId", CASE_UUID); // check the study result = mockMvc.perform(get("/v1/studies/{studyUuid}", studyUuid).header(USER_ID_HEADER, "userId")) - .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) + .andReturn(); resultAsString = result.getResponse().getContentAsString(); StudyInfos infos = mapper.readValue(resultAsString, StudyInfos.class); @@ -764,21 +758,20 @@ public void test() throws Exception { assertThat(infos, createMatcherStudyInfos(studyUuid, "UCTE")); //insert a study with a non existing case and except exception - result = mockMvc.perform(post("/v1/studies/cases/{caseUuid}", - NOT_EXISTING_CASE_UUID, "false").header(USER_ID_HEADER, "userId").param(CASE_FORMAT, "XIIDM")) - .andExpectAll(status().isFailedDependency(), content().contentType(MediaType.valueOf("text/plain;charset=UTF-8"))).andReturn(); + result = mockMvc.perform(post("/v1/studies/cases/{caseUuid}", NOT_EXISTING_CASE_UUID, "false") + .header(USER_ID_HEADER, "userId") + .param(CASE_FORMAT, "XIIDM")) + .andExpectAll(status().isFailedDependency(), content().contentType(MediaType.valueOf("text/plain;charset=UTF-8"))) + .andReturn(); assertEquals("The case '" + NOT_EXISTING_CASE_UUID + "' does not exist", result.getResponse().getContentAsString()); - assertTrue(TestUtils.getRequestsDone(1, server) - .contains(String.format("/v1/cases/%s/exists", NOT_EXISTING_CASE_UUID))); + assertTrue(TestUtils.getRequestsDone(1, server).contains(String.format("/v1/cases/%s/exists", NOT_EXISTING_CASE_UUID))); result = mockMvc.perform(get("/v1/studies").header(USER_ID_HEADER, "userId")) - .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn(); resultAsString = result.getResponse().getContentAsString(); - List createdStudyBasicInfosList = mapper.readValue(resultAsString, - new TypeReference>() { - }); + List createdStudyBasicInfosList = mapper.readValue(resultAsString, new TypeReference>() { }); assertThat(createdStudyBasicInfosList.get(0), createMatcherCreatedStudyBasicInfos(studyUuid, "UCTE")); @@ -787,11 +780,12 @@ public void test() throws Exception { studyUuid = createStudy("userId2", CASE_UUID); resultAsString = mockMvc.perform(get("/v1/studies").header("userId", "userId2")) - .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getContentAsString(); + .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) + .andReturn() + .getResponse() + .getContentAsString(); - createdStudyBasicInfosList = mapper.readValue(resultAsString, - new TypeReference>() { - }); + createdStudyBasicInfosList = mapper.readValue(resultAsString, new TypeReference>() { }); assertThat(createdStudyBasicInfosList.get(1), createMatcherCreatedStudyBasicInfos(studyUuid, "UCTE")); @@ -799,45 +793,43 @@ public void test() throws Exception { UUID randomUuid = UUID.randomUUID(); //get a non existing study -> 404 not found mockMvc.perform(get("/v1/studies/{studyUuid}", randomUuid).header(USER_ID_HEADER, "userId")) - .andExpectAll(status().isNotFound(), - content().contentType(MediaType.APPLICATION_JSON), - jsonPath("$").value(STUDY_NOT_FOUND.name())); + .andExpectAll(status().isNotFound(), content().contentType(MediaType.APPLICATION_JSON), + jsonPath("$").value(STUDY_NOT_FOUND.name())); UUID studyNameUserIdUuid = studyRepository.findAll().get(0).getId(); // expect only 1 study (public one) since the other is private and we use // another userId result = mockMvc.perform(get("/v1/studies").header("userId", "a")) - .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) + .andReturn(); resultAsString = result.getResponse().getContentAsString(); - createdStudyBasicInfosList = mapper.readValue(resultAsString, - new TypeReference>() { - }); + createdStudyBasicInfosList = mapper.readValue(resultAsString, new TypeReference>() { }); assertEquals(2, createdStudyBasicInfosList.size()); //get available export format - mockMvc.perform(get("/v1/export-network-formats")).andExpectAll(status().isOk(), - content().string("[\"CGMES\",\"UCTE\",\"XIIDM\"]")); + mockMvc.perform(get("/v1/export-network-formats")) + .andExpectAll(status().isOk(), content().string("[\"CGMES\",\"UCTE\",\"XIIDM\"]")); assertTrue(TestUtils.getRequestsDone(1, server).contains("/v1/export/formats")); //export a network UUID rootNodeUuid = getRootNodeUuid(studyNameUserIdUuid); mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/export-network/{format}", studyNameUserIdUuid, rootNodeUuid, "XIIDM")) - .andExpect(status().isOk()); + .andExpect(status().isOk()); assertTrue(TestUtils.getRequestsDone(1, server).contains(String.format("/v1/networks/%s/export/XIIDM", NETWORK_UUID_STRING))); mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/export-network/{format}?formatParameters=%7B%22iidm.export.xml.indent%22%3Afalse%7D", studyNameUserIdUuid, rootNodeUuid, "XIIDM")) - .andExpect(status().isOk()); + .andExpect(status().isOk()); TestUtils.getRequestsDone(1, server); // just consume it NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 3", userId); UUID modificationNode1Uuid = modificationNode1.getId(); mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/export-network/{format}", studyNameUserIdUuid, modificationNode1Uuid, "XIIDM")) - .andExpect(status().isInternalServerError()); + .andExpect(status().isInternalServerError()); modificationNode1.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)); networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); @@ -845,7 +837,7 @@ public void test() throws Exception { checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/export-network/{format}", studyNameUserIdUuid, modificationNode1Uuid, "XIIDM")) - .andExpect(status().isOk()); + .andExpect(status().isOk()); assertTrue(TestUtils.getRequestsDone(1, server).contains(String.format("/v1/networks/%s/export/XIIDM?variantId=%s", NETWORK_UUID_STRING, VARIANT_ID))); } @@ -877,7 +869,7 @@ public void testDeleteStudy() throws Exception { UUID stubUuid = wireMockUtils.stubNetworkModificationDeleteGroup(); mockMvc.perform(delete("/v1/studies/{studyUuid}", studyUuid).header(USER_ID_HEADER, "userId")) - .andExpect(status().isOk()); + .andExpect(status().isOk()); assertTrue(studyRepository.findById(studyUuid).isEmpty()); @@ -909,7 +901,7 @@ public void testDeleteStudyWithError() throws Exception { UUID stubUuid = wireMockUtils.stubNetworkModificationDeleteGroup(); mockMvc.perform(delete("/v1/studies/{studyUuid}", studyUuid).header(USER_ID_HEADER, "userId")) - .andExpectAll(status().isInternalServerError(), content().string(InterruptedException.class.getName())); + .andExpectAll(status().isInternalServerError(), content().string(InterruptedException.class.getName())); wireMockUtils.verifyNetworkModificationDeleteGroup(stubUuid); @@ -932,7 +924,7 @@ public void testDeleteStudyWithNonExistingCase() throws Exception { studyRepository.save(studyEntity); mockMvc.perform(delete("/v1/studies/{studyUuid}", studyUuid).header(USER_ID_HEADER, "userId")) - .andExpect(status().isOk()); + .andExpect(status().isOk()); assertTrue(studyRepository.findById(studyUuid).isEmpty()); @@ -952,15 +944,13 @@ public void testMetadata() throws Exception { studyUuid = createStudy("userId2", CASE_UUID); - MvcResult mvcResult = mockMvc - .perform(get("/v1/studies/metadata?ids=" + MvcResult mvcResult = mockMvc.perform(get("/v1/studies/metadata?ids=" + Stream.of(oldStudyUuid, studyUuid).map(Object::toString).collect(Collectors.joining(","))) .header(USER_ID_HEADER, "userId")) - .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) + .andReturn(); String resultAsString = mvcResult.getResponse().getContentAsString(); - List createdStudyBasicInfosList = mapper.readValue(resultAsString, - new TypeReference>() { - }); + List createdStudyBasicInfosList = mapper.readValue(resultAsString, new TypeReference>() { }); assertNotNull(createdStudyBasicInfosList); assertEquals(2, createdStudyBasicInfosList.size()); @@ -977,13 +967,13 @@ public void testMetadata() throws Exception { public void testNotifyStudyMetadataUpdated() throws Exception { UUID studyUuid = UUID.randomUUID(); mockMvc.perform(post("/v1/studies/{studyUuid}/notification?type=metadata_updated", studyUuid) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isOk()); + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isOk()); checkStudyMetadataUpdatedMessagesReceived(); mockMvc.perform(post("/v1/studies/{studyUuid}/notification?type=NOT_EXISTING_TYPE", UUID.randomUUID()) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isBadRequest()); + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isBadRequest()); } @Test @@ -991,8 +981,10 @@ public void testLogsReport() throws Exception { UUID studyUuid = createStudy("userId", CASE_UUID); UUID rootNodeUuid = getRootNodeUuid(studyUuid); - MvcResult mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/parent-nodes-report?reportType=NETWORK_MODIFICATION", studyUuid, rootNodeUuid).header(USER_ID_HEADER, "userId")) - .andExpect(status().isOk()).andReturn(); + MvcResult mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/parent-nodes-report?reportType=NETWORK_MODIFICATION", studyUuid, rootNodeUuid) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isOk()) + .andReturn(); String resultAsString = mvcResult.getResponse().getContentAsString(); List reporterModel = mapper.readValue(resultAsString, new TypeReference>() { }); @@ -1024,8 +1016,10 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU jsonObject.put("modificationGroupUuid", modificationGroupUuid); mnBodyJson = jsonObject.toString(); - mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header(USER_ID_HEADER, userId)) - .andExpect(status().isOk()); + mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid) + .content(mnBodyJson).contentType(MediaType.APPLICATION_JSON) + .header(USER_ID_HEADER, userId)) + .andExpect(status().isOk()); checkElementUpdatedMessageSent(studyUuid, userId); var mess = output.receive(TIMEOUT, studyUpdateDestination); assertNotNull(mess); @@ -1040,10 +1034,10 @@ private UUID createStudy(String userId, UUID caseUuid) throws Exception { private UUID createStudy(String userId, UUID caseUuid, String parameterDuplicatedUuid, boolean parameterDuplicationSuccess) throws Exception { MvcResult result = mockMvc.perform(post("/v1/studies/cases/{caseUuid}", caseUuid) - .header("userId", userId) - .param(CASE_FORMAT, "UCTE")) - .andExpect(status().isOk()) - .andReturn(); + .header("userId", userId) + .param(CASE_FORMAT, "UCTE")) + .andExpect(status().isOk()) + .andReturn(); String resultAsString = result.getResponse().getContentAsString(); BasicStudyInfos infos = mapper.readValue(resultAsString, BasicStudyInfos.class); UUID studyUuid = infos.getId(); @@ -1070,11 +1064,11 @@ private UUID createStudy(String userId, UUID caseUuid, String parameterDuplicate protected UUID createStudyWithImportParameters(String userId, UUID caseUuid, String caseFormat, Map importParameters) throws Exception { MvcResult result = mockMvc.perform(post("/v1/studies/cases/{caseUuid}", caseUuid) - .header("userId", userId).contentType(MediaType.APPLICATION_JSON) - .param(CASE_FORMAT, caseFormat) - .content(mapper.writeValueAsString(importParameters))) - .andExpect(status().isOk()) - .andReturn(); + .header("userId", userId) + .param(CASE_FORMAT, caseFormat) + .content(mapper.writeValueAsString(importParameters)).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn(); String resultAsString = result.getResponse().getContentAsString(); BasicStudyInfos infos = mapper.readValue(resultAsString, BasicStudyInfos.class); UUID studyUuid = infos.getId(); @@ -1088,19 +1082,21 @@ protected UUID createStudyWithImportParameters(String userId, UUID caseUuid, Str assertTrue(requests.stream().anyMatch(r -> r.getPath().matches(String.format("/v1/cases/%s/disableExpiration", caseUuid)))); assertTrue(requests.stream().anyMatch(r -> r.getPath().matches("/v1/parameters/default"))); - assertEquals(mapper.writeValueAsString(importParameters), - requests.stream().filter(r -> r.getPath().matches("/v1/networks\\?caseUuid=" + caseUuid + "&variantId=" + FIRST_VARIANT_ID + "&reportUuid=.*")) - .findFirst().orElseThrow().getBody()); + assertEquals(mapper.writeValueAsString(importParameters), requests.stream() + .filter(r -> r.getPath().matches("/v1/networks\\?caseUuid=" + caseUuid + "&variantId=" + FIRST_VARIANT_ID + "&reportUuid=.*")) + .findFirst() + .orElseThrow() + .getBody()); return studyUuid; } private UUID createStudyWithDuplicateCase(String userId, UUID caseUuid) throws Exception { MvcResult result = mockMvc.perform(post("/v1/studies/cases/{caseUuid}", caseUuid) - .param("duplicateCase", "true") - .param(CASE_FORMAT, "UCTE") - .header("userId", userId)) - .andExpect(status().isOk()) - .andReturn(); + .param("duplicateCase", "true") + .param(CASE_FORMAT, "UCTE") + .header("userId", userId)) + .andExpect(status().isOk()) + .andReturn(); String resultAsString = result.getResponse().getContentAsString(); BasicStudyInfos infos = mapper.readValue(resultAsString, BasicStudyInfos.class); UUID studyUuid = infos.getId(); @@ -1156,7 +1152,7 @@ public void testCreateStudyWithErrorDuringCaseImport() throws Exception { mockMvc.perform(post("/v1/studies/cases/{caseUuid}", CASE_UUID_CAUSING_IMPORT_ERROR) .header("userId", userId) .param(CASE_FORMAT, "UCTE")) - .andExpect(status().is5xxServerError()); + .andExpect(status().is5xxServerError()); // assert that the broker message has been sent a study creation request message Message message = output.receive(TIMEOUT, "study.update"); @@ -1165,10 +1161,9 @@ public void testCreateStudyWithErrorDuringCaseImport() throws Exception { assertEquals(userId, headers.get(HEADER_USER_ID)); assertEquals(NotificationService.UPDATE_TYPE_STUDIES, headers.get(HEADER_UPDATE_TYPE)); - MvcResult mvcResult = mockMvc.perform(get("/v1/study_creation_requests").header(USER_ID_HEADER, "userId")).andExpectAll( - status().isOk(), - content().contentType(MediaType.APPLICATION_JSON)) - .andReturn(); + MvcResult mvcResult = mockMvc.perform(get("/v1/study_creation_requests").header(USER_ID_HEADER, "userId")) + .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) + .andReturn(); String resultAsString = mvcResult.getResponse().getContentAsString(); List bsiListResult = mapper.readValue(resultAsString, new TypeReference>() { }); @@ -1210,7 +1205,7 @@ public void testCreateStudyWithErrorDuringStudyCreation() throws Exception { mockMvc.perform(post("/v1/studies/cases/{caseUuid}", CASE_UUID_CAUSING_STUDY_CREATION_ERROR) .header("userId", userId) .param(CASE_FORMAT, "UCTE")) - .andExpect(status().isOk()); + .andExpect(status().isOk()); // assert that the broker message has been sent a study creation request message Message message = output.receive(TIMEOUT, "study.update"); @@ -1236,10 +1231,9 @@ public void testGetStudyCreationRequests() throws Exception { String resultAsString; countDownLatch = new CountDownLatch(1); - mvcResult = mockMvc.perform(get("/v1/study_creation_requests").header(USER_ID_HEADER, "userId")).andExpectAll( - status().isOk(), - content().contentType(MediaType.APPLICATION_JSON)) - .andReturn(); + mvcResult = mockMvc.perform(get("/v1/study_creation_requests").header(USER_ID_HEADER, "userId")) + .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) + .andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); List bsiListResult = mapper.readValue(resultAsString, new TypeReference>() { }); @@ -1255,20 +1249,18 @@ public void testGetStudyCreationRequests() throws Exception { // drop the broker message for study creation request (deletion) output.receive(TIMEOUT, studyUpdateDestination); - mvcResult = mockMvc.perform(get("/v1/study_creation_requests").header(USER_ID_HEADER, "userId")).andExpectAll( - status().isOk(), - content().contentType(MediaType.APPLICATION_JSON)) - .andReturn(); + mvcResult = mockMvc.perform(get("/v1/study_creation_requests").header(USER_ID_HEADER, "userId")) + .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) + .andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); bsiListResult = mapper.readValue(resultAsString, new TypeReference>() { }); assertEquals(List.of(), bsiListResult); - mvcResult = mockMvc.perform(get("/v1/studies").header(USER_ID_HEADER, "userId")).andExpectAll( - status().isOk(), - content().contentType(MediaType.APPLICATION_JSON)) - .andReturn(); + mvcResult = mockMvc.perform(get("/v1/studies").header(USER_ID_HEADER, "userId")) + .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) + .andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); List csbiListResponse = mapper.readValue(resultAsString, new TypeReference>() { }); @@ -1278,9 +1270,9 @@ public void testGetStudyCreationRequests() throws Exception { //insert a study mvcResult = mockMvc.perform(post("/v1/studies/cases/{caseUuid}", NEW_STUDY_CASE_UUID, "false") .header(USER_ID_HEADER, "userId") - .param(CASE_FORMAT, "XIIDM")) - .andExpect(status().isOk()) - .andReturn(); + .param(CASE_FORMAT, "XIIDM")) + .andExpect(status().isOk()) + .andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); BasicStudyInfos bsiResult = mapper.readValue(resultAsString, BasicStudyInfos.class); @@ -1288,10 +1280,9 @@ public void testGetStudyCreationRequests() throws Exception { assertThat(bsiResult, createMatcherStudyBasicInfos(studyCreationRequestRepository.findAll().get(0).getId())); mvcResult = mockMvc.perform(get("/v1/study_creation_requests", NEW_STUDY_CASE_UUID, "false") - .header(USER_ID_HEADER, "userId")).andExpectAll( - status().isOk(), - content().contentType(MediaType.APPLICATION_JSON)) - .andReturn(); + .header(USER_ID_HEADER, "userId")) + .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) + .andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); bsiListResult = mapper.readValue(resultAsString, new TypeReference>() { }); @@ -1307,22 +1298,18 @@ public void testGetStudyCreationRequests() throws Exception { // drop the broker message for study creation request (deletion) output.receive(TIMEOUT, studyUpdateDestination); - mvcResult = mockMvc.perform(get("/v1/study_creation_requests") - .header(USER_ID_HEADER, "userId")).andExpectAll( - status().isOk(), - content().contentType(MediaType.APPLICATION_JSON)) - .andReturn(); + mvcResult = mockMvc.perform(get("/v1/study_creation_requests").header(USER_ID_HEADER, "userId")) + .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) + .andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); bsiListResult = mapper.readValue(resultAsString, new TypeReference>() { }); assertEquals(List.of(), bsiListResult); - mvcResult = mockMvc.perform(get("/v1/studies") - .header(USER_ID_HEADER, "userId")).andExpectAll( - status().isOk(), - content().contentType(MediaType.APPLICATION_JSON)) - .andReturn(); + mvcResult = mockMvc.perform(get("/v1/studies").header(USER_ID_HEADER, "userId")) + .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) + .andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); csbiListResponse = mapper.readValue(resultAsString, new TypeReference>() { }); @@ -1448,10 +1435,9 @@ private void testDuplicateStudy(UUID study1Uuid) throws Exception { UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(createTwoWindingsTransformerAttributes) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isOk()); + .content(createTwoWindingsTransformerAttributes).contentType(MediaType.APPLICATION_JSON) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(study1Uuid, node1.getId()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(node1.getId())); checkUpdateModelsStatusMessagesReceived(study1Uuid, node1.getId()); @@ -1464,10 +1450,9 @@ private void testDuplicateStudy(UUID study1Uuid) throws Exception { stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(createLoadAttributes) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isOk()); + .content(createLoadAttributes).contentType(MediaType.APPLICATION_JSON) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(study1Uuid, node2.getId()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(node2.getId())); checkUpdateModelsStatusMessagesReceived(study1Uuid, node2.getId()); @@ -1491,9 +1476,8 @@ private void testDuplicateStudy(UUID study1Uuid) throws Exception { assertNotEquals(study1Uuid, duplicatedStudy.getId()); //Test duplication from a non existing source study - mockMvc.perform(post(STUDIES_URL + "?duplicateFrom={studyUuid}", UUID.randomUUID()) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isNotFound()); + mockMvc.perform(post(STUDIES_URL + "?duplicateFrom={studyUuid}", UUID.randomUUID()).header(USER_ID_HEADER, "userId")) + .andExpect(status().isNotFound()); } @Test @@ -1530,9 +1514,12 @@ public void testDuplicateStudyWithErrorDuringCaseDuplication() throws Exception }).when(caseService).duplicateCase(any(), any()); String response = mockMvc.perform(post(STUDIES_URL + "?duplicateFrom={studyUuid}", studyUuid) - .param(CASE_FORMAT, "XIIDM") - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isOk()).andReturn().getResponse().getContentAsString(); + .param(CASE_FORMAT, "XIIDM") + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isOk()) + .andReturn() + .getResponse() + .getContentAsString(); ObjectMapper mapper = new ObjectMapper(); String duplicatedStudyUuid = mapper.readValue(response, String.class); @@ -1544,8 +1531,11 @@ public void testDuplicateStudyWithErrorDuringCaseDuplication() throws Exception private StudyEntity duplicateStudy(UUID studyUuid, String userId, String caseFormat) throws Exception { UUID stubUuid = wireMockUtils.stubDuplicateModificationGroup(); String response = mockMvc.perform(post(STUDIES_URL + "?duplicateFrom={studyUuid}", studyUuid) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isOk()).andReturn().getResponse().getContentAsString(); + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isOk()) + .andReturn() + .getResponse() + .getContentAsString(); ObjectMapper mapper = new ObjectMapper(); String newUuid = mapper.readValue(response, String.class); StudyEntity sourceStudy = studyRepository.findById(studyUuid).orElseThrow(); @@ -1668,10 +1658,9 @@ public void testCutAndPasteNode() throws Exception { String createLoadAttributes = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"UNDEFINED\",\"activePower\":\"100.0\",\"reactivePower\":\"50.0\",\"voltageLevelId\":\"idVL1\",\"busId\":\"idBus1\"}"; stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(createLoadAttributes) - .header(USER_ID_HEADER, userId)) - .andExpect(status().isOk()); + .content(createLoadAttributes).contentType(MediaType.APPLICATION_JSON) + .header(USER_ID_HEADER, userId)) + .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(study1Uuid, node2.getId()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(node2.getId())); checkUpdateModelsStatusMessagesReceived(study1Uuid, node2.getId()); @@ -1795,27 +1784,24 @@ public void testCutAndPasteNodeAroundItself() throws Exception { UUID stubGetCountUuid = wireMockUtils.stubNetworkModificationCountGet(node1.getModificationGroupUuid().toString(), 0); //try to cut and paste a node before itself and expect forbidden - mockMvc.perform(post(STUDIES_URL + - "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", - study1Uuid, node1.getId(), node1.getId(), InsertMode.BEFORE) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isForbidden()); + mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", + study1Uuid, node1.getId(), node1.getId(), InsertMode.BEFORE) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isForbidden()); wireMockUtils.verifyNetworkModificationCountsGet(stubGetCountUuid, node1.getModificationGroupUuid().toString()); //try to cut and paste a node after itself and expect forbidden - mockMvc.perform(post(STUDIES_URL + - "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", - study1Uuid, node1.getId(), node1.getId(), InsertMode.AFTER) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isForbidden()); + mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", + study1Uuid, node1.getId(), node1.getId(), InsertMode.AFTER) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isForbidden()); wireMockUtils.verifyNetworkModificationCountsGet(stubGetCountUuid, node1.getModificationGroupUuid().toString()); //try to cut and paste a node in a new branch after itself and expect forbidden - mockMvc.perform(post(STUDIES_URL + - "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", - study1Uuid, node1.getId(), node1.getId(), InsertMode.CHILD) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isForbidden()); + mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", + study1Uuid, node1.getId(), node1.getId(), InsertMode.CHILD) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isForbidden()); wireMockUtils.verifyNetworkModificationCountsGet(stubGetCountUuid, node1.getModificationGroupUuid().toString()); } @@ -1870,26 +1856,23 @@ public void testCutAndPastErrors() throws Exception { NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); //try cut non existing node and expect not found - mockMvc.perform(post(STUDIES_URL + - "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", - study1Uuid, UUID.randomUUID(), node1.getId(), InsertMode.AFTER) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isNotFound()); + mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", + study1Uuid, UUID.randomUUID(), node1.getId(), InsertMode.AFTER) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isNotFound()); //try to cut to a non existing position and expect not found - mockMvc.perform(post(STUDIES_URL + - "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", - study1Uuid, node1.getId(), UUID.randomUUID(), InsertMode.AFTER) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isNotFound()); + mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", + study1Uuid, node1.getId(), UUID.randomUUID(), InsertMode.AFTER) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isNotFound()); //try to cut and paste to before the root node and expect forbidden UUID stubUuid = wireMockUtils.stubNetworkModificationCountGet(node1.getModificationGroupUuid().toString(), 0); - mockMvc.perform(post(STUDIES_URL + - "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", - study1Uuid, node1.getId(), rootNode.getId(), InsertMode.BEFORE) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isForbidden()); + mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", + study1Uuid, node1.getId(), rootNode.getId(), InsertMode.BEFORE) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isForbidden()); wireMockUtils.verifyNetworkModificationCountsGet(stubUuid, node1.getModificationGroupUuid().toString()); } @@ -1905,17 +1888,15 @@ public void testCutAndPasteSubtree() throws Exception { NetworkModificationNode emptyNode = createNetworkModificationNode(study1Uuid, rootNode.getId(), EMPTY_MODIFICATION_GROUP_UUID, VARIANT_ID_2, "emptyNode", BuildStatus.BUILT, userId); NetworkModificationNode emptyNodeChild = createNetworkModificationNode(study1Uuid, emptyNode.getId(), UUID.randomUUID(), VARIANT_ID_3, "emptyNodeChild", BuildStatus.BUILT, userId); - mockMvc.perform(post(STUDIES_URL + - "/{studyUuid}/tree/subtrees?subtreeToCutParentNodeUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}", - study1Uuid, emptyNode.getId(), emptyNodeChild.getId()) + mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/subtrees?subtreeToCutParentNodeUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}", + study1Uuid, emptyNode.getId(), emptyNodeChild.getId()) .header(USER_ID_HEADER, userId)) - .andExpect(status().isForbidden()); + .andExpect(status().isForbidden()); - mockMvc.perform(post(STUDIES_URL + - "/{studyUuid}/tree/subtrees?subtreeToCutParentNodeUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}", - study1Uuid, emptyNode.getId(), node1.getId()) + mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/subtrees?subtreeToCutParentNodeUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}", + study1Uuid, emptyNode.getId(), node1.getId()) .header(USER_ID_HEADER, userId)) - .andExpect(status().isOk()); + .andExpect(status().isOk()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(emptyNode.getId(), emptyNodeChild.getId())); @@ -1946,15 +1927,13 @@ public void testCutAndPasteSubtree() throws Exception { assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(emptyNode.getId()).getGlobalBuildStatus()); assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(emptyNodeChild.getId()).getGlobalBuildStatus()); - mockMvc.perform(get(STUDIES_URL + - "/{studyUuid}/subtree?parentNodeUuid={parentSubtreeNode}", - study1Uuid, emptyNode.getId()) - .header(USER_ID_HEADER, "userId")).andExpect(status().isOk()); + mockMvc.perform(get(STUDIES_URL + "/{studyUuid}/subtree?parentNodeUuid={parentSubtreeNode}", study1Uuid, emptyNode.getId()) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isOk()); - mockMvc.perform(get(STUDIES_URL + - "/{studyUuid}/subtree?parentNodeUuid={parentSubtreeNode}", - study1Uuid, UUID.randomUUID()) - .header(USER_ID_HEADER, "userId")).andExpect(status().isNotFound()); + mockMvc.perform(get(STUDIES_URL + "/{studyUuid}/subtree?parentNodeUuid={parentSubtreeNode}", study1Uuid, UUID.randomUUID()) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isNotFound()); } @Test @@ -1972,10 +1951,9 @@ public void testDuplicateNode() throws Exception { String createTwoWindingsTransformerAttributes = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; UUID stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(createTwoWindingsTransformerAttributes) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isOk()); + .content(createTwoWindingsTransformerAttributes).contentType(MediaType.APPLICATION_JSON) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(study1Uuid, node1.getId()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(node1.getId())); checkUpdateModelsStatusMessagesReceived(study1Uuid, node1.getId()); @@ -1987,10 +1965,9 @@ public void testDuplicateNode() throws Exception { String createLoadAttributes = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"UNDEFINED\",\"activePower\":\"100.0\",\"reactivePower\":\"50.0\",\"voltageLevelId\":\"idVL1\",\"busId\":\"idBus1\"}"; stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(createLoadAttributes) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isOk()); + .content(createLoadAttributes).contentType(MediaType.APPLICATION_JSON) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(study1Uuid, node2.getId()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(node2.getId())); checkUpdateModelsStatusMessagesReceived(study1Uuid, node2.getId()); @@ -2042,25 +2019,22 @@ public void testDuplicateNode() throws Exception { assertEquals(0, allNodes.stream().filter(nodeEntity -> nodeEntity.getParentNode() != null && nodeEntity.getParentNode().getIdNode().equals(duplicatedNodeUuid3)).count()); //try copy non existing node and expect not found - mockMvc.perform(post(STUDIES_URL + - "/{studyUuid}/tree/nodes?nodeToCopyUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}&sourceStudyUuid={sourceStudyUuid}", - study1Uuid, UUID.randomUUID(), node1.getId(), InsertMode.AFTER, study1Uuid) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isNotFound()); + mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCopyUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}&sourceStudyUuid={sourceStudyUuid}", + study1Uuid, UUID.randomUUID(), node1.getId(), InsertMode.AFTER, study1Uuid) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isNotFound()); //try to copy to a non existing position and expect not found - mockMvc.perform(post(STUDIES_URL + - "/{studyUuid}/tree/nodes?nodeToCopyUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}&sourceStudyUuid={sourceStudyUuid}", - study1Uuid, node1.getId(), UUID.randomUUID(), InsertMode.AFTER, study1Uuid) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isNotFound()); + mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCopyUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}&sourceStudyUuid={sourceStudyUuid}", + study1Uuid, node1.getId(), UUID.randomUUID(), InsertMode.AFTER, study1Uuid) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isNotFound()); //try to copy to before the root node and expect forbidden - mockMvc.perform(post(STUDIES_URL + - "/{studyUuid}/tree/nodes?nodeToCopyUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}&sourceStudyUuid={sourceStudyUuid}", - study1Uuid, node1.getId(), rootNode.getId(), InsertMode.BEFORE, study1Uuid) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isForbidden()); + mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCopyUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}&sourceStudyUuid={sourceStudyUuid}", + study1Uuid, node1.getId(), rootNode.getId(), InsertMode.BEFORE, study1Uuid) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isForbidden()); // Test Built status when duplicating an empty node assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(node3.getId()).getGlobalBuildStatus()); @@ -2092,10 +2066,9 @@ public void testDuplicateSubtree() throws Exception { String createTwoWindingsTransformerAttributes = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; UUID stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(createTwoWindingsTransformerAttributes) + .content(createTwoWindingsTransformerAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, "userId")) - .andExpect(status().isOk()); + .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(study1Uuid, node1.getId()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(node1.getId(), node3.getId())); checkUpdateModelsStatusMessagesReceived(study1Uuid, node1.getId()); @@ -2112,10 +2085,9 @@ public void testDuplicateSubtree() throws Exception { String createLoadAttributes = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"UNDEFINED\",\"activePower\":\"100.0\",\"reactivePower\":\"50.0\",\"voltageLevelId\":\"idVL1\",\"busId\":\"idBus1\"}"; stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(createLoadAttributes) + .content(createLoadAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, "userId")) - .andExpect(status().isOk()); + .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(study1Uuid, node2.getId()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(node2.getId())); checkUpdateModelsStatusMessagesReceived(study1Uuid, node2.getId()); @@ -2138,11 +2110,10 @@ public void testDuplicateSubtree() throws Exception { List allNodesBeforeDuplication = networkModificationTreeService.getAllNodes(study1Uuid).stream().map(NodeEntity::getIdNode).collect(Collectors.toList()); UUID stubDuplicateUuid = wireMockUtils.stubDuplicateModificationGroup(); - mockMvc.perform(post(STUDIES_URL + - "/{study1Uuid}/tree/subtrees?subtreeToCopyParentNodeUuid={parentNodeToCopy}&referenceNodeUuid={referenceNodeUuid}&sourceStudyUuid={sourceStudyUuid}", - study1Uuid, node1.getId(), node4.getId(), study1Uuid) + mockMvc.perform(post(STUDIES_URL + "/{study1Uuid}/tree/subtrees?subtreeToCopyParentNodeUuid={parentNodeToCopy}&referenceNodeUuid={referenceNodeUuid}&sourceStudyUuid={sourceStudyUuid}", + study1Uuid, node1.getId(), node4.getId(), study1Uuid) .header(USER_ID_HEADER, "userId")) - .andExpect(status().isOk()); + .andExpect(status().isOk()); List nodesAfterDuplication = networkModificationTreeService.getAllNodes(study1Uuid).stream().map(NodeEntity::getIdNode).collect(Collectors.toList()); nodesAfterDuplication.removeAll(allNodesBeforeDuplication); @@ -2164,15 +2135,13 @@ public void testDuplicateSubtree() throws Exception { └── node 3 duplicated */ - mockMvc.perform(get(STUDIES_URL + - "/{studyUuid}/subtree?parentNodeUuid={parentSubtreeNode}", - study1Uuid, nodesAfterDuplication.get(0)) - .header(USER_ID_HEADER, "userId")).andExpect(status().isOk()); + mockMvc.perform(get(STUDIES_URL + "/{studyUuid}/subtree?parentNodeUuid={parentSubtreeNode}", study1Uuid, nodesAfterDuplication.get(0)) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isOk()); - mockMvc.perform(get(STUDIES_URL + - "/{studyUuid}/subtree?parentNodeUuid={parentSubtreeNode}", - study1Uuid, UUID.randomUUID()) - .header(USER_ID_HEADER, "userId")).andExpect(status().isNotFound()); + mockMvc.perform(get(STUDIES_URL + "/{studyUuid}/subtree?parentNodeUuid={parentSubtreeNode}", study1Uuid, UUID.randomUUID()) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isNotFound()); allNodes = networkModificationTreeService.getAllNodes(study1Uuid); @@ -2196,18 +2165,16 @@ public void testDuplicateSubtree() throws Exception { assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(nodesAfterDuplication.get(1)).getGlobalBuildStatus()); //try copy non existing node and expect not found - mockMvc.perform(post(STUDIES_URL + - "/{targetStudyUuid}/tree/subtrees?subtreeToCopyParentNodeUuid={parentNodeToCopy}&referenceNodeUuid={referenceNodeUuid}&sourceStudyUuid={sourceStudyUuid}", - study1Uuid, UUID.randomUUID(), node1.getId(), study1Uuid) + mockMvc.perform(post(STUDIES_URL + "/{targetStudyUuid}/tree/subtrees?subtreeToCopyParentNodeUuid={parentNodeToCopy}&referenceNodeUuid={referenceNodeUuid}&sourceStudyUuid={sourceStudyUuid}", + study1Uuid, UUID.randomUUID(), node1.getId(), study1Uuid) .header(USER_ID_HEADER, "userId")) - .andExpect(status().isNotFound()); + .andExpect(status().isNotFound()); //try to copy to a non existing position and expect not found - mockMvc.perform(post(STUDIES_URL + - "/{targetStudyUuid}/tree/subtrees?subtreeToCopyParentNodeUuid={parentNodeToCopy}&referenceNodeUuid={referenceNodeUuid}&sourceStudyUuid={sourceStudyUuid}", - study1Uuid, node1.getId(), UUID.randomUUID(), study1Uuid) + mockMvc.perform(post(STUDIES_URL + "/{targetStudyUuid}/tree/subtrees?subtreeToCopyParentNodeUuid={parentNodeToCopy}&referenceNodeUuid={referenceNodeUuid}&sourceStudyUuid={sourceStudyUuid}", + study1Uuid, node1.getId(), UUID.randomUUID(), study1Uuid) .header(USER_ID_HEADER, "userId")) - .andExpect(status().isNotFound()); + .andExpect(status().isNotFound()); } @Test @@ -2228,10 +2195,9 @@ public void testDuplicateNodeBetweenStudies() throws Exception { UUID stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); String createTwoWindingsTransformerAttributes = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(createTwoWindingsTransformerAttributes) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isOk()); + .content(createTwoWindingsTransformerAttributes).contentType(MediaType.APPLICATION_JSON) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(study1Uuid, node1.getId()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(node1.getId())); checkUpdateModelsStatusMessagesReceived(study1Uuid, node1.getId()); @@ -2243,10 +2209,9 @@ public void testDuplicateNodeBetweenStudies() throws Exception { stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); String createLoadAttributes = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"UNDEFINED\",\"activePower\":\"100.0\",\"reactivePower\":\"50.0\",\"voltageLevelId\":\"idVL1\",\"busId\":\"idBus1\"}"; mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(createLoadAttributes) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isOk()); + .content(createLoadAttributes).contentType(MediaType.APPLICATION_JSON) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(study1Uuid, node2.getId()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(node2.getId())); checkUpdateModelsStatusMessagesReceived(study1Uuid, node2.getId()); @@ -2273,11 +2238,10 @@ public void testDuplicateNodeBetweenStudies() throws Exception { private void cutAndPasteNode(UUID studyUuid, NetworkModificationNode nodeToCopy, UUID referenceNodeUuid, InsertMode insertMode, int childCount, String userId) throws Exception { UUID stubUuid = wireMockUtils.stubNetworkModificationCountGet(nodeToCopy.getModificationGroupUuid().toString(), EMPTY_MODIFICATION_GROUP_UUID.equals(nodeToCopy.getModificationGroupUuid()) ? 0 : 1); - mockMvc.perform(post(STUDIES_URL + - "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", - studyUuid, nodeToCopy.getId(), referenceNodeUuid, insertMode) - .header(USER_ID_HEADER, userId)) - .andExpect(status().isOk()); + mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", + studyUuid, nodeToCopy.getId(), referenceNodeUuid, insertMode) + .header(USER_ID_HEADER, userId)) + .andExpect(status().isOk()); checkElementUpdatedMessageSent(studyUuid, userId); wireMockUtils.verifyNetworkModificationCountsGet(stubUuid, nodeToCopy.getModificationGroupUuid().toString()); @@ -2356,17 +2320,15 @@ private UUID duplicateNode(UUID sourceStudyUuid, UUID targetStudyUuid, NetworkMo UUID stubDuplicateUuid = wireMockUtils.stubDuplicateModificationGroup(); if (sourceStudyUuid.equals(targetStudyUuid)) { //if source and target are the same no need to pass sourceStudy param - mockMvc.perform(post(STUDIES_URL + - "/{targetStudyUuid}/tree/nodes?nodeToCopyUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", - targetStudyUuid, nodeToCopy.getId(), referenceNodeUuid, insertMode) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isOk()); + mockMvc.perform(post(STUDIES_URL + "/{targetStudyUuid}/tree/nodes?nodeToCopyUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", + targetStudyUuid, nodeToCopy.getId(), referenceNodeUuid, insertMode) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isOk()); } else { - mockMvc.perform(post(STUDIES_URL + - "/{targetStudyUuid}/tree/nodes?nodeToCopyUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}&sourceStudyUuid={sourceStudyUuid}", - targetStudyUuid, nodeToCopy.getId(), referenceNodeUuid, insertMode, sourceStudyUuid) - .header(USER_ID_HEADER, "userId")) - .andExpect(status().isOk()); + mockMvc.perform(post(STUDIES_URL + "/{targetStudyUuid}/tree/nodes?nodeToCopyUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}&sourceStudyUuid={sourceStudyUuid}", + targetStudyUuid, nodeToCopy.getId(), referenceNodeUuid, insertMode, sourceStudyUuid) + .header(USER_ID_HEADER, "userId")) + .andExpect(status().isOk()); } List nodesAfterDuplication = networkModificationTreeService.getAllNodes(targetStudyUuid).stream().map(NodeEntity::getIdNode).collect(Collectors.toList()); @@ -2389,21 +2351,17 @@ private UUID duplicateNode(UUID sourceStudyUuid, UUID targetStudyUuid, NetworkMo @Test public void testGetDefaultProviders() throws Exception { // related to LoadFlowTest::testGetDefaultProvidersFromProfile but without a user, so it doesn't use profiles - mockMvc.perform(get("/v1/loadflow-default-provider")).andExpectAll( - status().isOk(), - content().string(DEFAULT_PROVIDER)); - mockMvc.perform(get("/v1/security-analysis-default-provider")).andExpectAll( - status().isOk(), - content().string(DEFAULT_PROVIDER)); - mockMvc.perform(get("/v1/sensitivity-analysis-default-provider")).andExpectAll( - status().isOk(), - content().string(DEFAULT_PROVIDER)); + mockMvc.perform(get("/v1/loadflow-default-provider")) + .andExpectAll(status().isOk(), content().string(DEFAULT_PROVIDER)); + mockMvc.perform(get("/v1/security-analysis-default-provider")) + .andExpectAll(status().isOk(), content().string(DEFAULT_PROVIDER)); + mockMvc.perform(get("/v1/sensitivity-analysis-default-provider")) + .andExpectAll(status().isOk(), content().string(DEFAULT_PROVIDER)); var requests = TestUtils.getRequestsDone(3, server); assertTrue(requests.stream().allMatch(r -> r.matches("/v1/default-provider"))); - mockMvc.perform(get("/v1/non-evacuated-energy-default-provider")).andExpectAll( - status().isOk(), - content().string(defaultNonEvacuatedEnergyProvider)); + mockMvc.perform(get("/v1/non-evacuated-energy-default-provider")) + .andExpectAll(status().isOk(), content().string(defaultNonEvacuatedEnergyProvider)); } private void checkSubtreeMovedMessageSent(UUID studyUuid, UUID movedNodeUuid, UUID referenceNodeUuid) { @@ -2433,15 +2391,15 @@ private void checkElementUpdatedMessageSent(UUID elementUuid, String userId) { @Test public void reindexStudyTest() throws Exception { mockMvc.perform(post("/v1/studies/{studyUuid}/reindex-all", UUID.randomUUID())) - .andExpect(status().isNotFound()); + .andExpect(status().isNotFound()); mockMvc.perform(get("/v1/studies/{studyUuid}/indexation/status", UUID.randomUUID())) - .andExpectAll(status().isNotFound()); + .andExpectAll(status().isNotFound()); UUID notExistingNetworkStudyUuid = createStudy("userId", NOT_EXISTING_NETWORK_CASE_UUID); mockMvc.perform(post("/v1/studies/{studyUuid}/reindex-all", notExistingNetworkStudyUuid)) - .andExpect(status().isInternalServerError()); + .andExpect(status().isInternalServerError()); Message indexationStatusMessageOnGoing = output.receive(TIMEOUT, studyUpdateDestination); Message indexationStatusMessageNotIndexed = output.receive(TIMEOUT, studyUpdateDestination); @@ -2449,7 +2407,7 @@ public void reindexStudyTest() throws Exception { assertTrue(requests.stream().anyMatch(r -> r.getPath().contains("/v1/networks/" + NOT_EXISTING_NETWORK_UUID + "/reindex-all"))); mockMvc.perform(get("/v1/studies/{studyUuid}/indexation/status", notExistingNetworkStudyUuid)) - .andExpectAll(status().isInternalServerError()); + .andExpectAll(status().isInternalServerError()); requests = TestUtils.getRequestsWithBodyDone(1, server); assertEquals(1, requests.stream().filter(r -> r.getPath().contains("/v1/networks/" + NOT_EXISTING_NETWORK_UUID + "/indexed-equipments")).count()); @@ -2457,12 +2415,11 @@ public void reindexStudyTest() throws Exception { UUID study1Uuid = createStudy("userId", CASE_UUID); mockMvc.perform(get("/v1/studies/{studyUuid}/indexation/status", study1Uuid)) - .andExpectAll(status().isOk(), - content().string("NOT_INDEXED")); + .andExpectAll(status().isOk(), content().string("NOT_INDEXED")); indexationStatusMessageNotIndexed = output.receive(TIMEOUT, studyUpdateDestination); mockMvc.perform(post("/v1/studies/{studyUuid}/reindex-all", study1Uuid)) - .andExpect(status().isOk()); + .andExpect(status().isOk()); indexationStatusMessageOnGoing = output.receive(TIMEOUT, studyUpdateDestination); Message indexationStatusMessageDone = output.receive(TIMEOUT, studyUpdateDestination); @@ -2470,8 +2427,7 @@ public void reindexStudyTest() throws Exception { assertEquals(NotificationService.UPDATE_TYPE_INDEXATION_STATUS, indexationStatusMessageDone.getHeaders().get(HEADER_UPDATE_TYPE)); mockMvc.perform(get("/v1/studies/{studyUuid}/indexation/status", study1Uuid)) - .andExpectAll(status().isOk(), - content().string("INDEXED")); + .andExpectAll(status().isOk(), content().string("INDEXED")); requests = TestUtils.getRequestsWithBodyDone(4, server); assertTrue(requests.stream().anyMatch(r -> r.getPath().contains("/v1/networks/" + NETWORK_UUID_STRING + "/reindex-all"))); @@ -2483,7 +2439,7 @@ public void reindexStudyTest() throws Exception { assertEquals(NotificationService.NODE_BUILD_STATUS_UPDATED, buildStatusMessage.getHeaders().get(HEADER_UPDATE_TYPE)); mockMvc.perform(post("/v1/studies/{studyUuid}/reindex-all", study1Uuid)) - .andExpect(status().is5xxServerError()); + .andExpect(status().is5xxServerError()); indexationStatusMessageOnGoing = output.receive(TIMEOUT, studyUpdateDestination); indexationStatusMessageNotIndexed = output.receive(TIMEOUT, studyUpdateDestination); @@ -2496,42 +2452,37 @@ public void providerTest() throws Exception { UUID studyUuid = createStudy(USER_ID_HEADER, CASE_UUID); assertNotNull(studyUuid); mockMvc.perform(get("/v1/studies/{studyUuid}/non-evacuated-energy/provider", studyUuid)) - .andExpectAll(status().isOk(), - content().string(defaultNonEvacuatedEnergyProvider)); + .andExpectAll(status().isOk(), content().string(defaultNonEvacuatedEnergyProvider)); mockMvc.perform(post("/v1/studies/{studyUuid}/loadflow/provider", studyUuid) - .content("SuperLF") - .contentType(MediaType.TEXT_PLAIN) + .content("SuperLF").contentType(MediaType.TEXT_PLAIN) .header(USER_ID_HEADER, USER_ID_HEADER)) - .andExpect(status().isOk()); + .andExpect(status().isOk()); Message message = output.receive(TIMEOUT, studyUpdateDestination); assertNotNull(message); assertEquals(NotificationService.UPDATE_TYPE_LOADFLOW_STATUS, message.getHeaders().get(HEADER_UPDATE_TYPE)); assertNotNull(output.receive(TIMEOUT, elementUpdateDestination)); mockMvc.perform(post("/v1/studies/{studyUuid}/security-analysis/provider", studyUuid) - .content("SuperSA") - .contentType(MediaType.TEXT_PLAIN) + .content("SuperSA").contentType(MediaType.TEXT_PLAIN) .header(USER_ID_HEADER, USER_ID_HEADER)) - .andExpect(status().isOk()); + .andExpect(status().isOk()); message = output.receive(TIMEOUT, studyUpdateDestination); assertNotNull(message); assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS, message.getHeaders().get(HEADER_UPDATE_TYPE)); assertNotNull(output.receive(TIMEOUT, elementUpdateDestination)); mockMvc.perform(post("/v1/studies/{studyUuid}/non-evacuated-energy/provider", studyUuid) - .content("SuperNEE") - .contentType(MediaType.TEXT_PLAIN) - .header(USER_ID_HEADER, USER_ID_HEADER)) - .andExpect(status().isOk()); + .content("SuperNEE").contentType(MediaType.TEXT_PLAIN) + .header(USER_ID_HEADER, USER_ID_HEADER)) + .andExpect(status().isOk()); message = output.receive(TIMEOUT, studyUpdateDestination); assertNotNull(message); assertEquals(NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_STATUS, message.getHeaders().get(HEADER_UPDATE_TYPE)); assertNotNull(output.receive(TIMEOUT, elementUpdateDestination)); mockMvc.perform(get("/v1/studies/{studyUuid}/non-evacuated-energy/provider", studyUuid)) - .andExpectAll(status().isOk(), - content().string("SuperNEE")); + .andExpectAll(status().isOk(), content().string("SuperNEE")); var requests = TestUtils.getRequestsDone(2, server); assertTrue(requests.stream().allMatch(r -> r.matches("/v1/parameters/.*/provider")));