@@ -741,6 +741,22 @@ public void updateTestCaseValidationStatusProcessesValidatingTestCases() throws
741741 when (measureRepository .findAllByModel (ModelType .QI_CORE_6_0_0 .getValue ()))
742742 .thenReturn (List .of (measure ));
743743
744+ // Mock the repository behavior to update the validation status to PENDING
745+ doAnswer (
746+ invocation -> {
747+ String testCaseId = invocation .getArgument (0 , String .class );
748+ String measureId = invocation .getArgument (1 , String .class );
749+ if ("TC1" .equals (testCaseId ) && "M1" .equals (measureId )) {
750+ measure
751+ .getTestCases ()
752+ .get (0 )
753+ .setValidationStatus (TestCaseValidationStatus .PENDING .toString ());
754+ }
755+ return null ;
756+ })
757+ .when (measureRepository )
758+ .setValidationStatusToPending (anyString (), anyString ());
759+
744760 mockMvc
745761 .perform (
746762 MockMvcRequestBuilders .put ("/admin/measures/test-cases/restart-validation" )
@@ -861,4 +877,85 @@ public void updateTestCaseValidationStatusHandlesMeasuresWithoutTestCases() thro
861877
862878 verifyNoInteractions (testCaseValidationService );
863879 }
880+
881+ @ Test
882+ public void updateTestCaseValidationStatusProcessesMultipleTestCasesWithDifferentStatuses ()
883+ throws Exception {
884+ Measure measure =
885+ Measure .builder ()
886+ .id ("M1" )
887+ .model (ModelType .QI_CORE_6_0_0 .getValue ())
888+ .testCases (
889+ List .of (
890+ TestCase .builder ()
891+ .id ("TC1" )
892+ .validationStatus (TestCaseValidationStatus .VALIDATING .toString ())
893+ .build (),
894+ TestCase .builder ()
895+ .id ("TC2" )
896+ .validationStatus (TestCaseValidationStatus .PENDING .toString ())
897+ .build (),
898+ TestCase .builder ()
899+ .id ("TC3" )
900+ .validationStatus (TestCaseValidationStatus .INVALID .toString ())
901+ .build ()))
902+ .build ();
903+
904+ when (measureRepository .findAllByModel (ModelType .QI_CORE_6_0_0 .getValue ()))
905+ .thenReturn (List .of (measure ));
906+
907+ // Mock the repository behavior to update the validation status to PENDING
908+ doAnswer (
909+ invocation -> {
910+ String testCaseId = invocation .getArgument (0 , String .class );
911+ String measureId = invocation .getArgument (1 , String .class );
912+ if ("TC1" .equals (testCaseId ) && "M1" .equals (measureId )) {
913+ measure
914+ .getTestCases ()
915+ .get (0 )
916+ .setValidationStatus (TestCaseValidationStatus .PENDING .toString ());
917+ }
918+ return null ;
919+ })
920+ .when (measureRepository )
921+ .setValidationStatusToPending (anyString (), anyString ());
922+
923+ mockMvc
924+ .perform (
925+ MockMvcRequestBuilders .put ("/admin/measures/test-cases/restart-validation" )
926+ .with (csrf ())
927+ .with (user (TEST_USER_ID ))
928+ .header (ADMIN_TEST_API_KEY_HEADER , ADMIN_TEST_API_KEY_HEADER_VALUE )
929+ .header ("Authorization" , "test-okta" ))
930+ .andExpect (status ().isOk ());
931+
932+ verify (testCaseValidationService , times (1 ))
933+ .submitOnSaveValidationTask (
934+ eq ("M1" ),
935+ eq (measure .getTestCases ().get (0 )),
936+ eq ("test-okta" ),
937+ eq (ModelType .QI_CORE_6_0_0 ));
938+ verify (testCaseValidationService , times (1 ))
939+ .submitOnSaveValidationTask (
940+ eq ("M1" ),
941+ eq (measure .getTestCases ().get (1 )),
942+ eq ("test-okta" ),
943+ eq (ModelType .QI_CORE_6_0_0 ));
944+ verify (testCaseValidationService , never ())
945+ .submitOnSaveValidationTask (
946+ eq ("M1" ),
947+ eq (measure .getTestCases ().get (2 )),
948+ eq ("test-okta" ),
949+ eq (ModelType .QI_CORE_6_0_0 ));
950+
951+ assertEquals (
952+ TestCaseValidationStatus .PENDING .toString (),
953+ measure .getTestCases ().get (0 ).getValidationStatus ());
954+ assertEquals (
955+ TestCaseValidationStatus .PENDING .toString (),
956+ measure .getTestCases ().get (1 ).getValidationStatus ());
957+ assertEquals (
958+ TestCaseValidationStatus .INVALID .toString (),
959+ measure .getTestCases ().get (2 ).getValidationStatus ());
960+ }
864961}
0 commit comments