use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class ProjectSamplesControllerTest method testGetAjaxProjectSampleModels.
@SuppressWarnings("unchecked")
@Test
public void testGetAjaxProjectSampleModels() {
Sample sample = TestDataFactory.constructSample();
when(projectService.read(anyLong())).thenReturn(project);
when(sampleService.getSamplesForProject(any(Project.class))).thenReturn(ImmutableList.of(new ProjectSampleJoin(project, sample, true)));
when(sampleService.getFilteredSamplesForProjects(any(List.class), any(List.class), any(String.class), any(String.class), any(String.class), any(Date.class), any(Date.class), any(Integer.class), any(Integer.class), any(Sort.class))).thenReturn(TestDataFactory.getPageOfProjectSampleJoin());
DataTablesParams params = mock(DataTablesParams.class);
when(params.getSort()).thenReturn(new Sort(Direction.ASC, "sample.sampleName"));
DataTablesResponse response = controller.getProjectSamples(1L, params, ImmutableList.of(), ImmutableList.of(), new UISampleFilter(), Locale.US);
List<DataTablesResponseModel> data = response.getData();
assertEquals("Has the correct number of samples", 1, data.size());
DTProjectSamples sampleData = (DTProjectSamples) data.get(0);
assertEquals("Has the correct sample", "Joined Sample", sampleData.getSampleName());
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class SamplesControllerTest method testGetSampleFiles.
@SuppressWarnings("unchecked")
@Test
public void testGetSampleFiles() throws IOException {
ExtendedModelMap model = new ExtendedModelMap();
Long sampleId = 1L;
Sample sample = new Sample();
SequenceFile file = new SequenceFile(Paths.get("/tmp"));
file.setId(2L);
Project project = new Project();
List<SampleSequencingObjectJoin> files = Lists.newArrayList(new SampleSequencingObjectJoin(sample, new SingleEndSequenceFile(file)));
when(sampleService.read(sampleId)).thenReturn(sample);
when(sequencingObjectService.getSequencesForSampleOfType(sample, SingleEndSequenceFile.class)).thenReturn(files);
when(projectService.getProjectsForSample(sample)).thenReturn(Lists.newArrayList(new ProjectSampleJoin(project, sample, true)));
when(updateSamplePermission.isAllowed(any(Authentication.class), eq(sample))).thenReturn(true);
String sampleFiles = controller.getSampleFilesWithoutProject(model, sampleId);
assertEquals(SamplesController.SAMPLE_FILES_PAGE, sampleFiles);
assertTrue((boolean) model.get(SamplesController.MODEL_ATTR_CAN_MANAGE_SAMPLE));
verify(sampleService).read(sampleId);
verify(sequencingObjectService).getSequencesForSampleOfType(sample, SingleEndSequenceFile.class);
verify(sequencingObjectService).getSequencesForSampleOfType(sample, SequenceFilePair.class);
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class ReadSamplePermissionTest method testGrantPermissionWithDomainObject.
@Test
public void testGrantPermissionWithDomainObject() {
String username = "fbristow";
User u = new User();
u.setUsername(username);
Project p = new Project();
Sample s = new Sample();
List<Join<Project, User>> projectUsers = new ArrayList<>();
projectUsers.add(new ProjectUserJoin(p, u, ProjectRole.PROJECT_USER));
List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
projectSampleList.add(new ProjectSampleJoin(p, s, true));
when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
when(sampleRepository.findOne(1L)).thenReturn(s);
when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(true);
Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
assertTrue("permission was not granted.", readSamplePermission.isAllowed(auth, s));
verify(psjRepository).getProjectForSample(s);
// we didn't need to load the domain object for this test.
verifyZeroInteractions(sampleRepository);
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class ReadSamplePermissionTest method testGrantPermission.
@Test
public void testGrantPermission() {
String username = "fbristow";
User u = new User();
u.setUsername(username);
Project p = new Project();
Sample s = new Sample();
List<Join<Project, User>> projectUsers = new ArrayList<>();
projectUsers.add(new ProjectUserJoin(p, u, ProjectRole.PROJECT_USER));
List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
projectSampleList.add(new ProjectSampleJoin(p, s, true));
when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
when(sampleRepository.findOne(1L)).thenReturn(s);
when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(true);
Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
assertTrue("permission was not granted.", readSamplePermission.isAllowed(auth, 1L));
verify(sampleRepository).findOne(1L);
verify(psjRepository).getProjectForSample(s);
verify(readProjectPermission).isAllowed(any(), eq(p));
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class UpdateSamplePermissionTest method testGrantPermissionWithOneProject.
@Test
public void testGrantPermissionWithOneProject() {
final Project p1 = new Project();
final Project p2 = new Project();
final Sample s = new Sample();
when(projectSampleJoinRepository.getProjectForSample(s)).thenReturn(ImmutableList.of(new ProjectSampleJoin(p1, s, true), new ProjectSampleJoin(p2, s, true)));
when(projectOwnerPermission.isAllowed(auth, p1)).thenReturn(false);
when(projectOwnerPermission.isAllowed(auth, p2)).thenReturn(true);
assertTrue("Permission to update sample should be given.", updateSamplePermission.isAllowed(auth, s));
}
Aggregations