Search in sources :

Example 1 with WsmDbApplication

use of bio.terra.workspace.service.workspace.WsmApplicationService.WsmDbApplication 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 WsmDbApplication

use of bio.terra.workspace.service.workspace.WsmApplicationService.WsmDbApplication 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 3 with WsmDbApplication

use of bio.terra.workspace.service.workspace.WsmApplicationService.WsmDbApplication in project terra-workspace-manager by DataBiosphere.

the class ApplicationUnitTest method processAppTest.

// This test writes to the database, so conflicts with the missingConfigTest
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
@Test
public void processAppTest() {
    // Each "pass" in the test represents starting up with a different configuration.
    // Start with an empty map == no data in the database
    Map<UUID, WsmDbApplication> dbAppMap = new HashMap<>();
    WsmApplication wsmApp = makeWsmApp();
    // -- First Pass --
    // Create a new application in the database
    appService.enableTestMode();
    appService.processApp(wsmApp, dbAppMap);
    assertMessage(0, INFO_CREATED);
    // Retrieve apps from the database and validate the data round-trip
    // There can be stray applications in the database, so we use greater/equal assert
    List<WsmApplication> wsmApps = appDao.listApplications();
    assertThat(wsmApps.size(), greaterThanOrEqualTo(1));
    assertThat(wsmApps, hasItem(wsmApp));
    // Trying to create a duplicate new application. This is not caught in the map, but
    // the database create fails on a PK constraint.
    appService.processApp(wsmApp, dbAppMap);
    assertMessage(1, ERROR_CREATE_FAILED);
    // -- Second pass --
    // Rebuild the db app map with wsmApp in it
    dbAppMap = appService.buildAppMap();
    appService.enableTestMode();
    appService.processApp(wsmApp, dbAppMap);
    assertMessage(0, INFO_NOCHANGE);
    // Process it again with the same app map; should flag it as a duplicate
    appService.processApp(wsmApp, dbAppMap);
    assertMessage(1, ERROR_DUPLICATE);
    // -- 3rd pass -- update name and desc
    dbAppMap = appService.buildAppMap();
    appService.enableTestMode();
    wsmApp.displayName(GOOD_NAME);
    wsmApp.description(GOOD_DESC);
    appService.processApp(wsmApp, dbAppMap);
    assertMessage(0, INFO_UPDATED);
    // -- 4th pass -- State transition to deprecated
    stateTransition(WsmApplicationState.DEPRECATED, INFO_UPDATED);
    // -- 5th pass -- State transition back to operating
    stateTransition(WsmApplicationState.OPERATING, INFO_UPDATED);
    // -- 6th pass -- State transition to decommissioned
    stateTransition(WsmApplicationState.DECOMMISSIONED, INFO_UPDATED);
    // -- 7th pass -- Cannot transition from decommissioned
    stateTransition(WsmApplicationState.OPERATING, ERROR_DECOMMISSIONED);
    // -- 8th pass -- Cannot transition from decommissioned
    stateTransition(WsmApplicationState.DEPRECATED, ERROR_DECOMMISSIONED);
}
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)

Aggregations

WsmDbApplication (bio.terra.workspace.service.workspace.WsmApplicationService.WsmDbApplication)3 WsmApplication (bio.terra.workspace.service.workspace.model.WsmApplication)3 UUID (java.util.UUID)3 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)2 HashMap (java.util.HashMap)2 Test (org.junit.jupiter.api.Test)2 DirtiesContext (org.springframework.test.annotation.DirtiesContext)2