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