Search in sources :

Example 1 with Category

use of com.salesmanager.shop.model.catalog.category.Category in project shopizer by shopizer-ecommerce.

the class ServicesTestSupport method sampleProduct.

protected ReadableProduct sampleProduct(String code) {
    final PersistableCategory newCategory = new PersistableCategory();
    newCategory.setCode(code);
    newCategory.setSortOrder(1);
    newCategory.setVisible(true);
    newCategory.setDepth(4);
    final Category parent = new Category();
    newCategory.setParent(parent);
    final CategoryDescription description = new CategoryDescription();
    description.setLanguage("en");
    description.setName("test-cat");
    description.setFriendlyUrl("test-cat");
    description.setTitle("test-cat");
    final List<CategoryDescription> descriptions = new ArrayList<>();
    descriptions.add(description);
    newCategory.setDescriptions(descriptions);
    final HttpEntity<PersistableCategory> categoryEntity = new HttpEntity<>(newCategory, getHeader());
    final ResponseEntity<PersistableCategory> categoryResponse = testRestTemplate.postForEntity("/api/v1/private/category?store=" + Constants.DEFAULT_STORE, categoryEntity, PersistableCategory.class);
    final PersistableCategory cat = categoryResponse.getBody();
    assertThat(categoryResponse.getStatusCode(), is(CREATED));
    assertNotNull(cat.getId());
    final PersistableProduct product = new PersistableProduct();
    final ArrayList<Category> categories = new ArrayList<>();
    categories.add(cat);
    product.setCategories(categories);
    ProductSpecification specifications = new ProductSpecification();
    specifications.setManufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer.DEFAULT_MANUFACTURER);
    product.setProductSpecifications(specifications);
    product.setAvailable(true);
    product.setPrice(BigDecimal.TEN);
    product.setSku(code);
    product.setQuantity(100);
    ProductDescription productDescription = new ProductDescription();
    productDescription.setDescription("TEST");
    productDescription.setName("TestName");
    productDescription.setLanguage("en");
    product.getDescriptions().add(productDescription);
    final HttpEntity<PersistableProduct> entity = new HttpEntity<>(product, getHeader());
    final ResponseEntity<PersistableProduct> response = testRestTemplate.postForEntity("/api/v1/private/product?store=" + Constants.DEFAULT_STORE, entity, PersistableProduct.class);
    assertThat(response.getStatusCode(), is(CREATED));
    final HttpEntity<String> httpEntity = new HttpEntity<>(getHeader());
    String apiUrl = "/api/v1/products/" + response.getBody().getId();
    ResponseEntity<ReadableProduct> readableProduct = testRestTemplate.exchange(apiUrl, HttpMethod.GET, httpEntity, ReadableProduct.class);
    assertThat(readableProduct.getStatusCode(), is(OK));
    return readableProduct.getBody();
}
Also used : PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) Category(com.salesmanager.shop.model.catalog.category.Category) HttpEntity(org.springframework.http.HttpEntity) ArrayList(java.util.ArrayList) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) CategoryDescription(com.salesmanager.shop.model.catalog.category.CategoryDescription) ProductDescription(com.salesmanager.shop.model.catalog.product.ProductDescription)

Example 2 with Category

use of com.salesmanager.shop.model.catalog.category.Category in project shopizer by shopizer-ecommerce.

the class CategoryManagementAPIIntegrationTest method manufacturerForItemsInCategory.

