Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan-WorkGH committed Jun 10, 2024
1 parent bfb2daa commit 324f5d7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
36 changes: 18 additions & 18 deletions src/test/java/org/gridsuite/study/server/ShortCircuitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,41 +181,41 @@ public MockResponse dispatch(RecordedRequest request) {
.setHeader("busId", "BUS_TEST_ID")
.build(), shortCircuitAnalysisResultDestination);
return new MockResponse().setResponseCode(200)
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE)
.setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_UUID);
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
.setBody("\"" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "\"");
} else if (path.matches("^/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.+&reportUuid=.+&reporterId=.+&variantId=" + VARIANT_ID_2 + "$")) {
input.send(MessageBuilder.withPayload("")
.setHeader("resultUuid", SHORT_CIRCUIT_ANALYSIS_RESULT_UUID)
.setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D")
.build(), shortCircuitAnalysisResultDestination);
return new MockResponse().setResponseCode(200)
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE)
.setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_UUID);
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
.setBody("\"" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "\"");
} else if (path.matches("^/v1/networks/" + NETWORK_UUID_STRING_NOT_FOUND + "/run-and-save\\?receiver=.+&reportUuid=.+&reporterId=.+&variantId=" + VARIANT_ID_4 + "$")) {
input.send(MessageBuilder.withPayload("")
.setHeader("resultUuid", SHORT_CIRCUIT_ANALYSIS_RESULT_UUID_NOT_FOUND)
.setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D")
.build(), shortCircuitAnalysisResultDestination);
return new MockResponse().setResponseCode(200)
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE)
.setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_UUID_NOT_FOUND);
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
.setBody("\"" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID_NOT_FOUND + "\"");
} else if (path.matches("^/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.+&reportUuid=.+&reporterId=.+&variantId=" + VARIANT_ID + "$")) {
input.send(MessageBuilder.withPayload("")
.setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D")
.build(), shortCircuitAnalysisFailedDestination);
return new MockResponse().setResponseCode(200)
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE)
.setBody(SHORT_CIRCUIT_ANALYSIS_ERROR_RESULT_UUID);
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
.setBody("\"" + SHORT_CIRCUIT_ANALYSIS_ERROR_RESULT_UUID + "\"");
} else if (path.equals("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "?mode=FULL")) {
return new MockResponse().setResponseCode(200)
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
.setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON);
.setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON + "}");
} else if (path.equals("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/fault-types")) {
return new MockResponse().setResponseCode(200);
} else if (path.equals("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/fault_results/paged?mode=FULL&page=0&size=20&sort=id,DESC")) {
return new MockResponse().setResponseCode(200)
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
.setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON);
.setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON + "}");
} else if (path.equals("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/csv")) {
return new MockResponse().setResponseCode(200)
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
Expand All @@ -225,7 +225,7 @@ public MockResponse dispatch(RecordedRequest request) {
} else if (path.equals("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/feeder_results/paged?mode=FULL&filters=fakeFilters&page=0&size=20&sort=id,DESC")) {
return new MockResponse().setResponseCode(200)
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
.setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON);
.setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON + "}");
} else if (path.equals("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/status")) {
return new MockResponse().setResponseCode(200)
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
Expand All @@ -245,8 +245,8 @@ public MockResponse dispatch(RecordedRequest request) {
return new MockResponse().setResponseCode(200);
} else if (path.equals("/v1/supervision/results-count")) {
return new MockResponse().setResponseCode(200).setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE).setBody("1");
} else if ("POST".equalsIgnoreCase(request.getMethod()) && path.equals("/v1/parameters")) {
return new MockResponse().setResponseCode(200).setHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE).setBody(SHORT_CIRCUIT_ANALYSIS_PARAMETERS_UUID);
} else if ("POST".equalsIgnoreCase(request.getMethod()) && path.equals("/v1/parameters/default")) {
return new MockResponse().setResponseCode(200).setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE).setBody("\"" + SHORT_CIRCUIT_ANALYSIS_PARAMETERS_UUID + "\"");
} else if ("GET".equalsIgnoreCase(request.getMethod()) && path.equals("/v1/parameters/" + SHORT_CIRCUIT_ANALYSIS_PARAMETERS_UUID)) {
return new MockResponse().setResponseCode(200).setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE).setBody(TestUtils.resourceToString("/short-circuit-parameters.json"));
} else if ("PUT".equalsIgnoreCase(request.getMethod()) && path.equals("/v1/parameters/" + SHORT_CIRCUIT_ANALYSIS_PARAMETERS_UUID)) {
Expand All @@ -270,7 +270,7 @@ public void testShortCircuitAnalysisParameters() throws Exception {
//get default ShortCircuitParameters
mockMvc.perform(get("/v1/studies/{studyUuid}/short-circuit-analysis/parameters", studyNameUserIdUuid))
.andExpectAll(status().isOk(), content().string(TestUtils.resourceToString("/short-circuit-parameters.json")));
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.equals("/v1/parameters")));
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.equals("/v1/parameters/default")));
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.equals("/v1/parameters/" + SHORT_CIRCUIT_ANALYSIS_PARAMETERS_UUID)));

