use of bio.terra.workspace.service.workspace.model.WsmApplication in project terra-workspace-manager by DataBiosphere.
the class ApplicationUnitTest method stateTransition.
private void stateTransition(WsmApplicationState targetState, String message) {
WsmApplication wsmApp = makeWsmApp();
wsmApp.state(targetState);
Map<UUID, WsmDbApplication> dbAppMap = appService.buildAppMap();
appService.enableTestMode();
appService.processApp(wsmApp, dbAppMap);
assertMessage(0, message);
}
use of bio.terra.workspace.service.workspace.model.WsmApplication in project terra-workspace-manager by DataBiosphere.
the class ApplicationUnitTest method configValidationTest.
@Test
public void configValidationTest() {
// The App class is what we get from the configuration file. This test verifies that the
// config validation is working properly.
// Test with empty object
App testApp = new App();
configValidationFail(testApp, ERROR_MISSING_REQUIRED);
// Test with missing UUID
testApp = makeApp(null, GOOD_EMAIL, GOOD_STATE);
configValidationFail(testApp, ERROR_MISSING_REQUIRED);
// Test with missing service account
testApp = makeApp(GOOD_UUID_STRING, null, GOOD_STATE);
configValidationFail(testApp, ERROR_MISSING_REQUIRED);
// Test with missing state
testApp = makeApp(GOOD_UUID_STRING, GOOD_EMAIL, null);
configValidationFail(testApp, ERROR_MISSING_REQUIRED);
// Test with bad UUID
testApp = makeApp(BAD_DATA, GOOD_EMAIL, GOOD_STATE);
configValidationFail(testApp, ERROR_BAD_UUID);
// Test with bad email
testApp = makeApp(GOOD_UUID_STRING, BAD_DATA, GOOD_STATE);
configValidationFail(testApp, ERROR_BAD_EMAIL);
// Test with bad state
testApp = makeApp(GOOD_UUID_STRING, GOOD_EMAIL, BAD_DATA);
configValidationFail(testApp, ERROR_BAD_STATE);
// Test with everything good
testApp = makeApp(GOOD_UUID_STRING, GOOD_EMAIL, GOOD_STATE);
configValidationSuccess(testApp);
// Test with name and desc filled in
testApp = makeApp(GOOD_UUID_STRING, GOOD_EMAIL, GOOD_STATE);
testApp.setName(GOOD_NAME);
testApp.setDescription(GOOD_DESC);
WsmApplication wsmApp = configValidationSuccess(testApp);
assertEquals(GOOD_NAME, wsmApp.getDisplayName());
assertEquals(GOOD_DESC, wsmApp.getDescription());
}
use of bio.terra.workspace.service.workspace.model.WsmApplication in project terra-workspace-manager by DataBiosphere.
the class ApplicationUnitTest method missingConfigTest.
// This test writes to the database, so conflicts with the processAppTest
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
@Test
public void missingConfigTest() {
// Create two applications
Map<UUID, WsmDbApplication> dbAppMap = new HashMap<>();
WsmApplication wsmApp = makeWsmApp();
appService.enableTestMode();
appService.processApp(wsmApp, dbAppMap);
assertMessage(0, INFO_CREATED);
WsmApplication wsmApp2 = new WsmApplication().applicationId(UUID.fromString("EF580D18-5CB4-4BEF-A5C9-DB5F30EBE368")).serviceAccount("bar@kripalu.yoga").state(WsmApplicationState.OPERATING);
appService.processApp(wsmApp2, dbAppMap);
assertMessage(1, INFO_CREATED);
// 2nd pass - only process 1
dbAppMap = appService.buildAppMap();
appService.enableTestMode();
appService.processApp(wsmApp2, dbAppMap);
assertMessage(0, INFO_NOCHANGE);
appService.checkMissingConfig(dbAppMap);
assertMessage(1, ERROR_MISSING_APP);
// 3rd pass - process none
dbAppMap = appService.buildAppMap();
appService.checkMissingConfig(dbAppMap);
assertMessage(2, ERROR_MISSING_APP);
}
use of bio.terra.workspace.service.workspace.model.WsmApplication in project terra-workspace-manager by DataBiosphere.
the class ApplicationUnitTest method configValidationSuccess.
private WsmApplication configValidationSuccess(App testApp) {
appService.enableTestMode();
Optional<WsmApplication> wsmAppOpt = appService.appFromConfig(testApp);
assertTrue(wsmAppOpt.isPresent());
List<String> errorList = appService.getErrorList();
assertEquals(errorList.size(), 0);
WsmApplication wsmApp = wsmAppOpt.get();
assertEquals(wsmApp.getApplicationId(), GOOD_UUID);
assertEquals(wsmApp.getServiceAccount(), GOOD_EMAIL);
assertEquals(wsmApp.getState().name(), GOOD_STATE);
return wsmApp;
}
use of bio.terra.workspace.service.workspace.model.WsmApplication in project terra-workspace-manager by DataBiosphere.
the class ApplicationAblePrecheckStep method doStep.
@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
WsmApplication application = applicationDao.getApplication(applicationId);
// For enable, we require that the application be in the operating state
if (ableEnum == AbleEnum.ENABLE) {
if (application.getState() != WsmApplicationState.OPERATING) {
throw new InvalidApplicationStateException("Applications is " + application.getState().toApi() + " and cannot be enabled");
}
}
FlightMap workingMap = context.getWorkingMap();
workingMap.put(WsmApplicationKeys.WSM_APPLICATION, application);
// See if the application is enabled
WsmWorkspaceApplication workspaceApp;
try {
workspaceApp = applicationDao.getWorkspaceApplication(workspaceId, applicationId);
workingMap.put(WsmApplicationKeys.APPLICATION_ABLE_DAO, computeCorrectState(ableEnum, workspaceApp.isEnabled()));
} catch (ApplicationNotFoundException e) {
workingMap.put(WsmApplicationKeys.APPLICATION_ABLE_DAO, computeCorrectState(ableEnum, false));
}
// See if the application already has APPLICATION role for the workspace
boolean enabledSam = samService.isApplicationEnabledInSam(workspaceId, application.getServiceAccount(), userRequest);
workingMap.put(WsmApplicationKeys.APPLICATION_ABLE_SAM, computeCorrectState(ableEnum, enabledSam));
return StepResult.getStepResultSuccess();
}
Aggregations