@Test
public void manufacturerForItemsInCategory() throws Exception {
    ObjectWriter writer = new ObjectMapper().writer().withDefaultPrettyPrinter();
    // create first manufacturer
    PersistableManufacturer m1 = super.manufacturer("BRAND1");
    String json = writer.writeValueAsString(m1);
    HttpEntity<String> entity = new HttpEntity<>(json, getHeader());
    @SuppressWarnings("rawtypes") ResponseEntity response = testRestTemplate.postForEntity("/api/v1/private/manufacturer", entity, PersistableManufacturer.class);
    assertThat(response.getStatusCode(), is(CREATED));
    // create second manufacturer
    PersistableManufacturer m2 = super.manufacturer("BRAND2");
    json = writer.writeValueAsString(m2);
    entity = new HttpEntity<>(json, getHeader());
    response = testRestTemplate.postForEntity("/api/v1/private/manufacturer", entity, PersistableManufacturer.class);
    assertThat(response.getStatusCode(), is(CREATED));
    // create category
    PersistableCategory category = super.category("TEST");
    // to be used in product
    Category cat = new Category();
    cat.setCode("TEST");
    json = writer.writeValueAsString(category);
    entity = new HttpEntity<>(json, getHeader());
    @SuppressWarnings("rawtypes") ResponseEntity categoryResponse = testRestTemplate.postForEntity("/api/v1/private/category", entity, PersistableCategory.class);
    assertThat(categoryResponse.getStatusCode(), is(CREATED));
    final PersistableCategory persistable = (PersistableCategory) categoryResponse.getBody();
    Long id = persistable.getId();
    // create first item
    PersistableProduct product1 = super.product("PRODUCT1");
    product1.getCategories().add(cat);
    ProductSpecification specifications = new ProductSpecification();
    specifications.setManufacturer("BRAND1");
    product1.setProductSpecifications(specifications);
    json = writer.writeValueAsString(product1);
    entity = new HttpEntity<>(json, getHeader());
    response = testRestTemplate.postForEntity("/api/v1/private/product?store=" + Constants.DEFAULT_STORE, entity, PersistableProduct.class);
    assertThat(response.getStatusCode(), is(CREATED));
    // create second item
    PersistableProduct product2 = super.product("PRODUCT2");
    product2.getCategories().add(cat);
    specifications = new ProductSpecification();
    specifications.setManufacturer("BRAND2");
    product2.setProductSpecifications(specifications);
    json = writer.writeValueAsString(product2);
    entity = new HttpEntity<>(json, getHeader());
    response = testRestTemplate.postForEntity("/api/v1/private/product?store=" + Constants.DEFAULT_STORE, entity, PersistableProduct.class);
    assertThat(response.getStatusCode(), is(CREATED));
    entity = new HttpEntity<>(getHeader());
    // get manufacturers in category
    @SuppressWarnings("rawtypes") ResponseEntity<List> manufacturers = testRestTemplate.exchange(String.format("/api/v1/category/" + id + "/manufacturers"), HttpMethod.GET, entity, List.class);
    assertThat(manufacturers.getStatusCode(), is(OK));
    @SuppressWarnings("unchecked") List<ReadableManufacturer> manufacturerList = manufacturers.getBody();
// assertFalse(manufacturerList.isEmpty());
}
Also used : PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) Category(com.salesmanager.shop.model.catalog.category.Category) HttpEntity(org.springframework.http.HttpEntity) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ResponseEntity(org.springframework.http.ResponseEntity) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) ArrayList(java.util.ArrayList) ReadableCategoryList(com.salesmanager.shop.model.catalog.category.ReadableCategoryList) List(java.util.List) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with Category

use of com.salesmanager.shop.model.catalog.category.Category in project shopizer by shopizer-ecommerce.

the class CategoryManagementAPIIntegrationTest method postComplexCategory.

