Ejemplo n.º 1
0
  @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());
  }