ProductImporter { public ProductDTO createObject(ObjectMapper mapper, Reader reader, Owner owner) throws IOException { ProductDTO importedProduct = mapper.readValue(reader, ProductDTO.class); importedProduct.setUuid(null); importedProduct.setMultiplier(1L); if (importedProduct.getProductContent() != null) { for (ProductDTO.ProductContentDTO pc : importedProduct.getProductContent()) { ContentDTO content = pc.getContent(); content.setUuid(null); if (StringUtils.isBlank(content.getVendor())) { content.setVendor("unknown"); } content.setMetadataExpiration(1L); } } return importedProduct; } ProductImporter(); ProductDTO createObject(ObjectMapper mapper, Reader reader, Owner owner);  }
@Test public void testCreateObject() throws Exception { Product product = TestUtil.createProduct(); product.setAttribute("a1", "a1"); product.setAttribute("a2", "a2"); String json = getJsonForProduct(product); Reader reader = new StringReader(json); ProductDTO created = importer.createObject(mapper, reader, owner); assertEquals(product.getUuid(), created.getUuid()); assertEquals(product.getName(), created.getName()); assertEquals(product.getAttributes(), created.getAttributes()); }
@Test public void testNewProductCreated() throws Exception { ProductDTO product = new ProductDTO(); product.setId("test-id"); product.setName("test-name"); product.setAttribute("attr1", "val1"); product.setAttribute("attr2", "val2"); product.setMultiplier(1L); Set<String> dependentProdIDs = new HashSet<>(); dependentProdIDs.add("g23gh23h2"); dependentProdIDs.add("353g823h"); product.setDependentProductIds(dependentProdIDs); String json = getJsonForProduct(product); Reader reader = new StringReader(json); ProductDTO created = importer.createObject(mapper, reader, owner); assertEquals(product, created); }
@Test public void testContentCreated() throws Exception { Product product = TestUtil.createProduct(); addContentTo(product); String json = getJsonForProduct(product); Reader reader = new StringReader(json); ProductDTO created = importer.createObject(mapper, reader, owner); ContentDTO c = created.getProductContent().iterator().next().getContent(); assertEquals(new Long(1), c.getMetadataExpiration()); }
@Test public void testVendorSetToUnknown() throws Exception { Product product = TestUtil.createProduct(); addNoVendorContentTo(product); String json = getJsonForProduct(product); Reader reader = new StringReader(json); ProductDTO created = importer.createObject(mapper, reader, owner); ContentDTO c = created.getProductContent().iterator().next().getContent(); assertEquals("unknown", c.getVendor()); }