Search in sources :

Example 51 with WebApplicationException

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

the class UsersCT method create_shouldThrowBadRequestExceptionExWhenUserAddressHasAnId.

@Test
public void create_shouldThrowBadRequestExceptionExWhenUserAddressHasAnId() throws Exception {
    User user = new User();
    user.setLogin("toto@toto.com");
    Address address = new Address();
    address.setId(1L);
    user.setAddress(address);
    try {
        service.create(sessionContextMock, 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.jupiter.api.Test)

Example 52 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(sessionContextMock, 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.jupiter.api.Test)

Example 53 with WebApplicationException

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

the class MailTemplatesCT method create_shouldThrowConflictException_WhenThereIsAlreadyAMailTemplateWithSameLocaleAndName.

@Test
public void create_shouldThrowConflictException_WhenThereIsAlreadyAMailTemplateWithSameLocaleAndName() {
    MailTemplate mailTemplate = new MailTemplate("Newsletter1", "fr_FR", "test content", "Test Subject");
    try {
        service.create(mailTemplate);
        fail("Should have thrown exception");
    } catch (WebApplicationException e) {
        assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.CONFLICT);
    }
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) TestMailTemplate(org.rembx.jeeshop.user.test.TestMailTemplate) MailTemplate(org.rembx.jeeshop.user.model.MailTemplate) Test(org.junit.jupiter.api.Test)

Example 54 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(sessionContextMock, 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.jupiter.api.Test)

Example 55 with WebApplicationException

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

the class MailTemplates method create.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed(ADMIN)
public MailTemplate create(MailTemplate mailTemplate) {
    MailTemplate existingTpl = mailTemplateFinder.findByNameAndLocale(mailTemplate.getName(), mailTemplate.getLocale());
    if (existingTpl != null) {
        throw new WebApplicationException(Response.Status.CONFLICT);
    }
    entityManager.persist(mailTemplate);
    return mailTemplate;
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) MailTemplate(org.rembx.jeeshop.user.model.MailTemplate) RolesAllowed(javax.annotation.security.RolesAllowed)

Aggregations

WebApplicationException (org.rembx.jeeshop.rest.WebApplicationException)55 Test (org.junit.jupiter.api.Test)34 RolesAllowed (javax.annotation.security.RolesAllowed)19 Transactional (javax.transaction.Transactional)9 Catalog (org.rembx.jeeshop.catalog.model.Catalog)9 User (org.rembx.jeeshop.user.model.User)9 Store (org.rembx.jeeshop.catalog.model.Store)7 TestUser (org.rembx.jeeshop.user.test.TestUser)7 MailTemplate (org.rembx.jeeshop.user.model.MailTemplate)5 Category (org.rembx.jeeshop.catalog.model.Category)4 SKU (org.rembx.jeeshop.catalog.model.SKU)4 TestCatalog (org.rembx.jeeshop.catalog.test.TestCatalog)4 Order (org.rembx.jeeshop.order.model.Order)4 BasicUserPrincipal (org.apache.http.auth.BasicUserPrincipal)3 Product (org.rembx.jeeshop.catalog.model.Product)3 Address (org.rembx.jeeshop.user.model.Address)3 TestMailTemplate (org.rembx.jeeshop.user.test.TestMailTemplate)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 PermitAll (javax.annotation.security.PermitAll)2