diff --git a/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java b/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java index 4c7ffb737..d20d1dc5a 100644 --- a/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java +++ b/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java @@ -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) @@ -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) @@ -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)) { @@ -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) @@ -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"))); @@ -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"))); @@ -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"))); @@ -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"))); diff --git a/src/test/java/org/gridsuite/study/server/StudyTest.java b/src/test/java/org/gridsuite/study/server/StudyTest.java index 28e5e773e..96eab9886 100644 --- a/src/test/java/org/gridsuite/study/server/StudyTest.java +++ b/src/test/java/org/gridsuite/study/server/StudyTest.java @@ -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);