Search in sources :

Example 1 with ResearchPurpose

use of org.pmiops.workbench.model.ResearchPurpose in project workbench by all-of-us.

the class WorkspacesControllerTest method testListForApproval.

@Test
public void testListForApproval() throws Exception {
    List<Workspace> forApproval = workspacesController.getWorkspacesForReview().getBody().getItems();
    assertThat(forApproval).isEmpty();
    Workspace ws;
    ResearchPurpose researchPurpose;
    String nameForRequested = "requestedButNotApprovedYet";
    // requested approval, but not approved
    ws = createDefaultWorkspace();
    ws.setName(nameForRequested);
    researchPurpose = ws.getResearchPurpose();
    researchPurpose.setApproved(null);
    researchPurpose.setTimeReviewed(null);
    stubGetWorkspace(ws.getNamespace(), ws.getName().toLowerCase(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
    workspacesController.createWorkspace(ws);
    // already approved
    ws = createDefaultWorkspace();
    ws.setName("alreadyApproved");
    stubGetWorkspace(ws.getNamespace(), ws.getName().toLowerCase(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
    researchPurpose = ws.getResearchPurpose();
    ws = workspacesController.createWorkspace(ws).getBody();
    ResearchPurposeReviewRequest request = new ResearchPurposeReviewRequest();
    request.setApproved(true);
    workspacesController.reviewWorkspace(ws.getNamespace(), ws.getId(), request);
    // no approval requested
    ws = createDefaultWorkspace();
    ws.setName("noApprovalRequested");
    researchPurpose = ws.getResearchPurpose();
    researchPurpose.setReviewRequested(false);
    researchPurpose.setTimeRequested(null);
    researchPurpose.setApproved(null);
    researchPurpose.setTimeReviewed(null);
    stubGetWorkspace(ws.getNamespace(), ws.getName().toLowerCase(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
    ws = workspacesController.createWorkspace(ws).getBody();
    forApproval = workspacesController.getWorkspacesForReview().getBody().getItems();
    assertThat(forApproval.size()).isEqualTo(1);
    ws = forApproval.get(0);
    assertThat(ws.getName()).isEqualTo(nameForRequested);
}
Also used : ResearchPurposeReviewRequest(org.pmiops.workbench.model.ResearchPurposeReviewRequest) Matchers.anyString(org.mockito.Matchers.anyString) Workspace(org.pmiops.workbench.model.Workspace) ResearchPurpose(org.pmiops.workbench.model.ResearchPurpose) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 2 with ResearchPurpose

use of org.pmiops.workbench.model.ResearchPurpose in project workbench by all-of-us.

the class WorkspacesControllerTest method testCloneWorkspaceDifferentOwner.

@Test
public void testCloneWorkspaceDifferentOwner() throws Exception {
    Workspace workspace = createDefaultWorkspace();
    workspace = workspacesController.createWorkspace(workspace).getBody();
    User cloner = new User();
    cloner.setEmail("cloner@gmail.com");
    cloner.setUserId(456L);
    cloner.setFreeTierBillingProjectName("TestBillingProject1");
    cloner.setDisabled(false);
    cloner = userDao.save(cloner);
    when(userProvider.get()).thenReturn(cloner);
    stubGetWorkspace(workspace.getNamespace(), workspace.getName(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.READER);
    CloneWorkspaceRequest req = new CloneWorkspaceRequest();
    Workspace modWorkspace = new Workspace();
    modWorkspace.setName("cloned");
    modWorkspace.setNamespace("cloned-ns");
    ResearchPurpose modPurpose = new ResearchPurpose();
    modPurpose.setAncestry(true);
    modWorkspace.setResearchPurpose(modPurpose);
    req.setWorkspace(modWorkspace);
    stubGetWorkspace(modWorkspace.getNamespace(), modWorkspace.getName(), "cloner@gmail.com", WorkspaceAccessLevel.OWNER);
    Workspace workspace2 = workspacesController.cloneWorkspace(workspace.getNamespace(), workspace.getId(), req).getBody().getWorkspace();
    assertThat(workspace2.getCreator()).isEqualTo(cloner.getEmail());
    assertThat(workspace2.getUserRoles().size()).isEqualTo(1);
    assertThat(workspace2.getUserRoles().get(0).getRole()).isEqualTo(WorkspaceAccessLevel.OWNER);
    assertThat(workspace2.getUserRoles().get(0).getEmail()).isEqualTo(cloner.getEmail());
}
Also used : User(org.pmiops.workbench.db.model.User) CloneWorkspaceRequest(org.pmiops.workbench.model.CloneWorkspaceRequest) Workspace(org.pmiops.workbench.model.Workspace) ResearchPurpose(org.pmiops.workbench.model.ResearchPurpose) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 3 with ResearchPurpose

use of org.pmiops.workbench.model.ResearchPurpose in project workbench by all-of-us.

the class WorkspacesControllerTest method testCloneNotFound.

@Test(expected = NotFoundException.class)
public void testCloneNotFound() throws Exception {
    doThrow(new ApiException(404, "")).when(fireCloudService).getWorkspace("doesnot", "exist");
    CloneWorkspaceRequest req = new CloneWorkspaceRequest();
    Workspace modWorkspace = new Workspace();
    modWorkspace.setName("cloned");
    modWorkspace.setNamespace("cloned-ns");
    req.setWorkspace(modWorkspace);
    ResearchPurpose modPurpose = new ResearchPurpose();
    modPurpose.setAncestry(true);
    modWorkspace.setResearchPurpose(modPurpose);
    workspacesController.cloneWorkspace("doesnot", "exist", req);
}
Also used : CloneWorkspaceRequest(org.pmiops.workbench.model.CloneWorkspaceRequest) ApiException(org.pmiops.workbench.firecloud.ApiException) Workspace(org.pmiops.workbench.model.Workspace) ResearchPurpose(org.pmiops.workbench.model.ResearchPurpose) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 4 with ResearchPurpose

use of org.pmiops.workbench.model.ResearchPurpose in project workbench by all-of-us.

the class WorkspacesControllerTest method testClonePermissionDenied.

@Test(expected = NotFoundException.class)
public void testClonePermissionDenied() throws Exception {
    Workspace workspace = createDefaultWorkspace();
    workspace = workspacesController.createWorkspace(workspace).getBody();
    // Clone with a different user.
    User cloner = new User();
    cloner.setEmail("cloner@gmail.com");
    cloner.setUserId(456L);
    cloner.setFreeTierBillingProjectName("TestBillingProject1");
    cloner.setDisabled(false);
    cloner = userDao.save(cloner);
    when(userProvider.get()).thenReturn(cloner);
    // Permission denied manifests as a 404 in Firecloud.
    when(fireCloudService.getWorkspace(workspace.getNamespace(), workspace.getName())).thenThrow(new ApiException(404, ""));
    CloneWorkspaceRequest req = new CloneWorkspaceRequest();
    Workspace modWorkspace = new Workspace();
    modWorkspace.setName("cloned");
    modWorkspace.setNamespace("cloned-ns");
    req.setWorkspace(modWorkspace);
    ResearchPurpose modPurpose = new ResearchPurpose();
    modPurpose.setAncestry(true);
    modWorkspace.setResearchPurpose(modPurpose);
    workspacesController.cloneWorkspace(workspace.getNamespace(), workspace.getId(), req);
}
Also used : User(org.pmiops.workbench.db.model.User) CloneWorkspaceRequest(org.pmiops.workbench.model.CloneWorkspaceRequest) Workspace(org.pmiops.workbench.model.Workspace) ApiException(org.pmiops.workbench.firecloud.ApiException) ResearchPurpose(org.pmiops.workbench.model.ResearchPurpose) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 5 with ResearchPurpose

use of org.pmiops.workbench.model.ResearchPurpose in project workbench by all-of-us.

the class WorkspacesControllerTest method createDefaultWorkspace.

public Workspace createDefaultWorkspace() throws Exception {
    ResearchPurpose researchPurpose = new ResearchPurpose();
    researchPurpose.setDiseaseFocusedResearch(true);
    researchPurpose.setDiseaseOfFocus("cancer");
    researchPurpose.setMethodsDevelopment(true);
    researchPurpose.setControlSet(true);
    researchPurpose.setAggregateAnalysis(true);
    researchPurpose.setAncestry(true);
    researchPurpose.setCommercialPurpose(true);
    researchPurpose.setPopulation(true);
    researchPurpose.setPopulationOfFocus("population");
    researchPurpose.setAdditionalNotes("additional notes");
    researchPurpose.setTimeRequested(new Long(1000));
    researchPurpose.setTimeReviewed(new Long(1500));
    researchPurpose.setReviewRequested(true);
    researchPurpose.setApproved(false);
    Workspace workspace = new Workspace();
    workspace.setId("name");
    workspace.setName("name");
    workspace.setNamespace("namespace");
    workspace.setDescription("description");
    workspace.setDataAccessLevel(DataAccessLevel.PROTECTED);
    workspace.setResearchPurpose(researchPurpose);
    workspace.setUserRoles(new ArrayList<UserRole>());
    workspace.setCdrVersionId(cdrVersionId);
    stubGetWorkspace("namespace", "name", LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
    return workspace;
}
Also used : UserRole(org.pmiops.workbench.model.UserRole) ResearchPurpose(org.pmiops.workbench.model.ResearchPurpose) Workspace(org.pmiops.workbench.model.Workspace)

Aggregations

ResearchPurpose (org.pmiops.workbench.model.ResearchPurpose)13 Workspace (org.pmiops.workbench.model.Workspace)13 Test (org.junit.Test)10 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)10 CloneWorkspaceRequest (org.pmiops.workbench.model.CloneWorkspaceRequest)7 User (org.pmiops.workbench.db.model.User)6 Blob (com.google.cloud.storage.Blob)4 ApiException (org.pmiops.workbench.firecloud.ApiException)4 ResearchPurposeReviewRequest (org.pmiops.workbench.model.ResearchPurposeReviewRequest)4 UserRole (org.pmiops.workbench.model.UserRole)3 Gson (com.google.gson.Gson)2 Timestamp (java.sql.Timestamp)2 Before (org.junit.Before)2 Matchers.anyString (org.mockito.Matchers.anyString)2 CdrVersion (org.pmiops.workbench.db.model.CdrVersion)2 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)2 ConflictException (org.pmiops.workbench.exceptions.ConflictException)2 FailedPreconditionException (org.pmiops.workbench.exceptions.FailedPreconditionException)2 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)2 WorkspaceACLUpdate (org.pmiops.workbench.firecloud.model.WorkspaceACLUpdate)2