@Test
public void postComplexCategory() throws Exception {
    /**
     * Dining room *
     */
    final PersistableCategory dining = new PersistableCategory();
    dining.setCode("diningroom");
    dining.setSortOrder(0);
    dining.setVisible(true);
    CategoryDescription endescription = new CategoryDescription();
    endescription.setLanguage("en");
    endescription.setName("Dining room");
    endescription.setFriendlyUrl("dining-room");
    endescription.setTitle("Dining room");
    CategoryDescription frdescription = new CategoryDescription();
    frdescription.setLanguage("fr");
    frdescription.setName("Salle à manger");
    frdescription.setFriendlyUrl("salle-a-manger");
    frdescription.setTitle("Salle à manger");
    List<CategoryDescription> descriptions = new ArrayList<>();
    descriptions.add(endescription);
    descriptions.add(frdescription);
    dining.setDescriptions(descriptions);
    final Category diningParent = new Category();
    diningParent.setCode(dining.getCode());
    /**
     * armoire *
     */
    final PersistableCategory armoire = new PersistableCategory();
    armoire.setCode("armoire");
    armoire.setSortOrder(1);
    armoire.setVisible(true);
    armoire.setParent(diningParent);
    endescription = new CategoryDescription();
    endescription.setLanguage("en");
    endescription.setName("Armoires");
    endescription.setFriendlyUrl("armoires");
    endescription.setTitle("Armoires");
    frdescription = new CategoryDescription();
    frdescription.setLanguage("fr");
    frdescription.setName("Armoire");
    frdescription.setFriendlyUrl("armoires");
    frdescription.setTitle("Armoires");
    descriptions = new ArrayList<>();
    descriptions.add(endescription);
    descriptions.add(frdescription);
    armoire.setDescriptions(descriptions);
    dining.getChildren().add(armoire);
    /**
     * benches *
     */
    final PersistableCategory bench = new PersistableCategory();
    bench.setCode("bench");
    bench.setSortOrder(4);
    bench.setVisible(true);
    bench.setParent(diningParent);
    endescription = new CategoryDescription();
    endescription.setLanguage("en");
    endescription.setName("Benches");
    endescription.setFriendlyUrl("benches");
    endescription.setTitle("Benches");
    frdescription = new CategoryDescription();
    frdescription.setLanguage("fr");
    frdescription.setName("Bancs");
    frdescription.setFriendlyUrl("bancs");
    frdescription.setTitle("Bancs");
    descriptions = new ArrayList<>();
    descriptions.add(endescription);
    descriptions.add(frdescription);
    bench.setDescriptions(descriptions);
    dining.getChildren().add(bench);
    /**
     * Living room *
     */
    final PersistableCategory living = new PersistableCategory();
    living.setCode("livingroom");
    living.setSortOrder(2);
    living.setVisible(true);
    endescription = new CategoryDescription();
    endescription.setLanguage("en");
    endescription.setName("Living room");
    endescription.setFriendlyUrl("living-room");
    endescription.setTitle("Living room");
    frdescription = new CategoryDescription();
    frdescription.setLanguage("fr");
    frdescription.setName("Salon");
    frdescription.setFriendlyUrl("salon");
    frdescription.setTitle("Salon");
    descriptions = new ArrayList<>();
    descriptions.add(endescription);
    descriptions.add(frdescription);
    living.setDescriptions(descriptions);
    /**
     * lounge *
     */
    final PersistableCategory lounge = new PersistableCategory();
    lounge.setCode("lounge");
    lounge.setSortOrder(3);
    lounge.setVisible(true);
    final Category livingParent = living;
    lounge.setParent(livingParent);
    endescription = new CategoryDescription();
    endescription.setLanguage("en");
    endescription.setName("Lounge");
    endescription.setFriendlyUrl("lounge");
    endescription.setTitle("Lounge");
    frdescription = new CategoryDescription();
    frdescription.setLanguage("fr");
    frdescription.setName("Divan");
    frdescription.setFriendlyUrl("divan");
    frdescription.setTitle("Divan");
    descriptions = new ArrayList<>();
    descriptions.add(endescription);
    descriptions.add(frdescription);
    lounge.setDescriptions(descriptions);
    living.getChildren().add(lounge);
    final ObjectWriter writer = new ObjectMapper().writer().withDefaultPrettyPrinter();
    final String json = writer.writeValueAsString(dining);
    // System.out.println(json);
    final HttpEntity<String> entity = new HttpEntity<>(json, getHeader());
    final int sizeBefore = testRestTemplate.exchange(String.format("/api/v1/category"), HttpMethod.GET, new HttpEntity<>(getHeader()), ReadableCategoryList.class).getBody().getCategories().size();
    final ResponseEntity response = testRestTemplate.postForEntity("/api/v1/private/category", entity, PersistableCategory.class);
    final PersistableCategory cat = (PersistableCategory) response.getBody();
    assertThat(response.getStatusCode(), is(CREATED));
    assertNotNull(cat.getId());
}
Also used : PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) Category(com.salesmanager.shop.model.catalog.category.Category) HttpEntity(org.springframework.http.HttpEntity) ArrayList(java.util.ArrayList) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ReadableCategoryList(com.salesmanager.shop.model.catalog.category.ReadableCategoryList) ResponseEntity(org.springframework.http.ResponseEntity) CategoryDescription(com.salesmanager.shop.model.catalog.category.CategoryDescription) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Category

