Credentials mockCredentials = mock(Credentials.class);
when(mockIdentity.getCredentials()).thenReturn(mockCredentials);
when(mockCredentials.getUsername()).thenReturn("admin");
Project project =
new Project(PROJECT_SLUG, PROJECT_NAME,
ProjectType.Gettext.toString(), PROJECT_DESC);
IProjectResource projectService =
getClientRequestFactory().createProxy(IProjectResource.class,
createBaseURI(RESOURCE_PATH).resolve(PROJECT_SLUG));
Response response = projectService.put(project);
assertThat(response.getStatus(), is(Status.CREATED.getStatusCode()));
String location = (String) response.getMetadata().getFirst("Location");
assertThat(location, endsWith("/projects/p/" + PROJECT_SLUG));
projectService =
getClientRequestFactory().createProxy(IProjectResource.class,
createBaseURI(RESOURCE_PATH).resolve(PROJECT_SLUG));
ClientResponse<Project> response1 = projectService.get();
assertThat(response1.getStatus(), is(Status.OK.getStatusCode()));
Project projectRes = response1.getEntity();
assertThat(projectRes, notNullValue());
assertThat(projectRes.getName(), is(PROJECT_NAME));
assertThat(projectRes.getId(), is(PROJECT_SLUG));
assertThat(projectRes.getDescription(), is(PROJECT_DESC));
verify(mockIdentity).checkPermission(any(HProject.class), eq("insert"));
}