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