Search in sources :

Example 31 with Workspace

use of bio.terra.workspace.service.workspace.model.Workspace in project terra-workspace-manager by DataBiosphere.

the class WorkspaceServiceTest method createMcWorkspaceDoSteps.

@Test
void createMcWorkspaceDoSteps() {
    Workspace request = defaultRequestBuilder(UUID.randomUUID()).build();
    Map<String, StepStatus> retrySteps = new HashMap<>();
    retrySteps.put(CreateWorkspaceAuthzStep.class.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY);
    retrySteps.put(CreateWorkspaceStep.class.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY);
    FlightDebugInfo debugInfo = FlightDebugInfo.newBuilder().doStepFailures(retrySteps).build();
    jobService.setFlightDebugInfoForTest(debugInfo);
    UUID createdId = workspaceService.createWorkspace(request, USER_REQUEST);
    assertEquals(createdId, request.getWorkspaceId());
}
Also used : FlightDebugInfo(bio.terra.stairway.FlightDebugInfo) HashMap(java.util.HashMap) CreateWorkspaceStep(bio.terra.workspace.service.workspace.flight.CreateWorkspaceStep) StepStatus(bio.terra.stairway.StepStatus) UUID(java.util.UUID) CreateWorkspaceAuthzStep(bio.terra.workspace.service.workspace.flight.CreateWorkspaceAuthzStep) Workspace(bio.terra.workspace.service.workspace.model.Workspace) ApiClonedWorkspace(bio.terra.workspace.generated.model.ApiClonedWorkspace) Test(org.junit.jupiter.api.Test) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest)

Example 32 with Workspace

use of bio.terra.workspace.service.workspace.model.Workspace in project terra-workspace-manager by DataBiosphere.

the class WorkspaceServiceTest method deleteWorkspaceWithGoogleContext.

@Test
@DisabledIfEnvironmentVariable(named = "TEST_ENV", matches = BUFFER_SERVICE_DISABLED_ENVS_REG_EX)
void deleteWorkspaceWithGoogleContext() throws Exception {
    Workspace request = defaultRequestBuilder(UUID.randomUUID()).spendProfileId(spendUtils.defaultSpendId()).workspaceStage(WorkspaceStage.MC_WORKSPACE).build();
    workspaceService.createWorkspace(request, USER_REQUEST);
    String jobId = UUID.randomUUID().toString();
    workspaceService.createGcpCloudContext(request.getWorkspaceId(), jobId, USER_REQUEST, "/fake/value");
    jobService.waitForJob(jobId);
    assertNull(jobService.retrieveJobResult(jobId, Object.class, USER_REQUEST).getException());
    Workspace workspace = workspaceService.getWorkspace(request.getWorkspaceId(), USER_REQUEST);
    String projectId = workspaceService.getAuthorizedRequiredGcpProject(workspace.getWorkspaceId(), USER_REQUEST);
    // Verify project exists by retrieving it.
    crl.getCloudResourceManagerCow().projects().get(projectId).execute();
    workspaceService.deleteWorkspace(request.getWorkspaceId(), USER_REQUEST);
    // Check that project is now being deleted.
    Project project = crl.getCloudResourceManagerCow().projects().get(projectId).execute();
    assertEquals("DELETE_REQUESTED", project.getState());
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) Workspace(bio.terra.workspace.service.workspace.model.Workspace) ApiClonedWorkspace(bio.terra.workspace.generated.model.ApiClonedWorkspace) Test(org.junit.jupiter.api.Test) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest) DisabledIfEnvironmentVariable(org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)

Example 33 with Workspace

use of bio.terra.workspace.service.workspace.model.Workspace in project terra-workspace-manager by DataBiosphere.

the class WorkspaceServiceTest method testUpdateWorkspace.

