Skip to content

Commit 324f5d7

Browse files
fix tests
1 parent bfb2daa commit 324f5d7

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

src/test/java/org/gridsuite/study/server/ShortCircuitTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -181,41 +181,41 @@ public MockResponse dispatch(RecordedRequest request) {
181181
.setHeader("busId", "BUS_TEST_ID")
182182
.build(), shortCircuitAnalysisResultDestination);
183183
return new MockResponse().setResponseCode(200)
184-
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE)
185-
.setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_UUID);
184+
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
185+
.setBody("\"" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "\"");
186186
} else if (path.matches("^/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.+&reportUuid=.+&reporterId=.+&variantId=" + VARIANT_ID_2 + "$")) {
187187
input.send(MessageBuilder.withPayload("")
188188
.setHeader("resultUuid", SHORT_CIRCUIT_ANALYSIS_RESULT_UUID)
189189
.setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D")
190190
.build(), shortCircuitAnalysisResultDestination);
191191
return new MockResponse().setResponseCode(200)
192-
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE)
193-
.setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_UUID);
192+
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
193+
.setBody("\"" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "\"");
194194
} else if (path.matches("^/v1/networks/" + NETWORK_UUID_STRING_NOT_FOUND + "/run-and-save\\?receiver=.+&reportUuid=.+&reporterId=.+&variantId=" + VARIANT_ID_4 + "$")) {
195195
input.send(MessageBuilder.withPayload("")
196196
.setHeader("resultUuid", SHORT_CIRCUIT_ANALYSIS_RESULT_UUID_NOT_FOUND)
197197
.setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D")
198198
.build(), shortCircuitAnalysisResultDestination);
199199
return new MockResponse().setResponseCode(200)
200-
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE)
201-
.setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_UUID_NOT_FOUND);
200+
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
201+
.setBody("\"" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID_NOT_FOUND + "\"");
202202
} else if (path.matches("^/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.+&reportUuid=.+&reporterId=.+&variantId=" + VARIANT_ID + "$")) {
203203
input.send(MessageBuilder.withPayload("")
204204
.setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D")
205205
.build(), shortCircuitAnalysisFailedDestination);
206206
return new MockResponse().setResponseCode(200)
207-
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE)
208-
.setBody(SHORT_CIRCUIT_ANALYSIS_ERROR_RESULT_UUID);
207+
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
208+
.setBody("\"" + SHORT_CIRCUIT_ANALYSIS_ERROR_RESULT_UUID + "\"");
209209
} else if (path.equals("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "?mode=FULL")) {
210210
return new MockResponse().setResponseCode(200)
211211
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
212-
.setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON);
212+
.setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON + "}");
213213
} else if (path.equals("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/fault-types")) {
214214
return new MockResponse().setResponseCode(200);
215215
} else if (path.equals("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/fault_results/paged?mode=FULL&page=0&size=20&sort=id,DESC")) {
216216
return new MockResponse().setResponseCode(200)
217217
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
218-
.setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON);
218+
.setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON + "}");
219219
} else if (path.equals("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/csv")) {
220220
return new MockResponse().setResponseCode(200)
221221
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
@@ -225,7 +225,7 @@ public MockResponse dispatch(RecordedRequest request) {
225225
} 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")) {
226226
return new MockResponse().setResponseCode(200)
227227
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
228-
.setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON);
228+
.setBody(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON + "}");
229229
} else if (path.equals("/v1/results/" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "/status")) {
230230
return new MockResponse().setResponseCode(200)
231231
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
@@ -245,8 +245,8 @@ public MockResponse dispatch(RecordedRequest request) {
245245
return new MockResponse().setResponseCode(200);
246246
} else if (path.equals("/v1/supervision/results-count")) {
247247
return new MockResponse().setResponseCode(200).setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE).setBody("1");
248-
} else if ("POST".equalsIgnoreCase(request.getMethod()) && path.equals("/v1/parameters")) {
249-
return new MockResponse().setResponseCode(200).setHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE).setBody(SHORT_CIRCUIT_ANALYSIS_PARAMETERS_UUID);
248+
} else if ("POST".equalsIgnoreCase(request.getMethod()) && path.equals("/v1/parameters/default")) {
249+
return new MockResponse().setResponseCode(200).setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE).setBody("\"" + SHORT_CIRCUIT_ANALYSIS_PARAMETERS_UUID + "\"");
250250
} else if ("GET".equalsIgnoreCase(request.getMethod()) && path.equals("/v1/parameters/" + SHORT_CIRCUIT_ANALYSIS_PARAMETERS_UUID)) {
251251
return new MockResponse().setResponseCode(200).setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE).setBody(TestUtils.resourceToString("/short-circuit-parameters.json"));
252252
} else if ("PUT".equalsIgnoreCase(request.getMethod()) && path.equals("/v1/parameters/" + SHORT_CIRCUIT_ANALYSIS_PARAMETERS_UUID)) {
@@ -270,7 +270,7 @@ public void testShortCircuitAnalysisParameters() throws Exception {
270270
//get default ShortCircuitParameters
271271
mockMvc.perform(get("/v1/studies/{studyUuid}/short-circuit-analysis/parameters", studyNameUserIdUuid))
272272
.andExpectAll(status().isOk(), content().string(TestUtils.resourceToString("/short-circuit-parameters.json")));
273-
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.equals("/v1/parameters")));
273+
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.equals("/v1/parameters/default")));
274274
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.equals("/v1/parameters/" + SHORT_CIRCUIT_ANALYSIS_PARAMETERS_UUID)));
275275

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

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

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

