Search in sources :

Example 36 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project ORCID-Source by ORCID.

the class RegistrationControllerTest method verifyEmail_InvalidEmailTest.

@Test
public void verifyEmail_InvalidEmailTest() throws UnsupportedEncodingException {
    String orcid = "0000-0000-0000-0000";
    String email = "user_1@test.orcid.org";
    SecurityContextTestUtils.setupSecurityContextForWebUser(orcid, email);
    String encodedEmail = new String(Base64.encodeBase64(email.getBytes()));
    when(encryptionManagerMock.decryptForExternalUse(Mockito.anyString())).thenReturn(email);
    // Email doesn't exists
    when(emailManagerReadOnlyMock.emailExists(email)).thenReturn(false);
    when(emailManagerReadOnlyMock.findOrcidIdByEmail(email)).thenReturn(orcid);
    when(emailManager.verifyEmail(email, orcid)).thenReturn(true);
    when(emailManagerReadOnlyMock.isPrimaryEmail(orcid, email)).thenReturn(true);
    when(emailManagerReadOnlyMock.isPrimaryEmailVerified(orcid)).thenReturn(true);
    RedirectAttributesModelMap ra = new RedirectAttributesModelMap();
    ModelAndView mav = registrationController.verifyEmail(servletRequest, encodedEmail, ra);
    assertNotNull(mav);
    assertEquals("redirect:/my-orcid", mav.getViewName());
    assertFalse(ra.getFlashAttributes().containsKey("emailVerified"));
    assertFalse(ra.getFlashAttributes().containsKey("primaryEmailUnverified"));
    verify(emailManager, times(0)).verifyEmail(Mockito.anyString(), Mockito.anyString());
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 37 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project irida by phac-nml.

the class SamplesControllerTest method testRemoveFileFromSample.

@Test
public void testRemoveFileFromSample() {
    Long sampleId = 1L;
    Long fileId = 2L;
    Sample sample = new Sample();
    SequencingObject file = new SingleEndSequenceFile(new SequenceFile(Paths.get("/tmp")));
    when(sampleService.read(sampleId)).thenReturn(sample);
    when(sequencingObjectService.readSequencingObjectForSample(sample, fileId)).thenReturn(file);
    RedirectAttributesModelMap attributes = new RedirectAttributesModelMap();
    HttpServletRequest request = new MockHttpServletRequest();
    controller.removeSequencingObjectFromSample(attributes, sampleId, fileId, request, Locale.US);
    verify(sampleService).removeSequencingObjectFromSample(sample, file);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Example 38 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project irida by phac-nml.

the class SamplesControllerTest method testRemoveGenomeAssemblyFromSample.

@Test
public void testRemoveGenomeAssemblyFromSample() {
    Long sampleId = 1L;
    Long assemblyId = 2L;
    GenomeAssembly genomeAssembly = TestDataFactory.constructGenomeAssembly();
    Sample sample = new Sample();
    when(sampleService.read(sampleId)).thenReturn(sample);
    when(sampleService.getGenomeAssemblyForSample(sample, assemblyId)).thenReturn(genomeAssembly);
    when(updateSamplePermission.isAllowed(any(Authentication.class), eq(sample))).thenReturn(true);
    RedirectAttributesModelMap attributes = new RedirectAttributesModelMap();
    HttpServletRequest request = new MockHttpServletRequest();
    controller.removeGenomeAssemblyFromSample(attributes, sampleId, assemblyId, request, Locale.US);
    verify(sampleService).removeGenomeAssemblyFromSample(sample, assemblyId);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Authentication(org.springframework.security.core.Authentication) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) GenomeAssembly(ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly) Test(org.junit.Test)

Example 39 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project ORCID-Source by ORCID.

the class RegistrationControllerTest method verifyEmail_NotVerifiedTest.

@Test
public void verifyEmail_NotVerifiedTest() throws UnsupportedEncodingException {
    String orcid = "0000-0000-0000-0000";
    String email = "user_1@test.orcid.org";
    SecurityContextTestUtils.setupSecurityContextForWebUser(orcid, email);
    String encodedEmail = new String(Base64.encodeBase64(email.getBytes()));
    when(encryptionManagerMock.decryptForExternalUse(Mockito.anyString())).thenReturn(email);
    when(emailManagerReadOnlyMock.emailExists(email)).thenReturn(true);
    when(emailManagerReadOnlyMock.findOrcidIdByEmail(email)).thenReturn(orcid);
    // For some reason the email wasn't verified
    when(emailManager.verifyEmail(email, orcid)).thenReturn(false);
    when(emailManagerReadOnlyMock.isPrimaryEmail(orcid, email)).thenReturn(true);
    when(emailManagerReadOnlyMock.isPrimaryEmailVerified(orcid)).thenReturn(true);
    RedirectAttributesModelMap ra = new RedirectAttributesModelMap();
    ModelAndView mav = registrationController.verifyEmail(servletRequest, encodedEmail, ra);
    assertNotNull(mav);
    assertEquals("redirect:/my-orcid", mav.getViewName());
    assertTrue(ra.getFlashAttributes().containsKey("emailVerified"));
    assertFalse((Boolean) ra.getFlashAttributes().get("emailVerified"));
    assertFalse(ra.getFlashAttributes().containsKey("primaryEmailUnverified"));
    verify(emailManager, times(1)).verifyEmail(Mockito.anyString(), Mockito.anyString());
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 40 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project ORCID-Source by ORCID.

the class RegistrationControllerTest method verifyEmail_UnableToDecryptEmailTest.

@Test
public void verifyEmail_UnableToDecryptEmailTest() throws UnsupportedEncodingException {
    String orcid = "0000-0000-0000-0000";
    String email = "user_1@test.orcid.org";
    SecurityContextTestUtils.setupSecurityContextForWebUser(orcid, email);
    String encodedEmail = new String(Base64.encodeBase64(email.getBytes()));
    when(encryptionManagerMock.decryptForExternalUse(Mockito.anyString())).thenThrow(new EncryptionOperationNotPossibleException());
    RedirectAttributesModelMap ra = new RedirectAttributesModelMap();
    ModelAndView mav = registrationController.verifyEmail(servletRequest, encodedEmail, ra);
    assertNotNull(mav);
    assertEquals("redirect:/my-orcid", mav.getViewName());
    assertTrue(ra.getFlashAttributes().containsKey("invalidVerifyUrl"));
    assertTrue((Boolean) ra.getFlashAttributes().get("invalidVerifyUrl"));
    verify(emailManager, times(0)).verifyEmail(Mockito.anyString(), Mockito.anyString());
}
Also used : EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

RedirectAttributesModelMap (org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap)64 ModelMap (org.springframework.ui.ModelMap)44 Test (org.junit.jupiter.api.Test)33 ModelAndView (org.springframework.web.servlet.ModelAndView)25 Test (org.junit.Test)24 RedirectView (org.springframework.web.servlet.view.RedirectView)10 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)9 BindingResult (org.springframework.validation.BindingResult)6 DBUnitTest (org.orcid.test.DBUnitTest)5 MethodParameter (org.springframework.core.MethodParameter)5 DataBinder (org.springframework.validation.DataBinder)5 TodoDTO (net.petrikainulainen.spring.testmvc.todo.dto.TodoDTO)4 AbstractNGrinderTransactionalTest (org.ngrinder.AbstractNGrinderTransactionalTest)4 FileEntry (org.ngrinder.script.model.FileEntry)3 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)2 List (java.util.List)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 TodoNotFoundException (net.petrikainulainen.spring.testmvc.todo.exception.TodoNotFoundException)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 Model (org.springframework.ui.Model)2