mockMvc.perform(post("/v1/studies/{studyUuid}/short-circuit-analysis/parameters", studyNameUserIdUuid)
Expand Down Expand Up @@ -327,7 +327,7 @@ public void testAllBusesShortCircuit() throws Exception {
mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/shortcircuit/result", studyNameUserIdUuid, modificationNode3Uuid))
.andExpectAll(
status().isOk(),
content().string(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON));
content().string(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON + "}"));

assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.equals("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "?mode=FULL")));

Expand Down Expand Up @@ -468,7 +468,7 @@ public void testPagedShortCircuit() throws Exception {
// get short circuit result with pagination
mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/shortcircuit/result?paged=true&page=0&size=20&sort=id,DESC", studyNameUserIdUuid, modificationNode1Uuid)).andExpectAll(
status().isOk(),
content().string(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON));
content().string(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON + "}"));

assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.equals("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/fault_results/paged?mode=FULL&page=0&size=20&sort=id,DESC")));

Expand Down Expand Up @@ -541,7 +541,7 @@ public void testOneBusShortCircuit() throws Exception {
.param("type", ShortcircuitAnalysisType.ONE_BUS.name()))
.andExpectAll(
status().isOk(),
content().string(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON)
content().string(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON + "}")
);

assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.equals("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "?mode=FULL")));
Expand All @@ -551,7 +551,7 @@ public void testOneBusShortCircuit() throws Exception {
.param("type", ShortcircuitAnalysisType.ONE_BUS.name())
).andExpectAll(
status().isOk(),
content().string(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON));
content().string(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON + "}"));

assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.equals("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/feeder_results/paged?mode=FULL&filters=fakeFilters&page=0&size=20&sort=id,DESC")));

Expand Down
7 changes: 2 additions & 5 deletions src/test/java/org/gridsuite/study/server/StudyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -482,17 +482,14 @@ public MockResponse dispatch(RecordedRequest request) {
} else if (path.matches("/v1/networks\\?caseUuid=" + CLONED_CASE_UUID_STRING + "&variantId=" + FIRST_VARIANT_ID + "&reportUuid=.*&receiver=.*")) {
sendCaseImportSucceededMessage(path, NETWORK_INFOS, "UCTE");
return new MockResponse().setResponseCode(200);
} else if (path.matches("/v1/parameters.*") && POST.equals(request.getMethod())) {
} else if (path.startsWith("/v1/parameters") && POST.equals(request.getMethod())) {
if (path.matches("/v1/parameters\\?duplicateFrom=" + PROFILE_LOADFLOW_INVALID_PARAMETERS_UUID_STRING)) {
return new MockResponse().setResponseCode(404); // params duplication request KO
} else if (path.matches("/v1/parameters\\?duplicateFrom=" + PROFILE_LOADFLOW_VALID_PARAMETERS_UUID_STRING)) {
return new MockResponse().setResponseCode(200).setBody(DUPLICATED_PARAMS_JSON) // params duplication request OK
.addHeader("Content-Type", "application/json; charset=utf-8");
} else if (path.equals("/v1/parameters")
|| path.matches("/v1/parameters\\?duplicateFrom=.+") && request.getHeaders().get(HttpHeaders.ACCEPT).contains(MediaType.TEXT_PLAIN_VALUE)) {
return new MockResponse().setResponseCode(200).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN).setBody(UUID.randomUUID().toString());
} else {
return new MockResponse().setResponseCode(200).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).setBody(mapper.writeValueAsString(UUID.randomUUID()));
return new MockResponse().setResponseCode(200).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).setBody("\"" + UUID.randomUUID() + "\"");
}
} else if (path.matches("/v1/parameters/.*") && DELETE.equals(request.getMethod())) {
return new MockResponse().setResponseCode(200);
Expand Down

0 comments on commit 324f5d7

Please sign in to comment.