Search in sources :

Example 16 with BasicUserPrincipal

use of org.apache.http.auth.BasicUserPrincipal in project jeeshop by remibantos.

the class OrdersCT method findAll_whenClientHasUserRoleAndByStatusCREATED_shouldReturnOrdersWithThisStatus.

@Test
public void findAll_whenClientHasUserRoleAndByStatusCREATED_shouldReturnOrdersWithThisStatus() {
    when(sessionContextMock.isUserInRole(JeeshopRoles.USER)).thenReturn(true);
    when(sessionContextMock.isUserInRole(JeeshopRoles.ADMIN)).thenReturn(false);
    when(sessionContextMock.getUserPrincipal()).thenReturn(new BasicUserPrincipal(testOrder.firstOrdersUser().getLogin()));
    List<Order> orders = service.findAll(sessionContextMock, null, 0, 1, null, null, OrderStatus.CREATED, null, null);
    assertThat(orders).isNotEmpty();
    assertThat(orders).containsExactly(testOrder.secondOrder());
}
Also used : Order(org.rembx.jeeshop.order.model.Order) TestOrder(org.rembx.jeeshop.order.test.TestOrder) BasicUserPrincipal(org.apache.http.auth.BasicUserPrincipal) Test(org.junit.jupiter.api.Test)

Example 17 with BasicUserPrincipal

use of org.apache.http.auth.BasicUserPrincipal in project jeeshop by remibantos.

the class OrdersCT method create_shouldPersistOrderWithOrderItems_computePrice_andProcessPayment.

@Test
public void create_shouldPersistOrderWithOrderItems_computePrice_andProcessPayment() throws Exception {
    Set<OrderItem> orderItems = new HashSet<>();
    orderItems.add(new OrderItem(1L, 1L, 2));
    orderItems.add(new OrderItem(2L, 2L, 3));
    when(sessionContextMock.isUserInRole(JeeshopRoles.USER)).thenReturn(true);
    when(sessionContextMock.getUserPrincipal()).thenReturn(new BasicUserPrincipal(testOrder.firstOrdersUser().getLogin()));
    entityManager.getTransaction().begin();
    Order order = new Order(orderItems, new Address("7 Rue des arbres", "Paris", "92800", "John", "Doe", "M.", null, "USA"), new Address("7 Rue des arbres", "Paris", "92800", "John", "Doe", "M.", null, "USA"));
    order.setOrderDiscounts(new HashSet<>());
    service.create(sessionContextMock, order, null);
    entityManager.getTransaction().commit();
    verify(sessionContextMock).isUserInRole(JeeshopRoles.USER);
    verify(priceEngineMock).computePrice(order);
    final Order persistedOrder = entityManager.find(Order.class, order.getId());
    assertThat(persistedOrder).isNotNull();
    assertThat(persistedOrder.getStatus()).isEqualTo(PAYMENT_VALIDATED);
    assertThat(persistedOrder.getUser()).isEqualTo(testOrder.firstOrdersUser());
    assertThat(persistedOrder.getItems()).hasSize(2);
    entityManager.getTransaction().begin();
    entityManager.remove(order);
    entityManager.getTransaction().commit();
}
Also used : Order(org.rembx.jeeshop.order.model.Order) TestOrder(org.rembx.jeeshop.order.test.TestOrder) BasicUserPrincipal(org.apache.http.auth.BasicUserPrincipal) Address(org.rembx.jeeshop.user.model.Address) OrderItem(org.rembx.jeeshop.order.model.OrderItem) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 18 with BasicUserPrincipal

use of org.apache.http.auth.BasicUserPrincipal in project jeeshop by remibantos.

the class UsersCT method resetPassword_shouldReturnUnauthorizedResponse_whenAuthenticatedUserDoesNotMatchLogin.

@Test
public void resetPassword_shouldReturnUnauthorizedResponse_whenAuthenticatedUserDoesNotMatchLogin() throws Exception {
    try {
        when(sessionContextMock.isUserInRole(JeeshopRoles.USER)).thenReturn(true);
        when(sessionContextMock.getUserPrincipal()).thenReturn(new BasicUserPrincipal(testUser.firstUser().getLogin()));
        service.resetPassword(sessionContextMock, "not_matching_login", null, null);
        fail("should have thrown ex");
    } catch (WebApplicationException e) {
        assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.UNAUTHORIZED);
    }
}
Also used : BasicUserPrincipal(org.apache.http.auth.BasicUserPrincipal) WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) Test(org.junit.jupiter.api.Test)

Example 19 with BasicUserPrincipal

use of org.apache.http.auth.BasicUserPrincipal in project jeeshop by remibantos.

the class UsersCT method findCurrentUser_shouldReturnCurrentAuthenticatedUser.

@Test
public void findCurrentUser_shouldReturnCurrentAuthenticatedUser() throws Exception {
    when(sessionContextMock.getUserPrincipal()).thenReturn(new BasicUserPrincipal(testUser.firstUser().getLogin()));
    assertThat(service.findCurrentUser(sessionContextMock)).isEqualTo(testUser.firstUser());
}
Also used : BasicUserPrincipal(org.apache.http.auth.BasicUserPrincipal) Test(org.junit.jupiter.api.Test)

Example 20 with BasicUserPrincipal

use of org.apache.http.auth.BasicUserPrincipal in project jeeshop by remibantos.

the class CatalogItemCRUDTester method setSAnotherStoreAdminUser.

public void setSAnotherStoreAdminUser() {
    when(securityContext.isUserInRole(JeeshopRoles.ADMIN)).thenReturn(false);
    when(securityContext.isUserInRole(JeeshopRoles.STORE_ADMIN)).thenReturn(true);
    when(securityContext.getUserPrincipal()).thenReturn(new BasicUserPrincipal("test@test.org"));
}
Also used : BasicUserPrincipal(org.apache.http.auth.BasicUserPrincipal)

Aggregations

BasicUserPrincipal (org.apache.http.auth.BasicUserPrincipal)21 Test (org.junit.jupiter.api.Test)12 Order (org.rembx.jeeshop.order.model.Order)6 TestOrder (org.rembx.jeeshop.order.test.TestOrder)6 Principal (java.security.Principal)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 WebApplicationException (org.rembx.jeeshop.rest.WebApplicationException)3 User (org.rembx.jeeshop.user.model.User)3 TestUser (org.rembx.jeeshop.user.test.TestUser)3 HttpServletRequestWrapper (javax.servlet.http.HttpServletRequestWrapper)2 Address (org.rembx.jeeshop.user.model.Address)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 PublicKey (java.security.PublicKey)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Callback (javax.security.auth.callback.Callback)1