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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations