Search in sources :

Example 1 with ProjectReferenceFileJoin

use of ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin in project irida by phac-nml.

the class ProjectServiceImplTest method testAddReferenceFileToProject.

@Test
public void testAddReferenceFileToProject() throws IOException {
    Project p = new Project();
    Path createTempFile = Files.createTempFile(null, null);
    ReferenceFile f = new ReferenceFile(createTempFile);
    when(referenceFileRepository.save(f)).thenReturn(f);
    projectService.addReferenceFileToProject(p, f);
    verify(referenceFileRepository).save(f);
    verify(prfjRepository).save(new ProjectReferenceFileJoin(p, f));
}
Also used : Path(java.nio.file.Path) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ReferenceFile(ca.corefacility.bioinformatics.irida.model.project.ReferenceFile) ProjectReferenceFileJoin(ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin) Test(org.junit.Test)

Example 2 with ProjectReferenceFileJoin

use of ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin in project irida by phac-nml.

the class ProjectServiceImpl method addReferenceFileToProject.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#project, 'isProjectOwner')")
public Join<Project, ReferenceFile> addReferenceFileToProject(Project project, ReferenceFile referenceFile) {
    referenceFile = referenceFileRepository.save(referenceFile);
    ProjectReferenceFileJoin j = new ProjectReferenceFileJoin(project, referenceFile);
    return prfjRepository.save(j);
}
Also used : ProjectReferenceFileJoin(ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with ProjectReferenceFileJoin

use of ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin in project irida by phac-nml.

the class ReferenceFileControllerTest method testCreateNewReferenceFile.

@Test
public void testCreateNewReferenceFile() throws IOException {
    Path path = Paths.get(FILE_PATH);
    byte[] origBytes = Files.readAllBytes(path);
    List<MultipartFile> mockMultipartFiles = ImmutableList.of(new MockMultipartFile(FILE_NAME, FILE_NAME, "octet-stream", origBytes));
    // TODO: (14-08-14 - Josh) look at Franklin's TestDataFactory
    Project project = new Project("foo");
    ReferenceFile referenceFile = new TestReferenceFile(path, 2L);
    when(projectService.read(PROJECT_ID)).thenReturn(project);
    when(projectService.addReferenceFileToProject(eq(project), any(ReferenceFile.class))).thenReturn(new ProjectReferenceFileJoin(project, referenceFile));
    MockHttpServletResponse response = new MockHttpServletResponse();
    controller.addReferenceFileToProject(PROJECT_ID, mockMultipartFiles, response, null);
    verify(projectService).read(PROJECT_ID);
    verify(projectService).addReferenceFileToProject(eq(project), any(ReferenceFile.class));
}
Also used : Path(java.nio.file.Path) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) Project(ca.corefacility.bioinformatics.irida.model.project.Project) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) ReferenceFile(ca.corefacility.bioinformatics.irida.model.project.ReferenceFile) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) ProjectReferenceFileJoin(ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin) Test(org.junit.Test)

Aggregations

ProjectReferenceFileJoin (ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin)3 Project (ca.corefacility.bioinformatics.irida.model.project.Project)2 ReferenceFile (ca.corefacility.bioinformatics.irida.model.project.ReferenceFile)2 Path (java.nio.file.Path)2 Test (org.junit.Test)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 Transactional (org.springframework.transaction.annotation.Transactional)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1