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=9dc4987c4c0284dfb2f798bf715a9c803e2a82d3;hb=a46c269e0972357c54378520a4bba531bf7bb12d;hp=7bf8adb353d706afaadd5a06fcb63bb2e4b66431;hpb=4e0f690867551e6ff679debcc7a1fa531aa4c8e7;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 7bf8adb..9dc4987 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 @@ -1,7 +1,7 @@ /*- * ============LICENSE_START====================================================================== * Copyright (C) 2023 Nordix Foundation. All rights reserved. - * Copyright (C) 2023 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2023-2024 OpenInfra Foundation Europe. All rights reserved. * =============================================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,6 +60,9 @@ class RappServiceTest { @MockBean DmeDeployer dmeDeployer; + @MockBean + DeploymentArtifactsService deploymentArtifactsService; + @MockBean SmeLifecycleManager smeLifecycleManager; @@ -79,6 +82,8 @@ class RappServiceTest { .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build(); when(acmDeployer.primeRapp(any())).thenReturn(true); when(dmeDeployer.primeRapp(any())).thenReturn(true); + when(smeDeployer.primeRapp(any())).thenReturn(true); + when(deploymentArtifactsService.configureDeploymentArtifacts(any())).thenReturn(true); assertEquals(HttpStatus.OK, rappService.primeRapp(rapp).getStatusCode()); assertEquals(RappState.PRIMED, rapp.getState()); } @@ -99,9 +104,12 @@ class RappServiceTest { void testPrimeRappAcmFailure() { Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile) .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build(); + when(deploymentArtifactsService.configureDeploymentArtifacts(any())).thenReturn(true); when(acmDeployer.primeRapp(any())).thenReturn(false); when(dmeDeployer.primeRapp(any())).thenReturn(true); - assertEquals(HttpStatus.BAD_GATEWAY, rappService.primeRapp(rapp).getStatusCode()); + RappHandlerException rappHandlerException = + assertThrows(RappHandlerException.class, () -> rappService.primeRapp(rapp)); + assertEquals(HttpStatus.BAD_GATEWAY, rappHandlerException.getStatusCode()); assertEquals(RappState.COMMISSIONED, rapp.getState()); } @@ -109,12 +117,25 @@ class RappServiceTest { void testPrimeRappDmeFailure() { Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile) .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build(); + when(deploymentArtifactsService.configureDeploymentArtifacts(any())).thenReturn(true); when(acmDeployer.primeRapp(any())).thenReturn(true); when(dmeDeployer.primeRapp(any())).thenReturn(false); - assertEquals(HttpStatus.BAD_GATEWAY, rappService.primeRapp(rapp).getStatusCode()); + RappHandlerException rappHandlerException = + assertThrows(RappHandlerException.class, () -> rappService.primeRapp(rapp)); + assertEquals(HttpStatus.BAD_GATEWAY, rappHandlerException.getStatusCode()); assertEquals(RappState.COMMISSIONED, rapp.getState()); } + @Test + void testPrimeRappDeployArtifactFailure() { + Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile) + .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build(); + when(deploymentArtifactsService.configureDeploymentArtifacts(any())).thenReturn(false); + RappHandlerException rappHandlerException = + assertThrows(RappHandlerException.class, () -> rappService.primeRapp(rapp)); + assertEquals(HttpStatus.BAD_GATEWAY, rappHandlerException.getStatusCode()); + assertEquals(RappState.COMMISSIONED, rapp.getState()); + } @Test void testDeprimeRapp() { @@ -122,6 +143,7 @@ class RappServiceTest { .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build(); when(acmDeployer.deprimeRapp(any())).thenReturn(true); when(dmeDeployer.deprimeRapp(any())).thenReturn(true); + when(smeDeployer.deprimeRapp(any())).thenReturn(true); assertEquals(HttpStatus.OK, rappService.deprimeRapp(rapp).getStatusCode()); assertEquals(RappState.COMMISSIONED, rapp.getState()); } @@ -132,7 +154,9 @@ class RappServiceTest { .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build(); when(acmDeployer.deprimeRapp(any())).thenReturn(false); when(dmeDeployer.deprimeRapp(any())).thenReturn(true); - assertEquals(HttpStatus.BAD_GATEWAY, rappService.deprimeRapp(rapp).getStatusCode()); + RappHandlerException rappHandlerException = + assertThrows(RappHandlerException.class, () -> rappService.deprimeRapp(rapp)); + assertEquals(HttpStatus.BAD_GATEWAY, rappHandlerException.getStatusCode()); assertEquals(RappState.PRIMED, rapp.getState()); } @@ -142,7 +166,9 @@ class RappServiceTest { .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build(); when(acmDeployer.deprimeRapp(any())).thenReturn(true); when(dmeDeployer.deprimeRapp(any())).thenReturn(false); - assertEquals(HttpStatus.BAD_GATEWAY, rappService.deprimeRapp(rapp).getStatusCode()); + RappHandlerException rappHandlerException = + assertThrows(RappHandlerException.class, () -> rappService.deprimeRapp(rapp)); + assertEquals(HttpStatus.BAD_GATEWAY, rappHandlerException.getStatusCode()); assertEquals(RappState.PRIMED, rapp.getState()); } @@ -190,7 +216,9 @@ class RappServiceTest { 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()); + RappHandlerException rappHandlerException = + assertThrows(RappHandlerException.class, () -> rappService.deployRappInstance(rapp, rappInstance)); + assertEquals(HttpStatus.BAD_GATEWAY, rappHandlerException.getStatusCode()); } @Test @@ -232,7 +260,9 @@ class RappServiceTest { 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()); + RappHandlerException rappHandlerException = + assertThrows(RappHandlerException.class, () -> rappService.undeployRappInstance(rapp, rappInstance)); + assertEquals(HttpStatus.BAD_GATEWAY, rappHandlerException.getStatusCode()); } @Test