Search in sources :

Example 6 with Link

use of com.autentia.tnt.businessobject.Link in project TNTConcept by autentia.

the class LinkBeanTest method shouldFailWhenCheckingWithInactiveUser.

@Test
public void shouldFailWhenCheckingWithInactiveUser() {
    User testUser = new User();
    testUser.setLogin("testUser");
    testUser.setActive(false);
    Link testLink = new Link();
    testLink.setLink("linkTest");
    testLink.setUser("testUser");
    testLink.setInsertDate(new Date());
    doReturn(Arrays.asList(testLink)).when(sutMock).getLinksWithLink("linkTest");
    doReturn(testUser).when(sutMock).getUserByName(testLink.getUser());
    String result = sutMock.checkLinkAndResetPassword(testLink.getLink());
    assertThat(result, equalTo("<p>El enlace no existe o ha caducado</p>"));
}
Also used : User(com.autentia.tnt.businessobject.User) Link(com.autentia.tnt.businessobject.Link) Date(java.util.Date) Test(org.junit.Test)

Example 7 with Link

use of com.autentia.tnt.businessobject.Link in project TNTConcept by autentia.

the class LinkBeanTest method shouldProcessPasswordResetRequest.

@Test
public void shouldProcessPasswordResetRequest() {
    User testUser = new User();
    testUser.setLogin("testName");
    testUser.setActive(true);
    testUser.setEmail("test@mail.com");
    sutMock.setName("testName");
    Link testLink = new Link();
    testLink.setLink("randomLink");
    doReturn(testUser).when(sutMock).getUserByName("testName");
    doReturn(externalContext).when(sutMock).getFacesExternalContext();
    doReturn(testLink).when(sutMock).generateLink("testName");
    String result = sutMock.passwordResetRequest();
    verify(sutMock).sendMail(testLink, "test@mail.com");
    assertThat(result, equalTo("emailSent"));
}
Also used : User(com.autentia.tnt.businessobject.User) Link(com.autentia.tnt.businessobject.Link) Test(org.junit.Test)

Example 8 with Link

use of com.autentia.tnt.businessobject.Link in project TNTConcept by autentia.

the class LinkBeanTest method shouldFailWhenCheckingExpiredLink.

@Test
public void shouldFailWhenCheckingExpiredLink() {
    Link testLink = new Link();
    testLink.setLink("linkTest");
    testLink.setUser("testUser");
    Date yesterday = new Date();
    Calendar cal = Calendar.getInstance();
    cal.setTime(yesterday);
    cal.add(Calendar.DATE, -1);
    yesterday = cal.getTime();
    testLink.setInsertDate(yesterday);
    doReturn(Arrays.asList(testLink)).when(sutMock).getLinksWithLink("linkTest");
    String result = sutMock.checkLinkAndResetPassword(testLink.getLink());
    assertThat(result, equalTo("<p>El enlace no existe o ha caducado</p>"));
}
Also used : Calendar(java.util.Calendar) Link(com.autentia.tnt.businessobject.Link) Date(java.util.Date) Test(org.junit.Test)

Example 9 with Link

use of com.autentia.tnt.businessobject.Link in project TNTConcept by autentia.

the class LinkBeanTest method shouldCheckLinkAndCallResetPassword.

@Test
public void shouldCheckLinkAndCallResetPassword() {
    User testUser = new User();
    testUser.setLogin("testUser");
    testUser.setActive(true);
    Link testLink = new Link();
    testLink.setLink("linkTest");
    testLink.setUser("testUser");
    testLink.setInsertDate(new Date());
    doReturn(Arrays.asList(testLink)).when(sutMock).getLinksWithLink("linkTest");
    doReturn(testUser).when(sutMock).getUserByName(testLink.getUser());
    doReturn("changedPassword").when(sutMock).resetPassword(testUser);
    String result = sutMock.checkLinkAndResetPassword(testLink.getLink());
    assertThat(result, equalTo("Tu nueva contraseña es: <b>changedPassword</b></br> <p>Se te pedirá que la modifiques al entrar por primera vez.</p>"));
}
Also used : User(com.autentia.tnt.businessobject.User) Link(com.autentia.tnt.businessobject.Link) Date(java.util.Date) Test(org.junit.Test)

Example 10 with Link

use of com.autentia.tnt.businessobject.Link in project TNTConcept by autentia.

the class LinkBeanTest method shouldSendMail.

@Test
public void shouldSendMail() throws MessagingException {
    Link link = new Link();
    link.setLink("dgfjhsadgflkjasghajksdhfk");
    String mailAddress = "test@mail.com";
    sutMock.sendMail(link, mailAddress);
    verify(mailService).send(mailAddress, "[RESETEO DE CONTRASEÑA] Email de verificación", "Haz click en el siguiente link para verificar que eres tú si quieres cambiar la contraseña: http://localhost:8080/tntconcept/linkEmailVerification.jsf?link=dgfjhsadgflkjasghajksdhfk");
}
Also used : Link(com.autentia.tnt.businessobject.Link) Test(org.junit.Test)

Aggregations

Link (com.autentia.tnt.businessobject.Link)12 Test (org.junit.Test)9 User (com.autentia.tnt.businessobject.User)6 Date (java.util.Date)6 Calendar (java.util.Calendar)2 DataNotFoundException (com.autentia.tnt.dao.DataNotFoundException)1 Random (java.util.Random)1