Search in sources :

Example 11 with EntityNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException in project irida by phac-nml.

the class SequencingRunServiceImplIT method testAddDetachedRunToSequenceFile.

/**
 * This test simulates a bug that happens from the REST API when uploading
 * sequence files to samples, where a new sequence file is created, then
 * detached from a transaction.
 *
 * @throws IOException
 * @throws InterruptedException
 */
@Test
@WithMockUser(username = "fbristow", password = "password1", roles = "ADMIN")
public void testAddDetachedRunToSequenceFile() throws IOException, InterruptedException {
    final String SEQUENCE = "ACGTACGTN";
    final byte[] FASTQ_FILE_CONTENTS = ("@testread\n" + SEQUENCE + "\n+\n?????????\n@testread2\n" + SEQUENCE + "\n+\n?????????").getBytes();
    Path p = Files.createTempFile(null, null);
    Files.write(p, FASTQ_FILE_CONTENTS);
    SequenceFile sf = new SequenceFile();
    sf.setFile(p);
    SingleEndSequenceFile so = new SingleEndSequenceFile(sf);
    Sample sample = sampleService.read(1L);
    SequencingRun run = miseqRunService.read(2L);
    objectService.createSequencingObjectInSample(so, sample);
    miseqRunService.addSequencingObjectToSequencingRun(run, so);
    AnalysisFastQC analysis = null;
    do {
        try {
            analysis = analysisService.getFastQCAnalysisForSequenceFile(so, sf.getId());
        } catch (final EntityNotFoundException e) {
            logger.info("Fastqc still isn't finished, sleeping a bit.");
            Thread.sleep(1000);
        }
    } while (analysis == null);
    assertNotNull("FastQC analysis should have been created for sequence file.", analysis);
}
Also used : Path(java.nio.file.Path) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 12 with EntityNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException in project irida by phac-nml.

the class SampleServiceImplIT method testRemoveGenomeAssemblyFromSampleSuccess.

@Test
@WithMockUser(username = "fbristow", roles = "USER")
public void testRemoveGenomeAssemblyFromSampleSuccess() {
    Sample s = sampleService.read(1L);
    assertNotNull(sampleService.getGenomeAssemblyForSample(s, 1L));
    sampleService.removeGenomeAssemblyFromSample(s, 1L);
    try {
        sampleService.getGenomeAssemblyForSample(s, 1L);
    } catch (EntityNotFoundException e) {
        return;
    }
    fail("Did not catch " + EntityNotFoundException.class);
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 13 with EntityNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException in project irida by phac-nml.

the class RemoteAPIControllerTest method testReadNoToken.

@Test
public void testReadNoToken() {
    Long apiId = 1L;
    ExtendedModelMap model = new ExtendedModelMap();
    RemoteAPI client = new RemoteAPI("name", "http://uri", "a description", "id", "secret");
    when(remoteAPIService.read(apiId)).thenReturn(client);
    when(tokenService.getToken(client)).thenThrow(new EntityNotFoundException("no token"));
    remoteAPIController.read(apiId, model, locale);
    verify(remoteAPIService).read(apiId);
    verify(tokenService).getToken(client);
    assertTrue(model.containsAttribute("remoteApi"));
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) Test(org.junit.Test)

Example 14 with EntityNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException in project irida by phac-nml.

the class PasswordResetControllerTest method testSubmitEmailNotExists.

@Test
public void testSubmitEmailNotExists() {
    String email = "tom@nowhere.com";
    ExtendedModelMap model = new ExtendedModelMap();
    when(userService.loadUserByEmail(email)).thenThrow(new EntityNotFoundException("email doesn't exist"));
    String submitEmail = controller.submitEmail(email, model);
    assertEquals(PasswordResetController.CREATE_RESET_PAGE, submitEmail);
    assertTrue(model.containsKey("email"));
    assertTrue(model.containsKey("emailError"));
    verify(userService).loadUserByEmail(email);
    verifyZeroInteractions(emailController);
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Matchers.anyString(org.mockito.Matchers.anyString) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) Test(org.junit.Test)

Example 15 with EntityNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException in project irida by phac-nml.

the class AnnouncementServiceImpl method markAnnouncementAsUnreadByUser.

/**
 *  {@inheritDoc}
 */
@Override
@Transactional
@PreAuthorize("hasAnyRole('ROLE_USER')")
public void markAnnouncementAsUnreadByUser(Announcement announcement, User user) throws EntityNotFoundException {
    try {
        final AnnouncementUserJoin join = announcementUserJoinRepository.getAnnouncementUserJoin(announcement, user);
        Long id = join.getId();
        announcementUserJoinRepository.delete(id);
    } catch (NullPointerException e) {
        throw new EntityNotFoundException("The user [" + user.getId() + "] has not yet read announcement [" + announcement.getId() + "]: cannot mark as unread.");
    }
}
Also used : AnnouncementUserJoin(ca.corefacility.bioinformatics.irida.model.announcements.AnnouncementUserJoin) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(javax.transaction.Transactional)

Aggregations

EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)45 Test (org.junit.Test)12 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)8 Project (ca.corefacility.bioinformatics.irida.model.project.Project)7 Transactional (org.springframework.transaction.annotation.Transactional)7 User (ca.corefacility.bioinformatics.irida.model.user.User)6 RemoteAPIToken (ca.corefacility.bioinformatics.irida.model.RemoteAPIToken)5 AnalysisType (ca.corefacility.bioinformatics.irida.model.enums.AnalysisType)5 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)5 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 IridaWorkflowNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException)4 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)4 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)4 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)4 Analysis (ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis)4 Path (java.nio.file.Path)4