@@ -347,6 +347,7 @@ public void runAndSaveTest() throws Exception {
347
347
content ().contentType (MediaType .APPLICATION_JSON ));
348
348
349
349
assertFiltredResultN ();
350
+ checkNResultEnumFilters (RESULT_UUID );
350
351
351
352
mockMvc .perform (get ("/" + VERSION + "/results/" + RESULT_UUID + "/nmk-contingencies-result/paged" ))
352
353
.andExpectAll (
@@ -358,6 +359,8 @@ public void runAndSaveTest() throws Exception {
358
359
status ().isOk (),
359
360
content ().contentType (MediaType .APPLICATION_JSON ));
360
361
362
+ checkNmKResultEnumFilters (RESULT_UUID );
363
+
361
364
// should throw not found if result does not exist
362
365
assertResultNotFound (OTHER_RESULT_UUID );
363
366
@@ -463,32 +466,74 @@ private void assertFiltredResultN() throws Exception {
463
466
List <PreContingencyLimitViolationResultDTO > preContingencyResult = mapper .readValue (resultAsString , new TypeReference <>() {
464
467
});
465
468
assertEquals (1 , preContingencyResult .size ());
469
+ }
466
470
467
- mvcResult = mockMvc .perform (get ("/" + VERSION + "/results/{resultUuid}/limit-types" , RESULT_UUID ))
468
- .andExpectAll (
469
- status ().isOk (),
470
- content ().contentType (MediaType .APPLICATION_JSON )
471
- ).andReturn ();
471
+ private void checkNResultEnumFilters (UUID resultUuid ) throws Exception {
472
+
473
+ MvcResult mvcResult = mockMvc .perform (get ("/" + VERSION + "/results/" + resultUuid + "/n-result" ))
474
+ .andExpectAll (
475
+ status ().isOk (),
476
+ content ().contentType (MediaType .APPLICATION_JSON )).andReturn ();
477
+
478
+ List <PreContingencyLimitViolationResultDTO > nResults = mapper .readValue (mvcResult .getResponse ().getContentAsString (), new TypeReference <>() {
479
+ });
480
+
481
+ List <LimitViolationType > expectedLimitTypes = nResults .stream ().map (result -> result .getLimitViolation ().getLimitType ()).distinct ().toList ();
482
+ mvcResult = mockMvc .perform (get ("/" + VERSION + "/results/{resultUuid}/n-limit-types" , resultUuid ))
483
+ .andExpectAll (
484
+ status ().isOk (),
485
+ content ().contentType (MediaType .APPLICATION_JSON )
486
+ ).andReturn ();
472
487
List <LimitViolationType > limitTypes = mapper .readValue (mvcResult .getResponse ().getContentAsString (), new TypeReference <>() { });
473
- assertEquals (2 , limitTypes .size ());
474
- assertFalse (limitTypes .contains (LimitViolationType .HIGH_SHORT_CIRCUIT_CURRENT ));
488
+ Assertions .assertThat (limitTypes ).hasSameElementsAs (expectedLimitTypes );
475
489
476
- mvcResult = mockMvc .perform (get ("/" + VERSION + "/results/{resultUuid}/branch-sides" , RESULT_UUID ))
477
- .andExpectAll (
478
- status ().isOk (),
479
- content ().contentType (MediaType .APPLICATION_JSON )
480
- ).andReturn ();
490
+ List <ThreeSides > expectedSides = nResults .stream ().map (result -> result .getLimitViolation ().getSide ()).distinct ().filter (side -> side != null ).toList ();
491
+ mvcResult = mockMvc .perform (get ("/" + VERSION + "/results/{resultUuid}/n-branch-sides" , resultUuid ))
492
+ .andExpectAll (
493
+ status ().isOk (),
494
+ content ().contentType (MediaType .APPLICATION_JSON )
495
+ ).andReturn ();
481
496
List <ThreeSides > sides = mapper .readValue (mvcResult .getResponse ().getContentAsString (), new TypeReference <>() { });
482
- assertEquals ( 1 , sides . size () );
483
- assertTrue ( sides . contains ( ThreeSides . ONE ));
497
+ Assertions . assertThat ( sides ). hasSameElementsAs ( expectedSides );
498
+ }
484
499
485
- mvcResult = mockMvc .perform (get ("/" + VERSION + "/results/{resultUuid}/computation-status" , RESULT_UUID ))
486
- .andExpectAll (
487
- status ().isOk (),
488
- content ().contentType (MediaType .APPLICATION_JSON )
489
- ).andReturn ();
500
+ private void checkNmKResultEnumFilters (UUID resultUuid ) throws Exception {
501
+ // getting 100 elements here because we want to fetch all test datas to check fetched filters belongs to fetched results
502
+ MvcResult mvcResult = mockMvc .perform (get ("/" + VERSION + "/results/" + RESULT_UUID + "/nmk-contingencies-result/paged?size=100" ))
503
+ .andExpectAll (
504
+ status ().isOk (),
505
+ content ().contentType (MediaType .APPLICATION_JSON )).andReturn ();
506
+ // getting paged result as list
507
+ JsonNode resultsJsonNode = mapper .readTree (mvcResult .getResponse ().getContentAsString ());
508
+ ObjectReader resultsObjectReader = mapper .readerFor (new TypeReference <List <ContingencyResultDTO >>() { });
509
+ List <ContingencyResultDTO > nmkResult = resultsObjectReader .readValue (resultsJsonNode .get ("content" ));
510
+
511
+ List <LimitViolationType > expectedLimitTypes = nmkResult .stream ().map (ContingencyResultDTO ::getSubjectLimitViolations ).flatMap (subjectLimitViolationDTOS -> subjectLimitViolationDTOS .stream ().map (slm -> slm .getLimitViolation ().getLimitType ())).distinct ().toList ();
512
+ mvcResult = mockMvc .perform (get ("/" + VERSION + "/results/{resultUuid}/nmk-limit-types" , resultUuid ))
513
+ .andExpectAll (
514
+ status ().isOk (),
515
+ content ().contentType (MediaType .APPLICATION_JSON )
516
+ ).andReturn ();
517
+ List <LimitViolationType > limitTypes = mapper .readValue (mvcResult .getResponse ().getContentAsString (), new TypeReference <>() { });
518
+ Assertions .assertThat (limitTypes ).hasSameElementsAs (expectedLimitTypes );
519
+
520
+ List <ThreeSides > expectedSides = nmkResult .stream ().map (ContingencyResultDTO ::getSubjectLimitViolations ).flatMap (subjectLimitViolationDTOS -> subjectLimitViolationDTOS .stream ().map (slm -> slm .getLimitViolation ().getSide ())).filter (Objects ::nonNull ).distinct ().toList ();
521
+ mvcResult = mockMvc .perform (get ("/" + VERSION + "/results/{resultUuid}/nmk-branch-sides" , resultUuid ))
522
+ .andExpectAll (
523
+ status ().isOk (),
524
+ content ().contentType (MediaType .APPLICATION_JSON )
525
+ ).andReturn ();
526
+ List <ThreeSides > sides = mapper .readValue (mvcResult .getResponse ().getContentAsString (), new TypeReference <>() { });
527
+ Assertions .assertThat (sides ).hasSameElementsAs (expectedSides );
528
+
529
+ List <LoadFlowResult .ComponentResult .Status > expectedStatus = nmkResult .stream ().map (result -> LoadFlowResult .ComponentResult .Status .valueOf (result .getContingency ().getStatus ())).distinct ().toList ();
530
+ mvcResult = mockMvc .perform (get ("/" + VERSION + "/results/{resultUuid}/nmk-computation-status" , resultUuid ))
531
+ .andExpectAll (
532
+ status ().isOk (),
533
+ content ().contentType (MediaType .APPLICATION_JSON )
534
+ ).andReturn ();
490
535
List <LoadFlowResult .ComponentResult .Status > status = mapper .readValue (mvcResult .getResponse ().getContentAsString (), new TypeReference <>() { });
491
- assertEquals ( 0 , status . size () );
536
+ Assertions . assertThat ( status ). hasSameElementsAs ( expectedStatus );
492
537
}
493
538
494
539
@ Test
0 commit comments