use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.
the class ProjectServiceImplTest method testAddUserToProjectTwice.
@Test(expected = EntityExistsException.class)
public void testAddUserToProjectTwice() {
User u = new User("test", "test@nowhere.com", "PASSWOD!1", "Test", "User", "1234");
u.setId(new Long(1111));
Project p = project();
ProjectRole r = ProjectRole.PROJECT_USER;
ProjectUserJoin join = new ProjectUserJoin(p, u, r);
when(pujRepository.save(join)).thenThrow(new DataIntegrityViolationException("Duplicates."));
projectService.addUserToProject(p, u, r);
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.
the class ProjectUsersControllerTest method testAddUserToProject.
@Test
public void testAddUserToProject() throws ProjectWithoutOwnerException {
Project p = TestDataFactory.constructProject();
User u = TestDataFactory.constructUser();
ProjectRole r = ProjectRole.PROJECT_USER;
ProjectUserJoin j = new ProjectUserJoin(p, u, r);
MockHttpServletResponse response = new MockHttpServletResponse();
when(projectService.read(p.getId())).thenReturn(p);
when(userService.getUserByUsername(u.getUsername())).thenReturn(u);
when(projectService.addUserToProject(p, u, r)).thenReturn(j);
// prepare the "user" for addition to the project, just a map of userId and a username.
Map<String, String> userMap = ImmutableMap.of(RESTProjectUsersController.USER_ID_KEY, u.getUsername());
// add the user to the project
ModelMap map = controller.addUserToProject(p.getId(), userMap, response);
// confirm that the service method was called
verify(projectService, times(1)).addUserToProject(p, u, ProjectRole.PROJECT_USER);
verify(projectService, times(1)).read(p.getId());
verify(userService, times(1)).getUserByUsername(u.getUsername());
// check that the response is as expected:
assertEquals("Response must be CREATED", HttpStatus.CREATED.value(), response.getStatus());
// check for a correct user link
String location = response.getHeader(HttpHeaders.LOCATION);
assertNotNull("location must not be null", location);
assertFalse("location must not be empty", location.isEmpty());
assertEquals("location must be correct", "http://localhost/api/projects/" + p.getId() + "/users/" + u.getUsername(), location);
// check the ModelMap's resource type
Object o = map.get(RESTGenericController.RESOURCE_NAME);
assertNotNull("object must not be null", o);
assertTrue("object must be an instance of LabelledRelationshipResource", o instanceof LabelledRelationshipResource);
@SuppressWarnings("unchecked") LabelledRelationshipResource<Project, User> lrr = (LabelledRelationshipResource<Project, User>) o;
Object o2 = lrr.getResource();
assertNotNull("object must not be null", o2);
assertTrue("object must be an instance of ProjectUserJoin", o2 instanceof ProjectUserJoin);
ProjectUserJoin pj = (ProjectUserJoin) o2;
Object o3 = pj.getObject();
assertNotNull("object must not be null", o3);
assertTrue("object must be an instance of User", o3 instanceof User);
User user = (User) o3;
assertEquals("Username must be correct", user.getUsername(), u.getUsername());
// check for a correct relationship link
assertTrue("relationship link must be correct", lrr.getLink("self").getHref().endsWith(u.getUsername()));
Link relationship = lrr.getLink(RESTGenericController.REL_RELATIONSHIP);
assertNotNull("relationship link must exist", relationship);
assertEquals("relationship link must be correct", "http://localhost/api/projects/" + p.getId() + "/users/" + u.getUsername(), relationship.getHref());
// confirm that a project link exists
Link projectLink = lrr.getLink(RESTProjectsController.REL_PROJECT);
assertNotNull("project link must exist", projectLink);
assertEquals("project link must be correct", "http://localhost/api/projects/" + p.getId(), projectLink.getHref());
// confirm that a project users link exists
Link projectUsersLink = lrr.getLink(RESTProjectUsersController.REL_PROJECT_USERS);
assertNotNull("project users link must exist", projectUsersLink);
assertEquals("project users link must be correct", "http://localhost/api/projects/" + p.getId() + "/users", projectUsersLink.getHref());
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.
the class ProjectEventHandler method handleUserRoleSetProjectEvent.
/**
* Create a {@link UserRoleSetProjectEvent}. The method must have returned a
* {@link ProjectUserJoin}
*
* @param event
* The {@link MethodEvent} that this event is being launched from
*/
private ProjectEvent handleUserRoleSetProjectEvent(MethodEvent event) {
Object returnValue = event.getReturnValue();
if (!(returnValue instanceof ProjectUserJoin)) {
throw new IllegalArgumentException("Method annotated with @LaunchesProjectEvent(UserRoleSetProjectEvent.class) method must return ProjectUserJoin");
}
ProjectUserJoin join = (ProjectUserJoin) returnValue;
return eventRepository.save(new UserRoleSetProjectEvent(join));
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.
the class ProjectSamplesControllerTest method mockSidebarInfo.
/**
* Mocks the information found within the project sidebar.
*/
private void mockSidebarInfo() {
Project project = getProject();
Collection<Join<Project, User>> ownerList = new ArrayList<>();
ownerList.add(new ProjectUserJoin(project, user, ProjectRole.PROJECT_OWNER));
when(projectService.read(PROJECT_ID)).thenReturn(project);
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin in project irida by phac-nml.
the class ProjectsControllerTest method getProjectsForUser.
private List<Join<Project, User>> getProjectsForUser() {
List<Join<Project, User>> projects = new ArrayList<>();
for (int i = 0; i < 10; i++) {
Project p = new Project("project" + i);
p.setId(1L + i);
projects.add(new ProjectUserJoin(p, user, ProjectRole.PROJECT_USER));
}
return projects;
}
Aggregations