use of com.salesmanager.shop.model.catalog.category.Category in project shopizer by shopizer-ecommerce.

the class CategoryManagementAPIIntegrationTest method postCategory.

/**
 * Creates - POST a category for a given store
 *
 * @throws Exception
 */
@Test
public void postCategory() throws Exception {
    PersistableCategory newCategory = new PersistableCategory();
    newCategory.setCode("javascript");
    newCategory.setSortOrder(1);
    newCategory.setVisible(true);
    newCategory.setDepth(4);
    Category parent = new Category();
    newCategory.setParent(parent);
    CategoryDescription description = new CategoryDescription();
    description.setLanguage("en");
    description.setName("Javascript");
    description.setFriendlyUrl("javascript");
    description.setTitle("Javascript");
    List<CategoryDescription> descriptions = new ArrayList<>();
    descriptions.add(description);
    newCategory.setDescriptions(descriptions);
    final ObjectWriter writer = new ObjectMapper().writer().withDefaultPrettyPrinter();
    final String json = writer.writeValueAsString(newCategory);
    HttpEntity<String> entity = new HttpEntity<>(json, getHeader());
    ResponseEntity response = testRestTemplate.postForEntity("/api/v1/private/category", entity, PersistableCategory.class);
    PersistableCategory cat = (PersistableCategory) response.getBody();
    assertThat(response.getStatusCode(), is(CREATED));
    assertNotNull(cat.getId());
}
Also used : PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) ResponseEntity(org.springframework.http.ResponseEntity) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) Category(com.salesmanager.shop.model.catalog.category.Category) HttpEntity(org.springframework.http.HttpEntity) ArrayList(java.util.ArrayList) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) CategoryDescription(com.salesmanager.shop.model.catalog.category.CategoryDescription) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with Category

use of com.salesmanager.shop.model.catalog.category.Category in project shopizer by shopizer-ecommerce.

the class ProductManagementAPIIntegrationTest method postProduct.