@Test
void testUpdateWorkspace() {
    Map<String, String> propertyMap = new HashMap<>();
    propertyMap.put("foo", "bar");
    propertyMap.put("xyzzy", "plohg");
    Workspace request = defaultRequestBuilder(UUID.randomUUID()).properties(propertyMap).build();
    workspaceService.createWorkspace(request, USER_REQUEST);
    Workspace createdWorkspace = workspaceService.getWorkspace(request.getWorkspaceId(), USER_REQUEST);
    assertEquals(request.getWorkspaceId(), createdWorkspace.getWorkspaceId());
    assertEquals("", createdWorkspace.getDisplayName().orElse(null));
    assertEquals("", createdWorkspace.getDescription().orElse(null));
    UUID workspaceUuid = request.getWorkspaceId();
    String userFacingId = "my-user-facing-id";
    String name = "My workspace";
    String description = "The greatest workspace";
    Map<String, String> propertyMap2 = new HashMap<>();
    propertyMap.put("ted", "lasso");
    propertyMap.put("keeley", "jones");
    Workspace updatedWorkspace = workspaceService.updateWorkspace(USER_REQUEST, workspaceUuid, userFacingId, name, description, propertyMap2);
    assertEquals(userFacingId, updatedWorkspace.getUserFacingId());
    assertTrue(updatedWorkspace.getDisplayName().isPresent());
    assertEquals(name, updatedWorkspace.getDisplayName().get());
    assertTrue(updatedWorkspace.getDescription().isPresent());
    assertEquals(description, updatedWorkspace.getDescription().get());
    assertEquals(propertyMap2, updatedWorkspace.getProperties());
    String otherDescription = "The deprecated workspace";
    Workspace secondUpdatedWorkspace = workspaceService.updateWorkspace(USER_REQUEST, workspaceUuid, null, null, otherDescription, null);
    // Since name is null, leave it alone. Description should be updated.
    assertTrue(secondUpdatedWorkspace.getDisplayName().isPresent());
    assertEquals(name, secondUpdatedWorkspace.getDisplayName().get());
    assertTrue(secondUpdatedWorkspace.getDescription().isPresent());
    assertEquals(otherDescription, secondUpdatedWorkspace.getDescription().get());
    assertEquals(propertyMap2, updatedWorkspace.getProperties());
    // Sending through empty strings and an empty map clears the values.
    Map<String, String> propertyMap3 = new HashMap<>();
    Workspace thirdUpdatedWorkspace = workspaceService.updateWorkspace(USER_REQUEST, workspaceUuid, userFacingId, "", "", propertyMap3);
    assertTrue(thirdUpdatedWorkspace.getDisplayName().isPresent());
    assertEquals("", thirdUpdatedWorkspace.getDisplayName().get());
    assertTrue(thirdUpdatedWorkspace.getDescription().isPresent());
    assertEquals("", thirdUpdatedWorkspace.getDescription().get());
    // Fail if request doesn't contain any updated fields.
    assertThrows(MissingRequiredFieldException.class, () -> workspaceService.updateWorkspace(USER_REQUEST, workspaceUuid, null, null, null, null));
}
Also used : HashMap(java.util.HashMap) UUID(java.util.UUID) Workspace(bio.terra.workspace.service.workspace.model.Workspace) ApiClonedWorkspace(bio.terra.workspace.generated.model.ApiClonedWorkspace) Test(org.junit.jupiter.api.Test) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest)

Example 34 with Workspace

use of bio.terra.workspace.service.workspace.model.Workspace in project terra-workspace-manager by DataBiosphere.

the class WorkspaceServiceTest method testWithSpendProfile.

@Test
void testWithSpendProfile() {
    SpendProfileId spendProfileId = new SpendProfileId("foo");
    Workspace request = defaultRequestBuilder(UUID.randomUUID()).spendProfileId(spendProfileId).build();
    workspaceService.createWorkspace(request, USER_REQUEST);
    Workspace createdWorkspace = workspaceService.getWorkspace(request.getWorkspaceId(), USER_REQUEST);
    assertEquals(request.getWorkspaceId(), createdWorkspace.getWorkspaceId());
    assertEquals(spendProfileId, createdWorkspace.getSpendProfileId().orElse(null));
}
Also used : SpendProfileId(bio.terra.workspace.service.spendprofile.SpendProfileId) Workspace(bio.terra.workspace.service.workspace.model.Workspace) ApiClonedWorkspace(bio.terra.workspace.generated.model.ApiClonedWorkspace) Test(org.junit.jupiter.api.Test) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest)

Example 35 with Workspace

use of bio.terra.workspace.service.workspace.model.Workspace in project terra-workspace-manager by DataBiosphere.

the class WorkspaceServiceTest method getWorkspaceByUserFacingId_forbiddenExisting.

@Test
void getWorkspaceByUserFacingId_forbiddenExisting() throws Exception {
    String userFacingId = "user-facing-id-getworkspacebyuserfacingid_forbiddenexisting";
    Workspace request = defaultRequestBuilder(UUID.randomUUID()).userFacingId(userFacingId).build();
    workspaceService.createWorkspace(request, USER_REQUEST);
    Workspace createdWorkspace = workspaceService.getWorkspace(request.getWorkspaceId(), USER_REQUEST);
    doThrow(new ForbiddenException("forbid!")).when(mockSamService).checkAuthz(any(), any(), any(), any());
    assertThrows(ForbiddenException.class, () -> workspaceService.getWorkspaceByUserFacingId(userFacingId, USER_REQUEST));
}
Also used : ForbiddenException(bio.terra.common.exception.ForbiddenException) Workspace(bio.terra.workspace.service.workspace.model.Workspace) ApiClonedWorkspace(bio.terra.workspace.generated.model.ApiClonedWorkspace) Test(org.junit.jupiter.api.Test) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest)

Aggregations

Workspace (bio.terra.workspace.service.workspace.model.Workspace)74 Test (org.junit.jupiter.api.Test)40 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)30 ApiClonedWorkspace (bio.terra.workspace.generated.model.ApiClonedWorkspace)27 UUID (java.util.UUID)27 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)11 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)8 HashMap (java.util.HashMap)7 FlightDebugInfo (bio.terra.stairway.FlightDebugInfo)6 ApiCreatedWorkspace (bio.terra.workspace.generated.model.ApiCreatedWorkspace)6 SpendProfileId (bio.terra.workspace.service.spendprofile.SpendProfileId)6 ResponseEntity (org.springframework.http.ResponseEntity)6 FlightMap (bio.terra.stairway.FlightMap)5 StepStatus (bio.terra.stairway.StepStatus)5 Traced (io.opencensus.contrib.spring.aop.Traced)5 DisabledIfEnvironmentVariable (org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)5 ForbiddenException (bio.terra.common.exception.ForbiddenException)4 FlightState (bio.terra.stairway.FlightState)3 ApiWorkspaceDescription (bio.terra.workspace.generated.model.ApiWorkspaceDescription)3 JobBuilder (bio.terra.workspace.service.job.JobBuilder)3