@@ -473,19 +473,17 @@ public MockResponse dispatch(RecordedRequest request) {
473
473
} else if (path .matches ("/v1/networks\\ ?caseUuid=" + CLONED_CASE_UUID_STRING + "&variantId=" + FIRST_VARIANT_ID + "&reportUuid=.*&receiver=.*" )) {
474
474
sendCaseImportSucceededMessage (path , NETWORK_INFOS , "UCTE" );
475
475
return new MockResponse ().setResponseCode (200 );
476
- } else if (path .matches ("/v1/parameters\\ ?duplicateFrom=.*" ) && POST .equals (request .getMethod ())) {
477
- return new MockResponse ().setResponseCode (200 ).addHeader (HttpHeaders .CONTENT_TYPE , MediaType .APPLICATION_JSON_VALUE ).setBody (mapper .writeValueAsString (UUID .randomUUID ()));
478
- } else if (path .matches ("/v1/parameters/default" ) && POST .equals (request .getMethod ())) {
479
- return new MockResponse ().setResponseCode (200 ).addHeader (HttpHeaders .CONTENT_TYPE , MediaType .APPLICATION_JSON_VALUE ).setBody (mapper .writeValueAsString (UUID .randomUUID ()));
480
- } else if (path .matches ("/v1/parameters/.*" ) && POST .equals (request .getMethod ())) {
481
- if (path .matches ("/v1/parameters/" + PROFILE_LOADFLOW_INVALID_PARAMETERS_UUID_STRING )) {
476
+ } else if (path .matches ("/v1/parameters.*" ) && POST .equals (request .getMethod ())) {
477
+ if (path .matches ("/v1/parameters\\ ?duplicateFrom=" + PROFILE_LOADFLOW_INVALID_PARAMETERS_UUID_STRING )) {
482
478
return new MockResponse ().setResponseCode (404 ); // params duplication request KO
483
- } else if (path .matches ("/v1/parameters/ " + PROFILE_LOADFLOW_VALID_PARAMETERS_UUID_STRING )) {
479
+ } else if (path .matches ("/v1/parameters\\ ?duplicateFrom= " + PROFILE_LOADFLOW_VALID_PARAMETERS_UUID_STRING )) {
484
480
return new MockResponse ().setResponseCode (200 ).setBody (DUPLICATED_PARAMS_JSON ) // params duplication request OK
485
481
.addHeader ("Content-Type" , "application/json; charset=utf-8" );
486
482
} else {
487
483
return new MockResponse ().setResponseCode (200 ).addHeader (HttpHeaders .CONTENT_TYPE , MediaType .APPLICATION_JSON_VALUE ).setBody (mapper .writeValueAsString (UUID .randomUUID ()));
488
484
}
485
+ } else if (path .matches ("/v1/parameters/default" ) && POST .equals (request .getMethod ())) {
486
+ return new MockResponse ().setResponseCode (200 ).addHeader (HttpHeaders .CONTENT_TYPE , MediaType .APPLICATION_JSON_VALUE ).setBody (mapper .writeValueAsString (UUID .randomUUID ()));
489
487
} else if (path .matches ("/v1/parameters/.*" ) && DELETE .equals (request .getMethod ())) {
490
488
return new MockResponse ().setResponseCode (200 );
491
489
} else if (path .matches ("/v1/parameters/.*/provider" )) {
@@ -1053,7 +1051,7 @@ private UUID createStudy(String userId, UUID caseUuid, String parameterDuplicate
1053
1051
assertTrue (requests .contains (String .format ("/v1/cases/%s/disableExpiration" , caseUuid )));
1054
1052
assertTrue (requests .stream ().anyMatch (r -> r .equals ("/v1/users/" + userId + "/profile" )));
1055
1053
if (parameterDuplicatedUuid != null ) {
1056
- assertTrue (requests .stream ().anyMatch (r -> r .equals ("/v1/parameters/ " + parameterDuplicatedUuid ))); // post duplicate
1054
+ assertTrue (requests .stream ().anyMatch (r -> r .equals ("/v1/parameters?duplicateFrom= " + parameterDuplicatedUuid ))); // post duplicate
1057
1055
}
1058
1056
1059
1057
return studyUuid ;
@@ -1101,7 +1099,7 @@ private UUID createStudyWithDuplicateCase(String userId, UUID caseUuid) throws E
1101
1099
// assert that all http requests have been sent to remote services
1102
1100
var requests = TestUtils .getRequestsDone (8 , server );
1103
1101
assertTrue (requests .contains (String .format ("/v1/cases/%s/exists" , caseUuid )));
1104
- assertTrue (requests .contains (String .format ("/v1/cases?duplicateFrom=%s&withExpiration=true " , caseUuid )));
1102
+ assertTrue (requests .contains (String .format ("/v1/cases?duplicateFrom=%s&withExpiration=%s " , caseUuid , true )));
1105
1103
// note : it's a new case UUID
1106
1104
assertTrue (requests .stream ().anyMatch (r -> r .matches ("/v1/networks\\ ?caseUuid=" + CLONED_CASE_UUID_STRING + "&variantId=" + FIRST_VARIANT_ID + "&reportUuid=.*&receiver=.*" )));
1107
1105
assertTrue (requests .contains (String .format ("/v1/cases/%s/disableExpiration" , CLONED_CASE_UUID_STRING )));
@@ -1458,7 +1456,7 @@ private void testDuplicateStudy(UUID study1Uuid) throws Exception {
1458
1456
assertNotEquals (study1Uuid , duplicatedStudy .getId ());
1459
1457
1460
1458
//Test duplication from a non existing source study
1461
- mockMvc .perform (post (STUDIES_URL + "?duplicateFrom={sourceStudyUuid}& studyUuid={studyUuid }" , UUID .randomUUID (), DUPLICATED_STUDY_UUID )
1459
+ mockMvc .perform (post (STUDIES_URL + "?duplicateFrom={studyUuid}" , UUID .randomUUID ())
1462
1460
.header (USER_ID_HEADER , "userId" ))
1463
1461
.andExpect (status ().isNotFound ());
1464
1462
}
@@ -1496,46 +1494,44 @@ public void testDuplicateStudyWithErrorDuringCaseDuplication() throws Exception
1496
1494
throw new RuntimeException ();
1497
1495
}).when (caseService ).duplicateCase (any (), any ());
1498
1496
1499
- mockMvc .perform (post (STUDIES_URL )
1500
- .param ("duplicateFrom" , studyUuid .toString ())
1501
- .param ("studyUuid" , DUPLICATED_STUDY_UUID )
1497
+ String response = mockMvc .perform (post (STUDIES_URL + "?duplicateFrom={studyUuid}" , studyUuid )
1502
1498
.param (CASE_FORMAT , "XIIDM" )
1503
1499
.header (USER_ID_HEADER , "userId" ))
1504
- .andExpect (status ().isOk ());
1500
+ .andExpect (status ().isOk ()). andReturn (). getResponse (). getContentAsString () ;
1505
1501
1502
+ ObjectMapper mapper = new ObjectMapper ();
1503
+ String duplicatedStudyUuid = mapper .readValue (response , String .class );
1506
1504
assertNotNull (output .receive (TIMEOUT , studyUpdateDestination ));
1507
1505
1508
- assertNull (studyRepository .findById (UUID .fromString (DUPLICATED_STUDY_UUID )).orElse (null ));
1506
+ assertNull (studyRepository .findById (UUID .fromString (duplicatedStudyUuid )).orElse (null ));
1509
1507
}
1510
1508
1511
1509
private StudyEntity duplicateStudy (UUID studyUuid , String userId , String caseFormat ) throws Exception {
1512
1510
UUID stubUuid = wireMockUtils .stubDuplicateModificationGroup ();
1513
- mockMvc .perform (post (STUDIES_URL )
1514
- .param ("duplicateFrom" , studyUuid .toString ())
1515
- .param ("studyUuid" , DUPLICATED_STUDY_UUID )
1516
- .param (CASE_FORMAT , caseFormat )
1511
+ String response = mockMvc .perform (post (STUDIES_URL + "?duplicateFrom={studyUuid}" , studyUuid )
1517
1512
.header (USER_ID_HEADER , "userId" ))
1518
- .andExpect (status ().isOk ());
1519
-
1513
+ .andExpect (status ().isOk ()).andReturn ().getResponse ().getContentAsString ();
1514
+ ObjectMapper mapper = new ObjectMapper ();
1515
+ String newUuid = mapper .readValue (response , String .class );
1520
1516
StudyEntity sourceStudy = studyRepository .findById (studyUuid ).orElseThrow ();
1521
1517
assertNotNull (output .receive (TIMEOUT , studyUpdateDestination ));
1522
1518
assertNotNull (output .receive (TIMEOUT , studyUpdateDestination ));
1523
1519
assertNotNull (output .receive (TIMEOUT , studyUpdateDestination ));
1524
1520
assertNotNull (output .receive (TIMEOUT , studyUpdateDestination ));
1525
1521
assertNotNull (output .receive (TIMEOUT , studyUpdateDestination ));
1526
1522
Message <byte []> indexationStatusMessageOnGoing = output .receive (TIMEOUT , studyUpdateDestination );
1527
- assertEquals (DUPLICATED_STUDY_UUID , indexationStatusMessageOnGoing .getHeaders ().get (NotificationService .HEADER_STUDY_UUID ).toString ());
1523
+ assertEquals (newUuid , indexationStatusMessageOnGoing .getHeaders ().get (NotificationService .HEADER_STUDY_UUID ).toString ());
1528
1524
assertEquals (NotificationService .UPDATE_TYPE_INDEXATION_STATUS , indexationStatusMessageOnGoing .getHeaders ().get (HEADER_UPDATE_TYPE ));
1529
1525
assertEquals (StudyIndexationStatus .INDEXING_ONGOING .name (), indexationStatusMessageOnGoing .getHeaders ().get (NotificationService .HEADER_INDEXATION_STATUS ));
1530
1526
Message <byte []> indexationStatusMessageDone = output .receive (TIMEOUT , studyUpdateDestination );
1531
- assertEquals (DUPLICATED_STUDY_UUID , indexationStatusMessageDone .getHeaders ().get (NotificationService .HEADER_STUDY_UUID ).toString ());
1527
+ assertEquals (newUuid , indexationStatusMessageDone .getHeaders ().get (NotificationService .HEADER_STUDY_UUID ).toString ());
1532
1528
assertEquals (NotificationService .UPDATE_TYPE_INDEXATION_STATUS , indexationStatusMessageDone .getHeaders ().get (HEADER_UPDATE_TYPE ));
1533
1529
assertEquals (StudyIndexationStatus .INDEXED .name (), indexationStatusMessageDone .getHeaders ().get (NotificationService .HEADER_INDEXATION_STATUS ));
1534
1530
assertNotNull (output .receive (TIMEOUT , studyUpdateDestination ));
1535
1531
1536
- StudyEntity duplicatedStudy = studyRepository .findById (UUID .fromString (DUPLICATED_STUDY_UUID )).orElse (null );
1532
+ StudyEntity duplicatedStudy = studyRepository .findById (UUID .fromString (newUuid )).orElse (null );
1537
1533
assertNotNull (duplicatedStudy );
1538
- RootNode duplicatedRootNode = networkModificationTreeService .getStudyTree (UUID .fromString (DUPLICATED_STUDY_UUID ));
1534
+ RootNode duplicatedRootNode = networkModificationTreeService .getStudyTree (UUID .fromString (newUuid ));
1539
1535
assertNotNull (duplicatedRootNode );
1540
1536
1541
1537
//Check tree node has been duplicated
@@ -1589,13 +1585,13 @@ private StudyEntity duplicateStudy(UUID studyUuid, String userId, String caseFor
1589
1585
assertEquals (1 , requests .stream ().filter (r -> r .getPath ().matches ("/v1/parameters\\ ?duplicateFrom=" + sourceStudy .getVoltageInitParametersUuid ())).count ());
1590
1586
}
1591
1587
if (sourceStudy .getLoadFlowParametersUuid () != null ) {
1592
- assertEquals (1 , requests .stream ().filter (r -> r .getPath ().matches ("/v1/parameters/ " + sourceStudy .getLoadFlowParametersUuid ())).count ());
1588
+ assertEquals (1 , requests .stream ().filter (r -> r .getPath ().matches ("/v1/parameters\\ ?duplicateFrom= " + sourceStudy .getLoadFlowParametersUuid ())).count ());
1593
1589
}
1594
1590
if (sourceStudy .getSecurityAnalysisParametersUuid () != null ) {
1595
- assertEquals (1 , requests .stream ().filter (r -> r .getPath ().matches ("/v1/parameters/ " + sourceStudy .getSecurityAnalysisParametersUuid ())).count ());
1591
+ assertEquals (1 , requests .stream ().filter (r -> r .getPath ().matches ("/v1/parameters\\ ?duplicateFrom= " + sourceStudy .getSecurityAnalysisParametersUuid ())).count ());
1596
1592
}
1597
1593
if (sourceStudy .getSensitivityAnalysisParametersUuid () != null ) {
1598
- assertEquals (1 , requests .stream ().filter (r -> r .getPath ().matches ("/v1/parameters/ " + sourceStudy .getSensitivityAnalysisParametersUuid ())).count ());
1594
+ assertEquals (1 , requests .stream ().filter (r -> r .getPath ().matches ("/v1/parameters\\ ?duplicateFrom= " + sourceStudy .getSensitivityAnalysisParametersUuid ())).count ());
1599
1595
}
1600
1596
return duplicatedStudy ;
1601
1597
}
0 commit comments