Search in sources :

Example 21 with WebApplicationException

use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.

the class UsersCT method resetPassword_shouldReturnUnauthorizedResponse_whenAuthenticatedUserDoesNotMatchLogin.

@Test
public void resetPassword_shouldReturnUnauthorizedResponse_whenAuthenticatedUserDoesNotMatchLogin() throws Exception {
    try {
        when(sessionContextMock.isCallerInRole(JeeshopRoles.USER)).thenReturn(true);
        when(sessionContextMock.getCallerPrincipal()).thenReturn(new PrincipalImpl(testUser.firstUser().getLogin()));
        service.resetPassword("not_matching_login", null, null);
        fail("should have thrown ex");
    } catch (WebApplicationException e) {
        assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.UNAUTHORIZED);
    }
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) PrincipalImpl(sun.security.acl.PrincipalImpl) Test(org.junit.Test)

Example 22 with WebApplicationException

use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.

the class UsersCT method create_shouldThrowBadRequestExWhenUserHasAnId.

@Test
public void create_shouldThrowBadRequestExWhenUserHasAnId() throws Exception {
    User user = new User();
    user.setId(777L);
    try {
        service.create(user);
        fail("should have thrown ex");
    } catch (WebApplicationException e) {
        assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.BAD_REQUEST);
    }
}
Also used : TestUser(org.rembx.jeeshop.user.test.TestUser) User(org.rembx.jeeshop.user.model.User) WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) Test(org.junit.Test)

Example 23 with WebApplicationException

use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.

the class UsersCT method modifyUnknownUser_ShouldThrowNotFoundException.

@Test
public void modifyUnknownUser_ShouldThrowNotFoundException() {
    User detachedUser = new User("test3@test.com", "test", "John", "Doe", "+33616161616", null, new Date(), "fr_FR", null);
    detachedUser.setId(9999L);
    try {
        service.modify(detachedUser);
        fail("should have thrown ex");
    } catch (WebApplicationException e) {
        assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.NOT_FOUND);
    }
}
Also used : TestUser(org.rembx.jeeshop.user.test.TestUser) User(org.rembx.jeeshop.user.model.User) WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) Date(java.util.Date) Test(org.junit.Test)

Example 24 with WebApplicationException

use of org.rembx.jeeshop.rest.WebApplicationException in project jeeshop by remibantos.

the class UsersCT method create_shouldThrowBadRequestExceptionExWhenUsersCountryIsNotAvailable.

@Test
public void create_shouldThrowBadRequestExceptionExWhenUsersCountryIsNotAvailable() throws Exception {
    User user = new User();
    user.setLogin("toto@toto.com");
    Address address = new Address();
    address.setCountryIso3Code("ZZZ");
    user.setAddress(address);
    try {
        service.create(user);
        fail("should have thrown ex");
    } catch (WebApplicationException e) {
        assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.BAD_REQUEST);
    }
}
Also used : TestUser(org.rembx.jeeshop.user.test.TestUser) User(org.rembx.jeeshop.user.model.User) Address(org.rembx.jeeshop.user.model.Address) WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) Test(org.junit.Test)

Aggregations

WebApplicationException (org.rembx.jeeshop.rest.WebApplicationException)24 Test (org.junit.Test)19 User (org.rembx.jeeshop.user.model.User)8 TestUser (org.rembx.jeeshop.user.test.TestUser)6 MailTemplate (org.rembx.jeeshop.user.model.MailTemplate)5 RolesAllowed (javax.annotation.security.RolesAllowed)4 Order (org.rembx.jeeshop.order.model.Order)3 Address (org.rembx.jeeshop.user.model.Address)3 TestMailTemplate (org.rembx.jeeshop.user.test.TestMailTemplate)3 PrincipalImpl (sun.security.acl.PrincipalImpl)3 Date (java.util.Date)2 Catalog (org.rembx.jeeshop.catalog.model.Catalog)2 TestOrder (org.rembx.jeeshop.order.test.TestOrder)2 IOException (java.io.IOException)1 PermitAll (javax.annotation.security.PermitAll)1 FileItemIterator (org.apache.commons.fileupload.FileItemIterator)1 FileItemStream (org.apache.commons.fileupload.FileItemStream)1 FileUploadException (org.apache.commons.fileupload.FileUploadException)1 ServletFileUpload (org.apache.commons.fileupload.servlet.ServletFileUpload)1 Category (org.rembx.jeeshop.catalog.model.Category)1