Search in sources :

Example 21 with User

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();
}
Also used : TestUser(org.rembx.jeeshop.user.test.TestUser) User(org.rembx.jeeshop.user.model.User) Test(org.junit.jupiter.api.Test)

Example 22 with User

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);
}
Also used : TestUser(org.rembx.jeeshop.user.test.TestUser) User(org.rembx.jeeshop.user.model.User) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 23 with 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);
}
Also used : User(org.rembx.jeeshop.user.model.User) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 24 with User

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);
    }
}
Also used : User(org.rembx.jeeshop.user.model.User)

Example 25 with 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>");
}
Also used : User(org.rembx.jeeshop.user.model.User) Test(org.junit.jupiter.api.Test)

Aggregations

User (org.rembx.jeeshop.user.model.User)28 Test (org.junit.jupiter.api.Test)18 TestUser (org.rembx.jeeshop.user.test.TestUser)18 Date (java.util.Date)9 WebApplicationException (org.rembx.jeeshop.rest.WebApplicationException)9 RolesAllowed (javax.annotation.security.RolesAllowed)4 BasicUserPrincipal (org.apache.http.auth.BasicUserPrincipal)3 Address (org.rembx.jeeshop.user.model.Address)3 UUID (java.util.UUID)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 Order (org.rembx.jeeshop.order.model.Order)2 JPAQueryFactory (com.querydsl.jpa.impl.JPAQueryFactory)1 Configuration (freemarker.template.Configuration)1 Template (freemarker.template.Template)1 StringWriter (java.io.StringWriter)1 Discount (org.rembx.jeeshop.catalog.model.Discount)1 Product (org.rembx.jeeshop.catalog.model.Product)1 SKU (org.rembx.jeeshop.catalog.model.SKU)1 MailTemplate (org.rembx.jeeshop.user.model.MailTemplate)1