use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class UsersCT method modifyUser_ShouldModifyUser.
@Test
public void modifyUser_ShouldModifyUser() {
User detachedUserToModify = new User("test2@test.com", "test", "John", "Doe", "+33616161616", null, new Date(), "fr_FR", null);
detachedUserToModify.setId(testUser.firstUser().getId());
service.modify(sessionContextMock, detachedUserToModify);
}
use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class UsersCT method delete_shouldRemove.
@Test
public void delete_shouldRemove() {
entityManager.getTransaction().begin();
User user = new User("test4@test.com", "test", "John", "Doe", "+33616161616", null, new Date(), "fr_FR", null);
user.setGender("M.");
entityManager.persist(user);
entityManager.getTransaction().commit();
entityManager.getTransaction().begin();
service.delete(user.getId());
entityManager.getTransaction().commit();
assertThat(entityManager.find(User.class, user.getId())).isNull();
}
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(@QueryParam("locale") String locale) {
User currentUser = userFinder.findByLogin(sessionContext.getCallerPrincipal().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(Order order, String userLogin) {
User user;
if (sessionContext.isCallerInRole(USER)) {
user = userFinder.findByLogin(sessionContext.getCallerPrincipal().getName());
order.setUser(user);
}
if (sessionContext.isCallerInRole(ADMIN)) {
user = userFinder.findByLogin(userLogin);
order.setUser(user);
}
}
use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class OrdersCT method find_whenClientHasUserRoleAndOrderBelongsToAnotherUser_ShouldThrowException.
@Test
public void find_whenClientHasUserRoleAndOrderBelongsToAnotherUser_ShouldThrowException() throws Exception {
entityManager.getTransaction().begin();
User user = new User("777@test.com", "test", "M.", "John", "Doe", "+33616161616", null, null, "fr_FR", null);
entityManager.persist(user);
entityManager.getTransaction().commit();
when(sessionContextMock.isUserInRole(JeeshopRoles.USER)).thenReturn(true);
when(sessionContextMock.isUserInRole(JeeshopRoles.ADMIN)).thenReturn(false);
when(sessionContextMock.getUserPrincipal()).thenReturn(new BasicUserPrincipal("777@test.com"));
try {
service.find(sessionContextMock, 1L, null);
fail("should have thrown ex");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.UNAUTHORIZED);
} finally {
entityManager.getTransaction().begin();
entityManager.remove(user);
entityManager.persist(user);
}
}
Aggregations