use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class UsersCT method sendResetPasswordMail_shouldGenerateActionTokenAndSendResetPasswordMail.
@Test
public void sendResetPasswordMail_shouldGenerateActionTokenAndSendResetPasswordMail() throws Exception {
entityManager.getTransaction().begin();
service.sendResetPasswordMail(testUser.firstUser().getLogin());
entityManager.getTransaction().commit();
verify(mailerMock).sendMail(testMailTemplate.resetPasswordMailTemplate().getSubject(), testUser.firstUser().getLogin(), "<html><body>Here is the link to reset your password</body></html>");
User persistedUser = entityManager.find(User.class, testUser.firstUser().getId());
assertThat(persistedUser).isNotNull();
entityManager.getTransaction().begin();
persistedUser.setActionToken(null);
entityManager.getTransaction().commit();
}
use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class UsersCT method create_shouldOnlyPersistUserWhenOperationIsTriggeredByAdminUser.
@Test
public void create_shouldOnlyPersistUserWhenOperationIsTriggeredByAdminUser() throws Exception {
User user = new User("register2@test.com", "test", "John", "Doe", "+33616161616", null, new Date(), "fr_FR", null);
user.setGender("M.");
when(sessionContextMock.isUserInRole(JeeshopRoles.ADMIN)).thenReturn(true);
entityManager.getTransaction().begin();
service.create(sessionContextMock, user);
entityManager.getTransaction().commit();
verify(sessionContextMock).isUserInRole(JeeshopRoles.ADMIN);
assertThat(entityManager.find(User.class, user.getId())).isNotNull();
removeTestUser(user);
}
use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class EligibleDiscounts method findEligible.
@GET
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed(JeeshopRoles.USER)
public List<Discount> findEligible(@Context SecurityContext securityContext, @QueryParam("locale") String locale) {
User currentUser = userFinder.findByLogin(securityContext.getUserPrincipal().getName());
Long completedOrders = orderFinder.countUserCompletedOrders(currentUser);
return discountFinder.findEligibleOrderDiscounts(locale, completedOrders);
}
use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class Orders method assignOrderToUser.
private void assignOrderToUser(SecurityContext securityContext, Order order, String userLogin) {
User user;
if (securityContext.isUserInRole(USER)) {
user = userFinder.findByLogin(securityContext.getUserPrincipal().getName());
order.setUser(user);
}
if (securityContext.isUserInRole(ADMIN)) {
user = userFinder.findByLogin(userLogin);
order.setUser(user);
}
}
use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class MailTemplatesCT method sendTestEmail_shouldSendMailFromFTLAndPropertiesToRecipient.
@Test
public void sendTestEmail_shouldSendMailFromFTLAndPropertiesToRecipient() throws Exception {
String recipient = "toto@toto.com";
User user = new User();
user.setGender("Miss");
user.setFirstname("Jane");
user.setLastname("Doe");
service.sendTestEmail(user, Mails.userRegistration.name(), "fr_FR", recipient);
verify(mailerMock).sendMail(testMailTemplate.userRegistrationMailTemplate().getSubject(), recipient, "<html><body>Welcome Miss Jane Doe</body></html>");
}
Aggregations