Search in sources :

Example 6 with WebApplicationException

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

the class CatalogsCT method modifyUnknownCatalog_ShouldThrowNotFoundException.

@Test
public void modifyUnknownCatalog_ShouldThrowNotFoundException() {
    Catalog detachedCatalogToModify = new Catalog(9999L, null);
    try {
        service.modify(detachedCatalogToModify);
        fail("should have thrown ex");
    } catch (WebApplicationException e) {
        assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.NOT_FOUND);
    }
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) Catalog(org.rembx.jeeshop.catalog.model.Catalog) TestCatalog(org.rembx.jeeshop.catalog.test.TestCatalog) Test(org.junit.Test)

Example 7 with WebApplicationException

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

the class CategoriesCT method modifyUnknownCategory_ShouldThrowNotFoundException.

@Test
public void modifyUnknownCategory_ShouldThrowNotFoundException() {
    Category detachedCategoryToModify = new Category(9999L, null, null, null, null, null);
    try {
        service.modify(detachedCategoryToModify);
        fail("should have thrown ex");
    } catch (WebApplicationException e) {
        assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.NOT_FOUND);
    }
}
Also used : Category(org.rembx.jeeshop.catalog.model.Category) WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) Test(org.junit.Test)

Example 8 with WebApplicationException

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

the class ProductsCT method modifyUnknownProduct_ShouldThrowNotFoundException.

@Test
public void modifyUnknownProduct_ShouldThrowNotFoundException() {
    Product detachedProductToModify = new Product(9999L, null, null, null, null, null);
    try {
        service.modify(detachedProductToModify);
        fail("should have thrown ex");
    } catch (WebApplicationException e) {
        assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.NOT_FOUND);
    }
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) Product(org.rembx.jeeshop.catalog.model.Product) Test(org.junit.Test)

Example 9 with WebApplicationException

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

the class SKUsCT method modifyUnknownSKU_ShouldThrowNotFoundException.

@Test
public void modifyUnknownSKU_ShouldThrowNotFoundException() {
    SKU detachedProductToModify = new SKU(9999L, null, null, null, null, null, null, null, null, null);
    try {
        service.modify(detachedProductToModify);
        fail("should have thrown ex");
    } catch (WebApplicationException e) {
        assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.NOT_FOUND);
    }
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) SKU(org.rembx.jeeshop.catalog.model.SKU) Test(org.junit.Test)

Example 10 with WebApplicationException

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

the class Medias method upload.

@POST
@Consumes("multipart/form-data")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed(ADMIN)
@Path("/{type}/{id}/{locale}/upload")
public void upload(@Context HttpServletRequest request, @NotNull @PathParam("type") String itemType, @NotNull @PathParam("id") Long itemId, @NotNull @PathParam("locale") String locale) {
    try {
        ServletFileUpload upload = new ServletFileUpload();
        FileItemIterator iterator = upload.getItemIterator(request);
        while (iterator.hasNext()) {
            FileItemStream item = iterator.next();
            java.nio.file.Path itemBasePath = getBasePath().resolve(itemType).resolve(itemId.toString()).resolve(locale);
            if (!Files.exists(itemBasePath))
                Files.createDirectories(itemBasePath);
            java.nio.file.Path filePath = itemBasePath.resolve(item.getName());
            Files.copy(item.openStream(), filePath, StandardCopyOption.REPLACE_EXISTING);
            LOG.info("File written to " + filePath);
        }
    } catch (IOException | FileUploadException e) {
        LOG.error("Could not handle upload of file with type: " + itemType + " and id: " + itemId, e);
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) FileItemStream(org.apache.commons.fileupload.FileItemStream) IOException(java.io.IOException) FileItemIterator(org.apache.commons.fileupload.FileItemIterator) FileUploadException(org.apache.commons.fileupload.FileUploadException) RolesAllowed(javax.annotation.security.RolesAllowed)

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