import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doThrow;
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.exception.RappHandlerException;
+import com.oransc.rappmanager.models.exception.RappValidationException;
import com.oransc.rappmanager.models.rapp.Rapp;
import com.oransc.rappmanager.models.rapp.RappState;
import com.oransc.rappmanager.models.rappinstance.RappInstance;
@MockBean
DmeDeployer dmeDeployer;
+ @MockBean
+ DeploymentArtifactsService deploymentArtifactsService;
+
@MockBean
SmeLifecycleManager smeLifecycleManager;
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());
}
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());
}
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 testPrimeRappHelmUploadFailure() {
+ Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile)
+ .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
+ doThrow(new RappValidationException("")).when(deploymentArtifactsService).configureDeploymentArtifacts(any());
+ when(acmDeployer.primeRapp(any())).thenReturn(true);
+ when(dmeDeployer.primeRapp(any())).thenReturn(false);
+ RappValidationException rappValidationException =
+ assertThrows(RappValidationException.class, () -> rappService.primeRapp(rapp));
+ assertEquals(HttpStatus.BAD_REQUEST, rappValidationException.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() {
.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());
}
.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());
}
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
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