Search in sources :

Example 1 with UpdateWorkspaceRequest

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

the class WorkspacesControllerTest method testUpdateWorkspaceStaleThrows.

@Test(expected = ConflictException.class)
public void testUpdateWorkspaceStaleThrows() throws Exception {
    Workspace ws = createDefaultWorkspace();
    ws = workspacesController.createWorkspace(ws).getBody();
    UpdateWorkspaceRequest request = new UpdateWorkspaceRequest();
    request.setWorkspace(new Workspace().name("updated-name").etag(ws.getEtag()));
    stubGetWorkspace(ws.getNamespace(), ws.getId(), ws.getCreator(), WorkspaceAccessLevel.OWNER);
    workspacesController.updateWorkspace(ws.getNamespace(), ws.getId(), request).getBody();
    // Still using the initial now-stale etag; this should throw.
    stubGetWorkspace(ws.getNamespace(), ws.getId(), ws.getCreator(), WorkspaceAccessLevel.OWNER);
    request.setWorkspace(new Workspace().name("updated-name2").etag(ws.getEtag()));
    workspacesController.updateWorkspace(ws.getNamespace(), ws.getId(), request).getBody();
}
Also used : UpdateWorkspaceRequest(org.pmiops.workbench.model.UpdateWorkspaceRequest) Workspace(org.pmiops.workbench.model.Workspace) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 2 with UpdateWorkspaceRequest

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

the class WorkspacesControllerTest method testUpdateWorkspace.

@Test
public void testUpdateWorkspace() throws Exception {
    Workspace ws = createDefaultWorkspace();
    ws = workspacesController.createWorkspace(ws).getBody();
    ws.setName("updated-name");
    stubGetWorkspace(ws.getNamespace(), ws.getId(), ws.getCreator(), WorkspaceAccessLevel.OWNER);
    UpdateWorkspaceRequest request = new UpdateWorkspaceRequest();
    request.setWorkspace(ws);
    Workspace updated = workspacesController.updateWorkspace(ws.getNamespace(), ws.getId(), request).getBody();
    ws.setEtag(updated.getEtag());
    assertThat(updated).isEqualTo(ws);
    ws.setName("updated-name2");
    stubGetWorkspace(ws.getNamespace(), ws.getId(), ws.getCreator(), WorkspaceAccessLevel.OWNER);
    updated = workspacesController.updateWorkspace(ws.getNamespace(), ws.getId(), request).getBody();
    ws.setEtag(updated.getEtag());
    assertThat(updated).isEqualTo(ws);
    stubGetWorkspace(ws.getNamespace(), ws.getId(), ws.getCreator(), WorkspaceAccessLevel.OWNER);
    Workspace got = workspacesController.getWorkspace(ws.getNamespace(), ws.getId()).getBody().getWorkspace();
    assertThat(got).isEqualTo(ws);
}
Also used : UpdateWorkspaceRequest(org.pmiops.workbench.model.UpdateWorkspaceRequest) Workspace(org.pmiops.workbench.model.Workspace) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 3 with UpdateWorkspaceRequest

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

the class WorkspacesControllerTest method testUpdateWorkspaceInvalidEtagsThrow.

@Test
public void testUpdateWorkspaceInvalidEtagsThrow() throws Exception {
    Workspace ws = createDefaultWorkspace();
    ws = workspacesController.createWorkspace(ws).getBody();
    // TODO: Refactor to be a @Parameterized test case.
    List<String> cases = ImmutableList.of("", "hello, world", "\"\"", "\"\"1234\"\"", "\"-1\"");
    for (String etag : cases) {
        try {
            stubGetWorkspace(ws.getNamespace(), ws.getId(), ws.getCreator(), WorkspaceAccessLevel.OWNER);
            UpdateWorkspaceRequest request = new UpdateWorkspaceRequest();
            request.setWorkspace(new Workspace().name("updated-name").etag(etag));
            workspacesController.updateWorkspace(ws.getNamespace(), ws.getId(), request);
            fail(String.format("expected BadRequestException for etag: %s", etag));
        } catch (BadRequestException e) {
        // expected
        }
    }
}
Also used : BadRequestException(org.pmiops.workbench.exceptions.BadRequestException) UpdateWorkspaceRequest(org.pmiops.workbench.model.UpdateWorkspaceRequest) Matchers.anyString(org.mockito.Matchers.anyString) Workspace(org.pmiops.workbench.model.Workspace) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 4 with UpdateWorkspaceRequest

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

the class WorkspacesControllerTest method testReaderUpdateWorkspaceThrows.

@Test(expected = ForbiddenException.class)
public void testReaderUpdateWorkspaceThrows() throws Exception {
    Workspace ws = createDefaultWorkspace();
    ws = workspacesController.createWorkspace(ws).getBody();
    ws.setName("updated-name");
    UpdateWorkspaceRequest request = new UpdateWorkspaceRequest();
    request.setWorkspace(ws);
    stubGetWorkspace(ws.getNamespace(), ws.getId(), ws.getCreator(), WorkspaceAccessLevel.READER);
    Workspace updated = workspacesController.updateWorkspace(ws.getNamespace(), ws.getId(), request).getBody();
}
Also used : UpdateWorkspaceRequest(org.pmiops.workbench.model.UpdateWorkspaceRequest) Workspace(org.pmiops.workbench.model.Workspace) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 UpdateWorkspaceRequest (org.pmiops.workbench.model.UpdateWorkspaceRequest)4 Workspace (org.pmiops.workbench.model.Workspace)4 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)4 Matchers.anyString (org.mockito.Matchers.anyString)1 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)1