use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class CartControllerTest method testAddProject.
@Test
public void testAddProject() {
Map<String, Object> addProject = controller.addProject(projectId);
assertTrue((boolean) addProject.get("success"));
List<Join<Project, Sample>> joins = new ArrayList<>();
samples.forEach((s) -> {
joins.add(new ProjectSampleJoin(project, s, true));
});
when(sampleService.getSamplesForProject(project)).thenReturn(joins);
verify(projectService).read(projectId);
verify(sampleService).getSamplesForProject(project);
Map<Project, Set<Sample>> selected = controller.getSelected();
assertEquals(1, selected.keySet().size());
Project projectKey = selected.keySet().iterator().next();
assertEquals(project, projectKey);
for (Sample s : selected.get(projectKey)) {
assertTrue(sampleIds.contains(s.getId()));
}
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class CartControllerTest method testData.
private void testData() {
projectId = 1L;
sampleIds = Sets.newHashSet(2L, 3L);
project = new Project("project");
project.setId(projectId);
samples = new HashSet<>();
when(projectService.read(projectId)).thenReturn(project);
for (Long id : sampleIds) {
Sample sample = new Sample("sample" + id);
sample.setId(id);
samples.add(sample);
when(sampleService.getSampleForProject(project, id)).thenReturn(new ProjectSampleJoin(project, sample, true));
}
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class ReadSequencingObjectPermissionTest method testRejectPermission.
@Test
public void testRejectPermission() {
Project p = new Project();
Sample s = new Sample();
List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
projectSampleList.add(new ProjectSampleJoin(p, s, true));
SingleEndSequenceFile sf = new SingleEndSequenceFile(null);
SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(s, sf);
when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
when(sequencingObjectRepository.findOne(1L)).thenReturn(sf);
when(ssoRepository.getSampleForSequencingObject(sf)).thenReturn(join);
when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(false);
Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
assertFalse("permission was granted.", permission.isAllowed(auth, 1L));
verify(sequencingObjectRepository).findOne(1L);
verify(psjRepository).getProjectForSample(s);
verify(ssoRepository).getSampleForSequencingObject(sf);
verify(readProjectPermission).isAllowed(any(), eq(p));
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class ReadSequencingObjectPermissionTest method testGrantPermission.
@Test
public void testGrantPermission() {
Project p = new Project();
Sample s = new Sample();
List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
projectSampleList.add(new ProjectSampleJoin(p, s, true));
SingleEndSequenceFile sf = new SingleEndSequenceFile(null);
SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(s, sf);
when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
when(sequencingObjectRepository.findOne(1L)).thenReturn(sf);
when(ssoRepository.getSampleForSequencingObject(sf)).thenReturn(join);
when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(true);
Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
assertTrue("permission was not granted.", permission.isAllowed(auth, 1L));
verify(sequencingObjectRepository).findOne(1L);
verify(psjRepository).getProjectForSample(s);
verify(ssoRepository).getSampleForSequencingObject(sf);
verify(readProjectPermission).isAllowed(any(), eq(p));
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class ReadSamplePermissionTest method testRejectPermission.
@Test
public void testRejectPermission() {
String username = "fbristow";
User u = new User();
u.setUsername(username);
Project p = new Project();
Sample s = new Sample();
List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
projectSampleList.add(new ProjectSampleJoin(p, s, true));
List<Join<Project, User>> projectUsers = new ArrayList<>();
projectUsers.add(new ProjectUserJoin(p, new User(), ProjectRole.PROJECT_USER));
when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
when(sampleRepository.findOne(1L)).thenReturn(s);
when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(false);
Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
assertFalse("permission was granted.", readSamplePermission.isAllowed(auth, 1L));
verify(sampleRepository).findOne(1L);
verify(psjRepository).getProjectForSample(s);
}
Aggregations