3232import org .gridsuite .computation .utils .SpecificationUtils ;
3333import org .gridsuite .securityanalysis .server .dto .*;
3434import org .gridsuite .securityanalysis .server .entities .AbstractLimitViolationEntity ;
35- import org .gridsuite .securityanalysis .server .entities .ContingencyEntity ;
3635import org .gridsuite .securityanalysis .server .entities .SubjectLimitViolationEntity ;
3736import org .gridsuite .securityanalysis .server .repositories .SubjectLimitViolationRepository ;
3837import org .gridsuite .securityanalysis .server .service .ActionsService ;
7776import static org .gridsuite .securityanalysis .server .util .DatabaseQueryUtils .assertRequestsCount ;
7877import static org .gridsuite .securityanalysis .server .util .TestUtils .assertLogMessage ;
7978import static org .hamcrest .MatcherAssert .assertThat ;
80- import static org .junit .jupiter .api .Assertions .assertEquals ;
81- import static org .junit .jupiter .api .Assertions .assertNull ;
79+ import static org .junit .jupiter .api .Assertions .*;
8280import static org .mockito .ArgumentMatchers .any ;
8381import static org .mockito .BDDMockito .given ;
8482import static org .mockito .Mockito .*;
@@ -338,12 +336,12 @@ void runAndSaveTest() throws Exception {
338336 .andExpectAll (
339337 status ().isOk (),
340338 content ().contentType (MediaType .APPLICATION_JSON ));
341-
339+ assertFiltredResultNmkContingencies ();
342340 mockMvc .perform (get ("/" + VERSION + "/results/" + RESULT_UUID + "/nmk-constraints-result/paged" ))
343341 .andExpectAll (
344342 status ().isOk (),
345343 content ().contentType (MediaType .APPLICATION_JSON ));
346-
344+ assertFiltredResultNmkConstraints ();
347345 checkNmKResultEnumFilters (RESULT_UUID );
348346
349347 // should throw not found if result does not exist
@@ -392,7 +390,7 @@ void testDeterministicResults() throws Exception {
392390 status ().isOk (),
393391 content ().contentType (MediaType .APPLICATION_JSON ))
394392 .andReturn ().getResponse ().getContentAsString ();
395-
393+ assertFiltredResultNmkConstraints ();
396394 JsonNode resultsPageNode0 = mapper .readTree (res );
397395 ObjectReader faultResultsReader = mapper .readerFor (new TypeReference <List <SubjectLimitViolationResultDTO >>() { });
398396 List <SubjectLimitViolationResultDTO > subjectLimitViolationResultDTOS = faultResultsReader .readValue (resultsPageNode0 .get ("content" ));
@@ -409,7 +407,7 @@ void testDeterministicResults() throws Exception {
409407 status ().isOk (),
410408 content ().contentType (MediaType .APPLICATION_JSON ))
411409 .andReturn ().getResponse ().getContentAsString ();
412-
410+ assertFiltredResultNmkContingencies ();
413411 resultsPageNode0 = mapper .readTree (res );
414412 faultResultsReader = mapper .readerFor (new TypeReference <List <SubjectLimitViolationResultDTO >>() { });
415413 subjectLimitViolationResultDTOS = faultResultsReader .readValue (resultsPageNode0 .get ("content" ));
@@ -436,6 +434,32 @@ private static String buildFilterUrl() throws JsonProcessingException {
436434 "&globalFilters=" + URLEncoder .encode (jsonGlobalFilters , StandardCharsets .UTF_8 ) + "&networkUuid=" + NETWORK_UUID + "&variantId=" + "initialState" ;
437435 }
438436
437+ private static String buildFilterNmkContingenciesUrl () throws JsonProcessingException {
438+ List <ResourceFilterDTO > filters = List .of ();
439+ GlobalFilter globalFilter = GlobalFilter .builder ()
440+ .genericFilter (List .of (LIST_FILTER_ID ))
441+ .nominalV (List .of ("400.0" ))
442+ .countryCode (List .of (Country .FR ))
443+ .build ();
444+ String jsonFilters = new ObjectMapper ().writeValueAsString (filters );
445+ String jsonGlobalFilters = new ObjectMapper ().writeValueAsString (globalFilter );
446+ return "filters=" + URLEncoder .encode (jsonFilters , StandardCharsets .UTF_8 ) +
447+ "&globalFilters=" + URLEncoder .encode (jsonGlobalFilters , StandardCharsets .UTF_8 ) + "&networkUuid=" + NETWORK_UUID + "&variantId=" + "initialState" ;
448+ }
449+
450+ private static String buildFilterNmkConstraintsUrl () throws JsonProcessingException {
451+ List <ResourceFilterDTO > filters = List .of ();
452+ GlobalFilter globalFilter = GlobalFilter .builder ()
453+ .genericFilter (List .of (LIST_FILTER_ID ))
454+ .nominalV (List .of ("400.0" ))
455+ .countryCode (List .of (Country .FR ))
456+ .build ();
457+ String jsonFilters = new ObjectMapper ().writeValueAsString (filters );
458+ String jsonGlobalFilters = new ObjectMapper ().writeValueAsString (globalFilter );
459+ return "filters=" + URLEncoder .encode (jsonFilters , StandardCharsets .UTF_8 ) +
460+ "&globalFilters=" + URLEncoder .encode (jsonGlobalFilters , StandardCharsets .UTF_8 ) + "&networkUuid=" + NETWORK_UUID + "&variantId=" + "initialState" ;
461+ }
462+
439463 private void assertFiltredResultN () throws Exception {
440464 Network network = mock (Network .class );
441465 VariantManager variantManager = mock (VariantManager .class );
@@ -462,9 +486,10 @@ private void assertFiltredResultNmkConstraints() throws Exception {
462486 when (networkStoreService .getNetwork (NETWORK_UUID , PreloadingStrategy .COLLECTION )).thenReturn (network );
463487
464488 // test - nmk-constraints-result/paged endpoint
465- MvcResult mvcResult = mockMvc .perform (get ("/" + VERSION + "/results/" + RESULT_UUID + "/nmk-constraints-result/paged?" + buildFilterUrl ())).andExpectAll (status ().isOk ()).andReturn ();
489+ MvcResult mvcResult = mockMvc .perform (get ("/" + VERSION + "/results/" + RESULT_UUID + "/nmk-constraints-result/paged?" + buildFilterNmkConstraintsUrl ()))
490+ .andExpectAll (status ().isOk ()).andReturn ();
466491 String resultAsString = mvcResult .getResponse ().getContentAsString ();
467- List < SubjectLimitViolationEntity > subjectLimitViolationList = mapper . readValue (resultAsString , new TypeReference <>() { } );
492+ assertNotNull (resultAsString );
468493 }
469494
470495 private void assertFiltredResultNmkContingencies () throws Exception {
@@ -476,10 +501,10 @@ private void assertFiltredResultNmkContingencies() throws Exception {
476501 when (networkStoreService .getNetwork (NETWORK_UUID , PreloadingStrategy .COLLECTION )).thenReturn (network );
477502
478503 // test - nmk-contingencies-result/paged endpoint
479- MvcResult mvcResult = mockMvc .perform (get ("/" + VERSION + "/results/" + RESULT_UUID + "/nmk-contingencies-result/paged?" + buildFilterUrl ()))
504+ MvcResult mvcResult = mockMvc .perform (get ("/" + VERSION + "/results/" + RESULT_UUID + "/nmk-contingencies-result/paged?" + buildFilterNmkContingenciesUrl ()))
480505 .andExpectAll (status ().isOk ()).andReturn ();
481506 String resultAsString = mvcResult .getResponse ().getContentAsString ();
482- List < ContingencyEntity > contingencyResult = mapper . readValue (resultAsString , new TypeReference <>() { } );
507+ assertNotNull (resultAsString );
483508 }
484509
485510 private void checkNResultEnumFilters (UUID resultUuid ) throws Exception {
0 commit comments