Skip to content

Commit

Permalink
Move PR to #587
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan-WorkGH committed Jun 10, 2024
1 parent e92d510 commit 2222273
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions src/test/java/org/gridsuite/study/server/StudyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ 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>() {
});
modificationInfos.setSubstationIds(Set.of("s2"));
return new MockResponse().setResponseCode(200)
.setBody("[" + mapper.writeValueAsString(modificationInfos) + "]")
Expand Down Expand Up @@ -709,31 +710,37 @@ public void testSearch() throws Exception {
.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<CreatedStudyBasicInfos> createdStudyBasicInfosList = mapper.readValue(resultAsString, new TypeReference<>() { });
List<CreatedStudyBasicInfos> createdStudyBasicInfosList = mapper.readValue(resultAsString,
new TypeReference<List<CreatedStudyBasicInfos>>() {
});
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();
resultAsString = mvcResult.getResponse().getContentAsString();
List<EquipmentInfos> equipmentInfos = mapper.readValue(resultAsString, new TypeReference<>() { });
List<EquipmentInfos> equipmentInfos = mapper.readValue(resultAsString,
new TypeReference<List<EquipmentInfos>>() {
});
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();
resultAsString = mvcResult.getResponse().getContentAsString();
equipmentInfos = mapper.readValue(resultAsString, new TypeReference<>() { });
equipmentInfos = mapper.readValue(resultAsString, new TypeReference<List<EquipmentInfos>>() {
});
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();
resultAsString = mvcResult.getResponse().getContentAsString();
equipmentInfos = mapper.readValue(resultAsString, new TypeReference<>() { });
equipmentInfos = mapper.readValue(resultAsString, new TypeReference<List<EquipmentInfos>>() {
});
assertThat(equipmentInfos, new MatcherJson<>(mapper, linesInfos));

mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/search?userInput={request}&fieldSelector=bogus",
Expand Down Expand Up @@ -782,7 +789,9 @@ public void test() throws Exception {
.andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn();

resultAsString = result.getResponse().getContentAsString();
List<CreatedStudyBasicInfos> createdStudyBasicInfosList = mapper.readValue(resultAsString, new TypeReference<>() { });
List<CreatedStudyBasicInfos> createdStudyBasicInfosList = mapper.readValue(resultAsString,
new TypeReference<List<CreatedStudyBasicInfos>>() {
});

assertThat(createdStudyBasicInfosList.get(0), createMatcherCreatedStudyBasicInfos(studyUuid, "UCTE"));

Expand All @@ -793,7 +802,9 @@ public void test() throws Exception {
resultAsString = mockMvc.perform(get("/v1/studies").header("userId", "userId2"))
.andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getContentAsString();

createdStudyBasicInfosList = mapper.readValue(resultAsString, new TypeReference<>() { });
createdStudyBasicInfosList = mapper.readValue(resultAsString,
new TypeReference<List<CreatedStudyBasicInfos>>() {
});

assertThat(createdStudyBasicInfosList.get(1),
createMatcherCreatedStudyBasicInfos(studyUuid, "UCTE"));
Expand All @@ -813,7 +824,9 @@ public void test() throws Exception {
.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<List<CreatedStudyBasicInfos>>() {
});
assertEquals(2, createdStudyBasicInfosList.size());

//get available export format
Expand Down Expand Up @@ -952,7 +965,9 @@ public void testMetadata() throws Exception {
.header(USER_ID_HEADER, "userId"))
.andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn();
String resultAsString = mvcResult.getResponse().getContentAsString();
List<CreatedStudyBasicInfos> createdStudyBasicInfosList = mapper.readValue(resultAsString, new TypeReference<>() { });
List<CreatedStudyBasicInfos> createdStudyBasicInfosList = mapper.readValue(resultAsString,
new TypeReference<List<CreatedStudyBasicInfos>>() {
});

assertNotNull(createdStudyBasicInfosList);
assertEquals(2, createdStudyBasicInfosList.size());
Expand Down Expand Up @@ -986,7 +1001,7 @@ public void testLogsReport() throws Exception {
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<ReportNode> reporterModel = mapper.readValue(resultAsString, new TypeReference<>() { });
List<ReportNode> reporterModel = mapper.readValue(resultAsString, new TypeReference<List<ReportNode>>() { });

assertThat(reporterModel.get(0), new MatcherReport(REPORT_TEST));
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/reports/.*")));
Expand Down Expand Up @@ -1165,7 +1180,7 @@ public void testCreateStudyWithErrorDuringCaseImport() throws Exception {
.andReturn();

String resultAsString = mvcResult.getResponse().getContentAsString();
List<BasicStudyInfos> bsiListResult = mapper.readValue(resultAsString, new TypeReference<>() { });
List<BasicStudyInfos> bsiListResult = mapper.readValue(resultAsString, new TypeReference<List<BasicStudyInfos>>() { });

assertEquals(List.of(), bsiListResult);

Expand Down Expand Up @@ -1235,7 +1250,7 @@ public void testGetStudyCreationRequests() throws Exception {
content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
resultAsString = mvcResult.getResponse().getContentAsString();
List<BasicStudyInfos> bsiListResult = mapper.readValue(resultAsString, new TypeReference<>() { });
List<BasicStudyInfos> bsiListResult = mapper.readValue(resultAsString, new TypeReference<List<BasicStudyInfos>>() { });

// once we checked study creation requests, we can countDown latch to trigger study creation request
countDownLatch.countDown();
Expand All @@ -1255,7 +1270,7 @@ public void testGetStudyCreationRequests() throws Exception {
.andReturn();

resultAsString = mvcResult.getResponse().getContentAsString();
bsiListResult = mapper.readValue(resultAsString, new TypeReference<>() { });
bsiListResult = mapper.readValue(resultAsString, new TypeReference<List<BasicStudyInfos>>() { });

assertEquals(List.of(), bsiListResult);

Expand All @@ -1265,7 +1280,7 @@ public void testGetStudyCreationRequests() throws Exception {
.andReturn();

resultAsString = mvcResult.getResponse().getContentAsString();
List<CreatedStudyBasicInfos> csbiListResponse = mapper.readValue(resultAsString, new TypeReference<>() { });
List<CreatedStudyBasicInfos> csbiListResponse = mapper.readValue(resultAsString, new TypeReference<List<CreatedStudyBasicInfos>>() { });

countDownLatch = new CountDownLatch(1);

Expand All @@ -1288,7 +1303,7 @@ public void testGetStudyCreationRequests() throws Exception {
.andReturn();
resultAsString = mvcResult.getResponse().getContentAsString();

bsiListResult = mapper.readValue(resultAsString, new TypeReference<>() { });
bsiListResult = mapper.readValue(resultAsString, new TypeReference<List<BasicStudyInfos>>() { });

countDownLatch.countDown();

Expand All @@ -1308,7 +1323,7 @@ public void testGetStudyCreationRequests() throws Exception {
.andReturn();
resultAsString = mvcResult.getResponse().getContentAsString();

bsiListResult = mapper.readValue(resultAsString, new TypeReference<>() { });
bsiListResult = mapper.readValue(resultAsString, new TypeReference<List<BasicStudyInfos>>() { });

assertEquals(List.of(), bsiListResult);

Expand All @@ -1318,7 +1333,7 @@ public void testGetStudyCreationRequests() throws Exception {
content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
resultAsString = mvcResult.getResponse().getContentAsString();
csbiListResponse = mapper.readValue(resultAsString, new TypeReference<>() { });
csbiListResponse = mapper.readValue(resultAsString, new TypeReference<List<CreatedStudyBasicInfos>>() { });

// assert that all http requests have been sent to remote services
var requests = TestUtils.getRequestsDone(8, server);
Expand Down Expand Up @@ -1509,6 +1524,7 @@ public void testDuplicateStudyWithErrorDuringCaseDuplication() throws Exception
.header(USER_ID_HEADER, "userId"))
.andExpect(status().isOk()).andReturn().getResponse().getContentAsString();

ObjectMapper mapper = new ObjectMapper();
String duplicatedStudyUuid = mapper.readValue(response, String.class);
assertNotNull(output.receive(TIMEOUT, studyUpdateDestination));

Expand All @@ -1520,6 +1536,7 @@ private StudyEntity duplicateStudy(UUID studyUuid) throws Exception {
String response = mockMvc.perform(post(STUDIES_URL + "?duplicateFrom={studyUuid}", studyUuid)
.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();
assertNotNull(output.receive(TIMEOUT, studyUpdateDestination));
Expand Down

0 comments on commit 2222273

Please sign in to comment.