Search in sources :

Example 6 with ProjectUserJoin

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);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test)

Example 7 with ProjectUserJoin

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());
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ModelMap(org.springframework.ui.ModelMap) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole) Project(ca.corefacility.bioinformatics.irida.model.project.Project) LabelledRelationshipResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.LabelledRelationshipResource) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Link(org.springframework.hateoas.Link) Test(org.junit.Test)

Example 8 with ProjectUserJoin

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));
}
Also used : UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)

Example 9 with ProjectUserJoin

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);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)

Example 10 with ProjectUserJoin

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;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)

Aggregations

ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)34 Project (ca.corefacility.bioinformatics.irida.model.project.Project)26 User (ca.corefacility.bioinformatics.irida.model.user.User)23 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)20 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)12 ProjectRole (ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)8 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)7 UserGroupProjectJoin (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin)7 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)6 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)6 Authentication (org.springframework.security.core.Authentication)6 ProjectEvent (ca.corefacility.bioinformatics.irida.model.event.ProjectEvent)4 UserRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent)4 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)4 ProjectWithoutOwnerException (ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException)3 ProjectReferenceFileJoin (ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin)3 DTUser (ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUser)3 List (java.util.List)3 Locale (java.util.Locale)3