/** Test whether the product updation date is updated when merging. */ @Test public void testSubsequentUpdate() { Product prod = new Product("test-label", "test-product-name", owner); productCurator.create(prod); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.MONTH, -2); prod.setUpdated(calendar.getTime()); long updated = prod.getUpdated().getTime(); prod.setName("test-changed-name"); prod = this.productCurator.merge(prod); assertTrue(prod.getUpdated().getTime() > updated); }
@Test public void testUpdateProduct() { Product original = createTestProduct(); productCurator.create(original); // Will have same ID, but we'll modify other data: Product modified = createTestProduct(); String newName = "new name"; modified.setName(newName); // Hack up the attributes, keep a1, skip a2, modify a3, add a4: Set<ProductAttribute> newAttributes = new HashSet<ProductAttribute>(); newAttributes.add(modified.getAttribute("a1")); ProductAttribute a3 = modified.getAttribute("a3"); a3.setValue("a3-modified"); a3.setProduct(modified); newAttributes.add(a3); ProductAttribute a4 = new ProductAttribute("a4", "a4"); a4.setProduct(modified); newAttributes.add(a4); modified.setAttributes(newAttributes); int initialAttrCount = attributeCurator.listAll().size(); productCurator.createOrUpdate(modified); Product lookedUp = productCurator.lookupById(owner, original.getId()); assertEquals(newName, lookedUp.getName()); assertEquals(3, lookedUp.getAttributes().size()); assertEquals("a1", lookedUp.getAttributeValue("a1")); assertEquals("a3-modified", lookedUp.getAttributeValue("a3")); assertEquals("a4", lookedUp.getAttributeValue("a4")); // TODO: test content merging // Old attributes should get cleaned up: assertEquals(initialAttrCount, attributeCurator.listAll().size()); }
@Test public void testSetName() throws Exception { product.setName("Bla"); assertEquals("Bla", product.getName()); }