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());
}
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());
}
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));
}
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));
}
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));
}
Aggregations