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=c50f0b4287931f7d3cc7201ae2a645bda934cab4;hb=refs%2Fchanges%2F03%2F11803%2F1;hp=dbb3da75fb23c009ce8ddcd57b55d4d40d0d086d;hpb=cc9f90ef6d725e90cf477ef6b83ec5a2948127b3;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 dbb3da7..c50f0b4 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 @@ -5,6 +5,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import com.oransc.rappmanager.acm.service.AcmDeployer; +import com.oransc.rappmanager.dme.service.DmeDeployer; import com.oransc.rappmanager.models.rapp.Rapp; import com.oransc.rappmanager.models.rapp.RappState; import com.oransc.rappmanager.models.rappinstance.RappInstance; @@ -34,6 +35,9 @@ class RappServiceTest { @MockBean SmeDeployer smeDeployer; + @MockBean + DmeDeployer dmeDeployer; + @MockBean SmeLifecycleManager smeLifecycleManager; @@ -44,15 +48,15 @@ class RappServiceTest { private final String validRappFile = "valid-rapp-package.csar"; - private final String invalidRappFile = "invalid-rapp-package.csar"; - @Test void testPrimeRapp() { 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(true); assertEquals(HttpStatus.OK, rappService.primeRapp(rapp).getStatusCode()); + assertEquals(RappState.PRIMED, rapp.getState()); } @Test @@ -67,23 +71,49 @@ class RappServiceTest { Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile) .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(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(RappState.COMMISSIONED, rapp.getState()); } + @Test void testDeprimeRapp() { Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile) .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build(); when(acmDeployer.deprimeRapp(any())).thenReturn(true); + when(dmeDeployer.deprimeRapp(any())).thenReturn(true); assertEquals(HttpStatus.OK, rappService.deprimeRapp(rapp).getStatusCode()); + assertEquals(RappState.COMMISSIONED, rapp.getState()); } @Test - void testDeprimeRappFailure() { + void testDeprimeRappAcmFailure() { Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile) .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(RappState.PRIMED, rapp.getState()); + } + + @Test + void testDeprimeRappDmeFailure() { + Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile) + .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(RappState.PRIMED, rapp.getState()); } @Test @@ -91,14 +121,16 @@ class RappServiceTest { Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile) .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build(); assertEquals(HttpStatus.BAD_REQUEST, rappService.deprimeRapp(rapp).getStatusCode()); + assertEquals(RappState.COMMISSIONED, rapp.getState()); } @Test void testDeprimeRappActiveInstances() { Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile) - .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED) + .packageLocation(validCsarFileLocation).state(RappState.PRIMED) .rappInstances(Map.of(UUID.randomUUID(), new RappInstance())).build(); assertEquals(HttpStatus.BAD_REQUEST, rappService.deprimeRapp(rapp).getStatusCode()); + assertEquals(RappState.PRIMED, rapp.getState()); } @Test @@ -109,6 +141,7 @@ class RappServiceTest { rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); when(acmDeployer.deployRappInstance(any(), any())).thenReturn(true); when(smeDeployer.deployRappInstance(any(), any())).thenReturn(true); + when(dmeDeployer.deployRappInstance(any(), any())).thenReturn(true); assertEquals(HttpStatus.ACCEPTED, rappService.deployRappInstance(rapp, rappInstance).getStatusCode()); } @@ -120,6 +153,19 @@ class RappServiceTest { rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); when(acmDeployer.deployRappInstance(any(), any())).thenReturn(true); when(smeDeployer.deployRappInstance(any(), any())).thenReturn(false); + when(dmeDeployer.deployRappInstance(any(), any())).thenReturn(true); + assertEquals(HttpStatus.BAD_GATEWAY, rappService.deployRappInstance(rapp, rappInstance).getStatusCode()); + } + + @Test + void testDeployRappInstanceDmeFailure() { + Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile) + .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build(); + RappInstance rappInstance = new RappInstance(); + rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); + when(acmDeployer.deployRappInstance(any(), any())).thenReturn(true); + when(smeDeployer.deployRappInstance(any(), any())).thenReturn(true); + when(dmeDeployer.deployRappInstance(any(), any())).thenReturn(false); assertEquals(HttpStatus.BAD_GATEWAY, rappService.deployRappInstance(rapp, rappInstance).getStatusCode()); } @@ -132,6 +178,7 @@ class RappServiceTest { rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); when(acmDeployer.undeployRappInstance(any(), any())).thenReturn(true); when(smeDeployer.undeployRappInstance(any(), any())).thenReturn(true); + when(dmeDeployer.undeployRappInstance(any(), any())).thenReturn(true); assertEquals(HttpStatus.ACCEPTED, rappService.undeployRappInstance(rapp, rappInstance).getStatusCode()); } @@ -144,6 +191,20 @@ class RappServiceTest { rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); when(acmDeployer.undeployRappInstance(any(), any())).thenReturn(true); when(smeDeployer.undeployRappInstance(any(), any())).thenReturn(false); + when(dmeDeployer.undeployRappInstance(any(), any())).thenReturn(true); + assertEquals(HttpStatus.BAD_GATEWAY, rappService.undeployRappInstance(rapp, rappInstance).getStatusCode()); + } + + @Test + void testUndeployRappInstanceDmeFailure() { + Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile) + .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build(); + RappInstance rappInstance = new RappInstance(); + rappInstance.setState(RappInstanceState.DEPLOYED); + rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); + when(acmDeployer.undeployRappInstance(any(), any())).thenReturn(true); + when(smeDeployer.undeployRappInstance(any(), any())).thenReturn(true); + when(dmeDeployer.undeployRappInstance(any(), any())).thenReturn(false); assertEquals(HttpStatus.BAD_GATEWAY, rappService.undeployRappInstance(rapp, rappInstance).getStatusCode()); } @@ -156,6 +217,7 @@ class RappServiceTest { rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId()); when(acmDeployer.undeployRappInstance(any(), any())).thenReturn(true); when(smeDeployer.undeployRappInstance(any(), any())).thenReturn(false); + when(dmeDeployer.undeployRappInstance(any(), any())).thenReturn(true); assertEquals(HttpStatus.BAD_REQUEST, rappService.undeployRappInstance(rapp, rappInstance).getStatusCode()); } }