Ejemplo n.º 1
0
  @Test
  public void listByIds() {
    List<Product> products = new ArrayList<Product>();
    List<String> pids = new ArrayList<String>();
    for (int i = 0; i < 5; i++) {
      Product p = TestUtil.createProduct(owner);
      productCurator.create(p);
      products.add(p);
      pids.add(p.getId());
    }

    // ok get first 3 items to lookup
    List<Product> returned = productCurator.listAllByIds(owner, pids.subList(0, 3));
    assertEquals(3, returned.size());

    // verify the first 3 were actually returned, and only those 3.
    assertTrue(returned.contains(products.get(0)));
    assertTrue(returned.contains(products.get(1)));
    assertTrue(returned.contains(products.get(2)));
    assertFalse(returned.contains(products.get(3)));
    assertFalse(returned.contains(products.get(4)));
  }
Ejemplo n.º 2
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());
  }