Search in sources :

Example 6 with Catalog

use of org.rembx.jeeshop.catalog.model.Catalog in project jeeshop by remibantos.

the class Catalogs method modify.

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Transactional
@RolesAllowed({ ADMIN, STORE_ADMIN })
public Catalog modify(@Context SecurityContext securityContext, Catalog catalogToModify) {
    Catalog originalCatalog = entityManager.find(Catalog.class, catalogToModify.getId());
    checkNotNull(originalCatalog);
    if (!isAdminUser(securityContext) && !isOwner(securityContext, originalCatalog.getOwner()))
        throw new WebApplicationException(Response.Status.FORBIDDEN);
    if (catalogToModify.getRootCategoriesIds() != null) {
        List<Category> newCategories = new ArrayList<>();
        catalogToModify.getRootCategoriesIds().forEach(categoryId -> newCategories.add(entityManager.find(Category.class, categoryId)));
        catalogToModify.setRootCategories(newCategories);
    } else {
        catalogToModify.setRootCategories(originalCatalog.getRootCategories());
    }
    catalogToModify.setPresentationByLocale(originalCatalog.getPresentationByLocale());
    return entityManager.merge(catalogToModify);
}
Also used : Category(org.rembx.jeeshop.catalog.model.Category) WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) ArrayList(java.util.ArrayList) Catalog(org.rembx.jeeshop.catalog.model.Catalog) RolesAllowed(javax.annotation.security.RolesAllowed) Transactional(javax.transaction.Transactional)

Example 7 with Catalog

use of org.rembx.jeeshop.catalog.model.Catalog in project jeeshop by remibantos.

the class CatalogsCT method modifyUnknownCatalog_ShouldThrowNotFoundException.

@Test
public void modifyUnknownCatalog_ShouldThrowNotFoundException() {
    tester.setStoreAdminUser();
    Catalog detachedCatalogToModify = new Catalog(9999L, null);
    try {
        tester.test_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.jupiter.api.Test)

Example 8 with Catalog

use of org.rembx.jeeshop.catalog.model.Catalog in project jeeshop by remibantos.

the class CatalogsCT method find_withIdOfVisibleCatalog_ShouldReturnExpectedCatalog.

@Test
public void find_withIdOfVisibleCatalog_ShouldReturnExpectedCatalog() {
    tester.setStoreAdminUser();
    Catalog catalog = localService.find(tester.getSecurityContext(), tester.getFixtures().getCatalogId(), null);
    assertThat(catalog).isNotNull();
    assertThat(catalog.isVisible()).isTrue();
}
Also used : Catalog(org.rembx.jeeshop.catalog.model.Catalog) TestCatalog(org.rembx.jeeshop.catalog.test.TestCatalog) Test(org.junit.jupiter.api.Test)

Example 9 with Catalog

use of org.rembx.jeeshop.catalog.model.Catalog in project jeeshop by remibantos.

the class CatalogItemFinderTest method find_NotVisibleCatalogItem_ShouldThrowForbiddenException.

@Test
public void find_NotVisibleCatalogItem_ShouldThrowForbiddenException() {
    try {
        instance.filterVisible(new Catalog(), null);
        fail("should have thrown ex");
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.FORBIDDEN, e.getResponse().getStatusInfo());
    }
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) Catalog(org.rembx.jeeshop.catalog.model.Catalog) Test(org.junit.jupiter.api.Test)

Example 10 with Catalog

use of org.rembx.jeeshop.catalog.model.Catalog in project jeeshop by remibantos.

the class CatalogsCT method delete_shouldThrowForbidden_for_store_admin.

@Test
public void delete_shouldThrowForbidden_for_store_admin() {
    try {
        tester.setStoreAdminUser();
        Catalog catalog = new Catalog("catalog");
        catalog.setOwner("test@test.org");
        tester.test_delete(catalog);
        fail("Should have throw an exception");
    } catch (WebApplicationException e) {
        assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.FORBIDDEN);
    }
}
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.jupiter.api.Test)

Aggregations

Catalog (org.rembx.jeeshop.catalog.model.Catalog)22 Test (org.junit.jupiter.api.Test)10 TestCatalog (org.rembx.jeeshop.catalog.test.TestCatalog)10 WebApplicationException (org.rembx.jeeshop.rest.WebApplicationException)9 RolesAllowed (javax.annotation.security.RolesAllowed)7 ArrayList (java.util.ArrayList)6 PermitAll (javax.annotation.security.PermitAll)4 Category (org.rembx.jeeshop.catalog.model.Category)4 Transactional (javax.transaction.Transactional)3 Store (org.rembx.jeeshop.catalog.model.Store)2 Test (org.junit.Test)1 Presentation (org.rembx.jeeshop.catalog.model.Presentation)1