X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=rapp-manager-application%2Fsrc%2Ftest%2Fjava%2Fcom%2Foransc%2Frappmanager%2Fservice%2FRappServiceTest.java;h=b45c289fdac814cbedbb3d3b6382343a44126129;hb=b5c6c711f527ccf4a288457fb7168cbbf7399f24;hp=c50f0b4287931f7d3cc7201ae2a645bda934cab4;hpb=6ab517a1fe9ea8bd69645a9bcb70839a436e8ea4;p=nonrtric%2Fplt%2Frappmanager.git diff --git a/rapp-manager-application/src/test/java/com/oransc/rappmanager/service/RappServiceTest.java b/rapp-manager-application/src/test/java/com/oransc/rappmanager/service/RappServiceTest.java index c50f0b4..b45c289 100755 --- a/rapp-manager-application/src/test/java/com/oransc/rappmanager/service/RappServiceTest.java +++ b/rapp-manager-application/src/test/java/com/oransc/rappmanager/service/RappServiceTest.java @@ -21,6 +21,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @AutoConfigureMockMvc @@ -75,6 +76,7 @@ class RappServiceTest { assertEquals(HttpStatus.OK, rappService.primeRapp(rapp).getStatusCode()); assertEquals(RappState.COMMISSIONED, rapp.getState()); } + @Test void testPrimeRappDmeFailure() { Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile) @@ -169,6 +171,20 @@ class RappServiceTest { assertEquals(HttpStatus.BAD_GATEWAY, rappService.deployRappInstance(rapp, rappInstance).getStatusCode()); } + @Test + void testDeployRappInstanceFailureWithState() { + Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile) + .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build(); + RappInstance rappInstance = new RappInstance(); + RappInstanceState rappInstanceState = RappInstanceState.DEPLOYED; + rappInstance.setState(rappInstanceState); + rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); + ResponseEntity responseEntity = rappService.deployRappInstance(rapp, rappInstance); + assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode()); + assertEquals("State transition from " + rappInstanceState + " to DEPLOYED is not permitted.", + responseEntity.getBody()); + } + @Test void testUndeployRappInstance() { Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile) @@ -220,4 +236,37 @@ class RappServiceTest { when(dmeDeployer.undeployRappInstance(any(), any())).thenReturn(true); assertEquals(HttpStatus.BAD_REQUEST, rappService.undeployRappInstance(rapp, rappInstance).getStatusCode()); } + + @Test + void testDeleteRappSuccess() { + Rapp rApp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile) + .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build(); + assertEquals(HttpStatus.OK, rappService.deleteRapp(rApp).getStatusCode()); + } + + @Test + void testDeleteRappFailureWithState() { + String rAppName = "rAppInPrimed"; + Rapp rApp = Rapp.builder().rappId(UUID.randomUUID()).name(rAppName).packageName(validRappFile) + .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build(); + ResponseEntity responseEntity = rappService.deleteRapp(rApp); + assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode()); + assertEquals("Unable to delete '" + rAppName + "' as the rApp is not in COMMISSIONED state.", + responseEntity.getBody()); + } + + @Test + void testDeleteRappFailureWithInstances() { + String rAppName = "rAppWithInstances"; + Rapp rApp = Rapp.builder().rappId(UUID.randomUUID()).name(rAppName).packageName(validRappFile) + .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build(); + RappInstance rappInstance = new RappInstance(); + rappInstance.setState(RappInstanceState.DEPLOYED); + rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); + rApp.setRappInstances(Map.of(rappInstance.getRappInstanceId(), rappInstance)); + ResponseEntity responseEntity = rappService.deleteRapp(rApp); + assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode()); + assertEquals("Unable to delete '" + rAppName + "' as there are active rApp instances.", + responseEntity.getBody()); + } }