Search in sources :

Example 1 with RootResource

use of ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource in project irida by phac-nml.

the class GenericControllerTest method testDeleteEntity.

@Test
public void testDeleteEntity() throws InstantiationException, IllegalAccessException {
    ModelMap modelMap = controller.delete(2L);
    RootResource rootResource = (RootResource) modelMap.get(RESTGenericController.RESOURCE_NAME);
    Link l = rootResource.getLink(RESTGenericController.REL_COLLECTION);
    assertNotNull(l);
    assertEquals("http://localhost/api/generic", l.getHref());
}
Also used : RootResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource) ModelMap(org.springframework.ui.ModelMap) Link(org.springframework.hateoas.Link) Test(org.junit.Test)

Example 2 with RootResource

use of ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource in project irida by phac-nml.

the class GenericControllerTest method testUpdate.

@Test
public void testUpdate() throws InstantiationException, IllegalAccessException {
    when(crudService.updateFields(identifier, updatedFields)).thenReturn(entity);
    ModelMap response = controller.update(identifier, updatedFields);
    RootResource r = (RootResource) response.get(RESTGenericController.RESOURCE_NAME);
    assertNotNull(r.getLink(Link.REL_SELF));
    assertNotNull(r.getLink(RESTGenericController.REL_COLLECTION));
}
Also used : RootResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource) ModelMap(org.springframework.ui.ModelMap) Test(org.junit.Test)

Example 3 with RootResource

use of ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource in project irida by phac-nml.

the class RootControllerTest method testGetLinks.

@Test
public void testGetLinks() {
    Map<String, Class<?>> controllers = RESTRootController.PUBLIC_CONTROLLERS;
    ModelMap map = controller.getLinks(new MockHttpServletRequest());
    Object o = map.get(RESTGenericController.RESOURCE_NAME);
    assertNotNull(o);
    assertTrue(o instanceof RootResource);
    RootResource r = (RootResource) o;
    for (Link l : r.getLinks()) {
        if (!l.getRel().equals("self")) {
            assertTrue(controllers.containsKey(l.getRel()));
        }
    }
    assertNotNull(r.getLink("self"));
}
Also used : RootResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ModelMap(org.springframework.ui.ModelMap) Link(org.springframework.hateoas.Link) Test(org.junit.Test)

Example 4 with RootResource

use of ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource in project irida by phac-nml.

the class ProjectUsersControllerTest method testRemoveUserFromProject.

@Test
public void testRemoveUserFromProject() throws ProjectWithoutOwnerException {
    Project p = TestDataFactory.constructProject();
    User u = TestDataFactory.constructUser();
    when(projectService.read(p.getId())).thenReturn(p);
    when(userService.getUserByUsername(u.getUsername())).thenReturn(u);
    ModelMap modelMap = controller.removeUserFromProject(p.getId(), u.getUsername());
    verify(projectService).read(p.getId());
    verify(userService).getUserByUsername(u.getUsername());
    verify(projectService).removeUserFromProject(p, u);
    Object o = modelMap.get(RESTGenericController.RESOURCE_NAME);
    assertTrue(o instanceof RootResource);
    RootResource r = (RootResource) o;
    // confirm that a project link exists
    Link projectLink = r.getLink(RESTProjectsController.REL_PROJECT);
    assertNotNull(projectLink);
    assertEquals("http://localhost/api/projects/" + p.getId(), projectLink.getHref());
    // confirm that a project users link exists
    Link projectUsersLink = r.getLink(RESTProjectUsersController.REL_PROJECT_USERS);
    assertNotNull(projectUsersLink);
    assertEquals("http://localhost/api/projects/" + p.getId() + "/users", projectUsersLink.getHref());
}
Also used : RootResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource) Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ModelMap(org.springframework.ui.ModelMap) Link(org.springframework.hateoas.Link) Test(org.junit.Test)

Example 5 with RootResource

use of ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource in project irida by phac-nml.

the class RESTProjectSamplesControllerTest method testRemoveSampleFromProject.

@Test
public void testRemoveSampleFromProject() {
    Project p = TestDataFactory.constructProject();
    Sample s = TestDataFactory.constructSample();
    when(projectService.read(p.getId())).thenReturn(p);
    when(sampleService.read(s.getId())).thenReturn(s);
    ModelMap modelMap = controller.removeSampleFromProject(p.getId(), s.getId());
    // verify that we actually tried to remove the sample from the project.
    verify(projectService, times(1)).removeSampleFromProject(p, s);
    verify(projectService, times(1)).read(p.getId());
    verify(sampleService, times(1)).read(s.getId());
    // confirm that the response looks right.
    Object o = modelMap.get(RESTGenericController.RESOURCE_NAME);
    assertTrue(o instanceof RootResource);
    RootResource resource = (RootResource) o;
    List<Link> links = resource.getLinks();
    // should be two links in the response, one back to the individual
    // project, the other to the samples collection
    Set<String> rels = Sets.newHashSet(RESTProjectsController.REL_PROJECT, RESTProjectSamplesController.REL_PROJECT_SAMPLES);
    for (Link link : links) {
        assertTrue(rels.contains(link.getRel()));
        assertNotNull(rels.remove(link.getRel()));
    }
    assertTrue(rels.isEmpty());
}
Also used : RootResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) Link(org.springframework.hateoas.Link) Test(org.junit.Test)

Aggregations

RootResource (ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource)12 ModelMap (org.springframework.ui.ModelMap)12 Test (org.junit.Test)6 Link (org.springframework.hateoas.Link)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Project (ca.corefacility.bioinformatics.irida.model.project.Project)4 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)4 User (ca.corefacility.bioinformatics.irida.model.user.User)2 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)1 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)1 ArrayList (java.util.ArrayList)1 MediaType (org.springframework.http.MediaType)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1