Search in sources :

Example 1 with Manufacturer

use of com.salesmanager.shop.model.catalog.manufacturer.Manufacturer 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

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 Category (com.salesmanager.shop.model.catalog.category.Category)1 PersistableCategory (com.salesmanager.shop.model.catalog.category.PersistableCategory)1 Manufacturer (com.salesmanager.shop.model.catalog.manufacturer.Manufacturer)1 PersistableProduct (com.salesmanager.shop.model.catalog.product.PersistableProduct)1 PersistableProductPrice (com.salesmanager.shop.model.catalog.product.PersistableProductPrice)1 ProductDescription (com.salesmanager.shop.model.catalog.product.ProductDescription)1 ProductSpecification (com.salesmanager.shop.model.catalog.product.ProductSpecification)1 RentalOwner (com.salesmanager.shop.model.catalog.product.RentalOwner)1 File (java.io.File)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 HttpEntity (org.springframework.http.HttpEntity)1 ResponseEntity (org.springframework.http.ResponseEntity)1 RestTemplate (org.springframework.web.client.RestTemplate)1