@Test
@Ignore
public void postProduct() throws Exception {
    restTemplate = new RestTemplate();
    final PersistableProduct product = new PersistableProduct();
    final String code = "abcdef";
    // root category
    final String categoryCode = "ROOT";
    final Category category = new Category();
    category.setCode(categoryCode);
    final List<Category> categories = new ArrayList<>();
    categories.add(category);
    final String manufacturer = "temple";
    final Manufacturer collection = new Manufacturer();
    collection.setCode(manufacturer);
    // core properties
    product.setSku(code);
    // product.setManufacturer(collection); //no manufacturer assigned for
    // now
    // product.setCategories(categories); //no category assigned for now
    // set iterator as sort order
    product.setSortOrder(0);
    // force availability
    product.setAvailable(true);
    // force tangible good
    product.setProductVirtual(false);
    // force to 1 minimum when ordering
    product.setQuantityOrderMinimum(1);
    // all items are shipeable
    product.setProductShipeable(true);
    /**
     * images *
     */
    final String image = "/Users/carlsamson/Documents/csti/IMG_4626.jpg";
    // String image = "C:/personal/em/pictures-misc/IMG_2675.JPG";
    final File imgPath = new File(image);
    // PersistableImage persistableImage = new PersistableImage();
    // persistableImage.setBytes(this.extractBytes(imgPath));
    // persistableImage.setImageName(imgPath.getName());
    // List<PersistableImage> images = new ArrayList<PersistableImage>();
    // images.add(persistableImage);
    // product.setImages(images);
    ProductSpecification specifications = new ProductSpecification();
    specifications.setHeight(new BigDecimal(20));
    specifications.setLength(new BigDecimal(21));
    specifications.setWeight(new BigDecimal(22));
    specifications.setWidth(new BigDecimal(23));
    product.setProductSpecifications(specifications);
    product.setQuantity(5);
    product.setQuantityOrderMaximum(2);
    final PersistableProductPrice productPrice = new PersistableProductPrice();
    productPrice.setDefaultPrice(true);
    productPrice.setOriginalPrice(new BigDecimal(250));
    productPrice.setDiscountedPrice(new BigDecimal(125));
    final List<PersistableProductPrice> productPriceList = new ArrayList<>();
    productPriceList.add(productPrice);
    product.setProductPrices(productPriceList);
    final List<ProductDescription> descriptions = new ArrayList<>();
    // add english description
    ProductDescription description = new ProductDescription();
    description.setLanguage("en");
    description.setTitle("Buddha Head");
    description.setName("Buddha Head");
    description.setDescription("Buddha Head");
    description.setFriendlyUrl("buddha-head");
    // description.setHighlights(record.get("highlights_en"));
    descriptions.add(description);
    // add french description
    description = new ProductDescription();
    description.setLanguage("fr");
    description.setTitle("Tête de Buddha");
    description.setName("Tête de Buddha");
    description.setDescription(description.getName());
    description.setFriendlyUrl("tete-de-buddha");
    // 
    descriptions.add(description);
    product.setDescriptions(descriptions);
    // RENTAL
    final RentalOwner owner = new RentalOwner();
    // need to create a customer first
    owner.setId(1L);
    product.setOwner(owner);
    final ObjectWriter writer = new ObjectMapper().writer().withDefaultPrettyPrinter();
    final String json = writer.writeValueAsString(product);
    System.out.println(json);
    final HttpEntity<String> entity = new HttpEntity<>(json, getHeader());
    // post to create category web service
    final ResponseEntity response = restTemplate.postForEntity("http://localhost:8080/api/v1/product", entity, PersistableProduct.class);
    final PersistableProduct prod = (PersistableProduct) response.getBody();
    System.out.println("---------------------");
}
Also used : PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) Category(com.salesmanager.shop.model.catalog.category.Category) PersistableProductPrice(com.salesmanager.shop.model.catalog.product.PersistableProductPrice) HttpEntity(org.springframework.http.HttpEntity) ArrayList(java.util.ArrayList) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) RentalOwner(com.salesmanager.shop.model.catalog.product.RentalOwner) BigDecimal(java.math.BigDecimal) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ResponseEntity(org.springframework.http.ResponseEntity) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) RestTemplate(org.springframework.web.client.RestTemplate) Manufacturer(com.salesmanager.shop.model.catalog.manufacturer.Manufacturer) ProductDescription(com.salesmanager.shop.model.catalog.product.ProductDescription) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Ignore(org.junit.Ignore) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Category (com.salesmanager.shop.model.catalog.category.Category)7 PersistableCategory (com.salesmanager.shop.model.catalog.category.PersistableCategory)7 ArrayList (java.util.ArrayList)7 HttpEntity (org.springframework.http.HttpEntity)7 Test (org.junit.Test)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 CategoryDescription (com.salesmanager.shop.model.catalog.category.CategoryDescription)5 PersistableProduct (com.salesmanager.shop.model.catalog.product.PersistableProduct)5 ProductSpecification (com.salesmanager.shop.model.catalog.product.ProductSpecification)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)4 ResponseEntity (org.springframework.http.ResponseEntity)4 ReadableCategory (com.salesmanager.shop.model.catalog.category.ReadableCategory)3 ReadableCategoryList (com.salesmanager.shop.model.catalog.category.ReadableCategoryList)2 ProductDescription (com.salesmanager.shop.model.catalog.product.ProductDescription)2 Manufacturer (com.salesmanager.shop.model.catalog.manufacturer.Manufacturer)1 PersistableManufacturer (com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer)1 ReadableManufacturer (com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer)1 PersistableProductPrice (com.salesmanager.shop.model.catalog.product.PersistableProductPrice)1 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)1