473473
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")));
474474

@@ -541,7 +541,7 @@ public void testOneBusShortCircuit() throws Exception {
541541
.param("type", ShortcircuitAnalysisType.ONE_BUS.name()))
542542
.andExpectAll(
543543
status().isOk(),
544-
content().string(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON)
544+
content().string(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON + "}")
545545
);
546546

547547
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 {
551551
.param("type", ShortcircuitAnalysisType.ONE_BUS.name())
552552
).andExpectAll(
553553
status().isOk(),
554-
content().string(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON));
554+
content().string(SHORT_CIRCUIT_ANALYSIS_RESULT_JSON + "}"));
555555

556556
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")));
557557

src/test/java/org/gridsuite/study/server/StudyTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,17 +482,14 @@ public MockResponse dispatch(RecordedRequest request) {
482482
} else if (path.matches("/v1/networks\\?caseUuid=" + CLONED_CASE_UUID_STRING + "&variantId=" + FIRST_VARIANT_ID + "&reportUuid=.*&receiver=.*")) {
483483
sendCaseImportSucceededMessage(path, NETWORK_INFOS, "UCTE");
484484
return new MockResponse().setResponseCode(200);
485-
} else if (path.matches("/v1/parameters.*") && POST.equals(request.getMethod())) {
485+
} else if (path.startsWith("/v1/parameters") && POST.equals(request.getMethod())) {
486486
if (path.matches("/v1/parameters\\?duplicateFrom=" + PROFILE_LOADFLOW_INVALID_PARAMETERS_UUID_STRING)) {
487487
return new MockResponse().setResponseCode(404); // params duplication request KO
488488
} else if (path.matches("/v1/parameters\\?duplicateFrom=" + PROFILE_LOADFLOW_VALID_PARAMETERS_UUID_STRING)) {
489489
return new MockResponse().setResponseCode(200).setBody(DUPLICATED_PARAMS_JSON) // params duplication request OK
490490
.addHeader("Content-Type", "application/json; charset=utf-8");
491-
} else if (path.equals("/v1/parameters")
492-
|| path.matches("/v1/parameters\\?duplicateFrom=.+") && request.getHeaders().get(HttpHeaders.ACCEPT).contains(MediaType.TEXT_PLAIN_VALUE)) {
493-
return new MockResponse().setResponseCode(200).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN).setBody(UUID.randomUUID().toString());
494491
} else {
495-
return new MockResponse().setResponseCode(200).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).setBody(mapper.writeValueAsString(UUID.randomUUID()));
492+
return new MockResponse().setResponseCode(200).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).setBody("\"" + UUID.randomUUID() + "\"");
496493
}
497494
} else if (path.matches("/v1/parameters/.*") && DELETE.equals(request.getMethod())) {
498495
return new MockResponse().setResponseCode(200);

0 commit comments

Comments
 (0)