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=6652dbae8e4bb7af9aaa21e927892a75ab9be9df;hb=refs%2Fchanges%2F22%2F11822%2F1;hp=c50f0b4287931f7d3cc7201ae2a645bda934cab4;hpb=b45f4856cd283f8b9e3e3372a80767145db6b554;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..6652dba 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 @@ -72,16 +73,17 @@ class RappServiceTest { .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build(); when(acmDeployer.primeRapp(any())).thenReturn(false); when(dmeDeployer.primeRapp(any())).thenReturn(true); - assertEquals(HttpStatus.OK, rappService.primeRapp(rapp).getStatusCode()); + assertEquals(HttpStatus.BAD_GATEWAY, rappService.primeRapp(rapp).getStatusCode()); assertEquals(RappState.COMMISSIONED, rapp.getState()); } + @Test void testPrimeRappDmeFailure() { Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile) .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build(); when(acmDeployer.primeRapp(any())).thenReturn(true); when(dmeDeployer.primeRapp(any())).thenReturn(false); - assertEquals(HttpStatus.OK, rappService.primeRapp(rapp).getStatusCode()); + assertEquals(HttpStatus.BAD_GATEWAY, rappService.primeRapp(rapp).getStatusCode()); assertEquals(RappState.COMMISSIONED, rapp.getState()); } @@ -102,7 +104,7 @@ class RappServiceTest { .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build(); when(acmDeployer.deprimeRapp(any())).thenReturn(false); when(dmeDeployer.deprimeRapp(any())).thenReturn(true); - assertEquals(HttpStatus.OK, rappService.deprimeRapp(rapp).getStatusCode()); + assertEquals(HttpStatus.BAD_GATEWAY, rappService.deprimeRapp(rapp).getStatusCode()); assertEquals(RappState.PRIMED, rapp.getState()); } @@ -112,7 +114,7 @@ class RappServiceTest { .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build(); when(acmDeployer.deprimeRapp(any())).thenReturn(true); when(dmeDeployer.deprimeRapp(any())).thenReturn(false); - assertEquals(HttpStatus.OK, rappService.deprimeRapp(rapp).getStatusCode()); + assertEquals(HttpStatus.BAD_GATEWAY, rappService.deprimeRapp(rapp).getStatusCode()); assertEquals(RappState.PRIMED, rapp.getState()); } @@ -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()); + } }