Search in sources :

Example 11 with Workspace

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

the class WorkspacesControllerTest method testCreateWorkspaceAlreadyApproved.

@Test
public void testCreateWorkspaceAlreadyApproved() throws Exception {
    Workspace workspace = createDefaultWorkspace();
    workspace.getResearchPurpose().setApproved(true);
    workspacesController.createWorkspace(workspace);
    stubGetWorkspace(workspace.getNamespace(), workspace.getName(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
    Workspace workspace2 = workspacesController.getWorkspace(workspace.getNamespace(), workspace.getId()).getBody().getWorkspace();
    assertThat(workspace2.getResearchPurpose().getApproved()).isNotEqualTo(true);
}
Also used : Workspace(org.pmiops.workbench.model.Workspace) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 12 with Workspace

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

the class WorkspacesControllerTest method testCloneWorkspaceWithNotebooks.

@Test
public void testCloneWorkspaceWithNotebooks() throws Exception {
    Workspace workspace = createDefaultWorkspace();
    workspace = workspacesController.createWorkspace(workspace).getBody();
    stubGetWorkspace(workspace.getNamespace(), workspace.getName(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
    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);
    org.pmiops.workbench.firecloud.model.Workspace fcWorkspace = createFcWorkspace(modWorkspace.getNamespace(), modWorkspace.getName(), LOGGED_IN_USER_EMAIL);
    fcWorkspace.setBucketName("bucket2");
    stubGetWorkspace(fcWorkspace, WorkspaceAccessLevel.OWNER);
    String f1 = "notebooks/f1.ipynb";
    String f2 = "notebooks/f2.ipynb";
    String f3 = "notebooks/f3.vcf";
    // Note: mockBlob cannot be inlined into thenReturn() due to Mockito nuances.
    List<Blob> blobs = ImmutableList.of(mockBlob(BUCKET_NAME, f1), mockBlob(BUCKET_NAME, f2), mockBlob(BUCKET_NAME, f3));
    when(cloudStorageService.getBlobList(BUCKET_NAME, "notebooks")).thenReturn(blobs);
    workspacesController.cloneWorkspace(workspace.getNamespace(), workspace.getId(), req).getBody().getWorkspace();
    verify(cloudStorageService).copyBlob(BlobId.of(BUCKET_NAME, f1), BlobId.of("bucket2", f1));
    verify(cloudStorageService).copyBlob(BlobId.of(BUCKET_NAME, f2), BlobId.of("bucket2", f2));
    verify(cloudStorageService, never()).copyBlob(BlobId.of(BUCKET_NAME, f3), BlobId.of("bucket2", f3));
}
Also used : Blob(com.google.cloud.storage.Blob) CloneWorkspaceRequest(org.pmiops.workbench.model.CloneWorkspaceRequest) 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 13 with Workspace

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

the class WorkspacesControllerTest method testRejectAfterApproveThrows.

@Test(expected = BadRequestException.class)
public void testRejectAfterApproveThrows() throws Exception {
    Workspace ws = createDefaultWorkspace();
    ResearchPurpose researchPurpose = ws.getResearchPurpose();
    workspacesController.createWorkspace(ws);
    ResearchPurposeReviewRequest request = new ResearchPurposeReviewRequest();
    request.setApproved(true);
    workspacesController.reviewWorkspace(ws.getNamespace(), ws.getName(), request);
    request.setApproved(false);
    workspacesController.reviewWorkspace(ws.getNamespace(), ws.getName(), request);
}
Also used : ResearchPurposeReviewRequest(org.pmiops.workbench.model.ResearchPurposeReviewRequest) 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 14 with Workspace

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

the class CohortsControllerTest method setUp.

@Before
public void setUp() throws Exception {
    User user = new User();
    user.setEmail("bob@gmail.com");
    user.setUserId(123L);
    user.setDisabled(false);
    user.setEmailVerificationStatus(EmailVerificationStatus.SUBSCRIBED);
    user = userDao.save(user);
    when(userProvider.get()).thenReturn(user);
    cdrVersion = new CdrVersion();
    cdrVersion.setName(CDR_VERSION_NAME);
    cdrVersionDao.save(cdrVersion);
    searchRequest = SearchRequests.males();
    cohortCriteria = new Gson().toJson(searchRequest);
    workspace = new Workspace();
    workspace.setName(WORKSPACE_NAME);
    workspace.setNamespace(WORKSPACE_NAMESPACE);
    workspace.setDataAccessLevel(DataAccessLevel.PROTECTED);
    workspace.setResearchPurpose(new ResearchPurpose());
    workspace.setCdrVersionId(String.valueOf(cdrVersion.getCdrVersionId()));
    CLOCK.setInstant(NOW);
    WorkspacesController workspacesController = new WorkspacesController(workspaceService, cdrVersionDao, userDao, userProvider, fireCloudService, cloudStorageService, CLOCK, "https://api.blah.com", userService);
    stubGetWorkspace(WORKSPACE_NAMESPACE, WORKSPACE_NAME, "bob@gmail.com", WorkspaceAccessLevel.OWNER);
    workspace = workspacesController.createWorkspace(workspace).getBody();
    this.cohortsController = new CohortsController(workspaceService, cohortDao, cdrVersionDao, cohortReviewDao, cohortMaterializationService, userProvider, CLOCK);
}
Also used : CdrVersion(org.pmiops.workbench.db.model.CdrVersion) User(org.pmiops.workbench.db.model.User) Gson(com.google.gson.Gson) Workspace(org.pmiops.workbench.model.Workspace) ResearchPurpose(org.pmiops.workbench.model.ResearchPurpose) Before(org.junit.Before)

Example 15 with Workspace

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

the class WorkspacesControllerTest method testShareWorkspace.

@Test
public void testShareWorkspace() throws Exception {
    User writerUser = new User();
    writerUser.setEmail("writerfriend@gmail.com");
    writerUser.setUserId(124L);
    writerUser.setFreeTierBillingProjectName("TestBillingProject2");
    writerUser.setDisabled(false);
    writerUser = userDao.save(writerUser);
    User readerUser = new User();
    readerUser.setEmail("readerfriend@gmail.com");
    readerUser.setUserId(125L);
    readerUser.setFreeTierBillingProjectName("TestBillingProject3");
    readerUser.setDisabled(false);
    readerUser = userDao.save(readerUser);
    Workspace workspace = createDefaultWorkspace();
    workspace = workspacesController.createWorkspace(workspace).getBody();
    ShareWorkspaceRequest shareWorkspaceRequest = new ShareWorkspaceRequest();
    shareWorkspaceRequest.setWorkspaceEtag(workspace.getEtag());
    UserRole creator = new UserRole();
    creator.setEmail(LOGGED_IN_USER_EMAIL);
    creator.setRole(WorkspaceAccessLevel.OWNER);
    shareWorkspaceRequest.addItemsItem(creator);
    UserRole writer = new UserRole();
    writer.setEmail("writerfriend@gmail.com");
    writer.setRole(WorkspaceAccessLevel.WRITER);
    shareWorkspaceRequest.addItemsItem(writer);
    UserRole reader = new UserRole();
    reader.setEmail("readerfriend@gmail.com");
    reader.setRole(WorkspaceAccessLevel.READER);
    shareWorkspaceRequest.addItemsItem(reader);
    // Simulate time between API calls to trigger last-modified/@Version changes.
    CLOCK.increment(1000);
    WorkspaceACLUpdateResponseList responseValue = new WorkspaceACLUpdateResponseList();
    when(fireCloudService.updateWorkspaceACL(anyString(), anyString(), anyListOf(WorkspaceACLUpdate.class))).thenReturn(responseValue);
    ShareWorkspaceResponse shareResp = workspacesController.shareWorkspace(workspace.getNamespace(), workspace.getName(), shareWorkspaceRequest).getBody();
    stubGetWorkspace(workspace.getNamespace(), workspace.getName(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
    Workspace workspace2 = workspacesController.getWorkspace(workspace.getNamespace(), workspace.getName()).getBody().getWorkspace();
    assertThat(shareResp.getWorkspaceEtag()).isEqualTo(workspace2.getEtag());
    assertThat(workspace2.getUserRoles().size()).isEqualTo(3);
    int numOwners = 0;
    int numWriters = 0;
    int numReaders = 0;
    for (UserRole userRole : workspace2.getUserRoles()) {
        if (userRole.getRole().equals(WorkspaceAccessLevel.OWNER)) {
            assertThat(userRole.getEmail()).isEqualTo(LOGGED_IN_USER_EMAIL);
            numOwners++;
        } else if (userRole.getRole().equals(WorkspaceAccessLevel.WRITER)) {
            assertThat(userRole.getEmail()).isEqualTo("writerfriend@gmail.com");
            numWriters++;
        } else {
            assertThat(userRole.getEmail()).isEqualTo("readerfriend@gmail.com");
            numReaders++;
        }
    }
    assertThat(numOwners).isEqualTo(1);
    assertThat(numWriters).isEqualTo(1);
    assertThat(numReaders).isEqualTo(1);
    assertThat(workspace.getEtag()).isNotEqualTo(workspace2.getEtag());
}
Also used : ShareWorkspaceResponse(org.pmiops.workbench.model.ShareWorkspaceResponse) User(org.pmiops.workbench.db.model.User) UserRole(org.pmiops.workbench.model.UserRole) WorkspaceACLUpdateResponseList(org.pmiops.workbench.firecloud.model.WorkspaceACLUpdateResponseList) ShareWorkspaceRequest(org.pmiops.workbench.model.ShareWorkspaceRequest) Workspace(org.pmiops.workbench.model.Workspace) WorkspaceACLUpdate(org.pmiops.workbench.firecloud.model.WorkspaceACLUpdate) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Aggregations

Workspace (org.pmiops.workbench.model.Workspace)31 Test (org.junit.Test)23 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)23 ResearchPurpose (org.pmiops.workbench.model.ResearchPurpose)13 User (org.pmiops.workbench.db.model.User)9 CloneWorkspaceRequest (org.pmiops.workbench.model.CloneWorkspaceRequest)8 UserRole (org.pmiops.workbench.model.UserRole)7 ConflictException (org.pmiops.workbench.exceptions.ConflictException)6 ShareWorkspaceRequest (org.pmiops.workbench.model.ShareWorkspaceRequest)6 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)5 WorkspaceACLUpdate (org.pmiops.workbench.firecloud.model.WorkspaceACLUpdate)5 WorkspaceACLUpdateResponseList (org.pmiops.workbench.firecloud.model.WorkspaceACLUpdateResponseList)5 UpdateWorkspaceRequest (org.pmiops.workbench.model.UpdateWorkspaceRequest)5 Blob (com.google.cloud.storage.Blob)4 Matchers.anyString (org.mockito.Matchers.anyString)4 ApiException (org.pmiops.workbench.firecloud.ApiException)4 ResearchPurposeReviewRequest (org.pmiops.workbench.model.ResearchPurposeReviewRequest)4 Timestamp (java.sql.Timestamp)3 FirecloudWorkspaceId (org.pmiops.workbench.db.model.Workspace.FirecloudWorkspaceId)3 ShareWorkspaceResponse (org.pmiops.workbench.model.ShareWorkspaceResponse)3