Search in sources :

Example 1 with WsmApplication

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);
}
Also used : WsmApplication(bio.terra.workspace.service.workspace.model.WsmApplication) UUID(java.util.UUID) WsmDbApplication(bio.terra.workspace.service.workspace.WsmApplicationService.WsmDbApplication)

Example 2 with WsmApplication

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());
}
Also used : App(bio.terra.workspace.app.configuration.external.WsmApplicationConfiguration.App) WsmApplication(bio.terra.workspace.service.workspace.model.WsmApplication) Test(org.junit.jupiter.api.Test) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest)

Example 3 with WsmApplication

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);
}
Also used : WsmApplication(bio.terra.workspace.service.workspace.model.WsmApplication) HashMap(java.util.HashMap) UUID(java.util.UUID) WsmDbApplication(bio.terra.workspace.service.workspace.WsmApplicationService.WsmDbApplication) DirtiesContext(org.springframework.test.annotation.DirtiesContext) Test(org.junit.jupiter.api.Test) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest)

Example 4 with WsmApplication

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;
}
Also used : WsmApplication(bio.terra.workspace.service.workspace.model.WsmApplication)

Example 5 with WsmApplication

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();
}
Also used : WsmApplication(bio.terra.workspace.service.workspace.model.WsmApplication) ApplicationNotFoundException(bio.terra.workspace.db.exception.ApplicationNotFoundException) FlightMap(bio.terra.stairway.FlightMap) InvalidApplicationStateException(bio.terra.workspace.db.exception.InvalidApplicationStateException) WsmWorkspaceApplication(bio.terra.workspace.service.workspace.model.WsmWorkspaceApplication)

Aggregations

WsmApplication (bio.terra.workspace.service.workspace.model.WsmApplication)12 UUID (java.util.UUID)5 Test (org.junit.jupiter.api.Test)4 FlightMap (bio.terra.stairway.FlightMap)3 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)3 WsmDbApplication (bio.terra.workspace.service.workspace.WsmApplicationService.WsmDbApplication)3 HashMap (java.util.HashMap)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 DirtiesContext (org.springframework.test.annotation.DirtiesContext)2 App (bio.terra.workspace.app.configuration.external.WsmApplicationConfiguration.App)1 BaseTest (bio.terra.workspace.common.BaseTest)1 ApplicationNotFoundException (bio.terra.workspace.db.exception.ApplicationNotFoundException)1 InvalidApplicationStateException (bio.terra.workspace.db.exception.InvalidApplicationStateException)1 InvalidApplicationConfigException (bio.terra.workspace.service.workspace.exceptions.InvalidApplicationConfigException)1 WsmApplicationState (bio.terra.workspace.service.workspace.model.WsmApplicationState)1 WsmWorkspaceApplication (bio.terra.workspace.service.workspace.model.WsmWorkspaceApplication)1 Nullable (javax.annotation.Nullable)1