예제 #1
0
  @Test
  public void testRemoveProductContent() {
    Product p = createTestProduct();
    Content content =
        new Content(
            this.owner,
            "test-content",
            "test-content",
            "test-content",
            "yum",
            "us",
            "here",
            "here",
            "test-arch");
    p.addContent(content);
    contentCurator.create(content);
    productCurator.create(p);

    p = productCurator.find(p.getUuid());
    assertEquals(1, p.getProductContent().size());

    productCurator.removeProductContent(p, content);
    p = productCurator.find(p.getUuid());
    assertEquals(0, p.getProductContent().size());
  }
예제 #2
0
  @Test
  public void nameNonUnique() {

    Product prod = new Product("label1", "name", owner);
    productCurator.create(prod);

    Product prod2 = new Product("label2", "name", owner);
    productCurator.create(prod2);

    assertEquals(prod.getName(), prod2.getName());
    assertFalse(prod.getUuid().equals(prod2.getUuid()));
  }
예제 #3
0
  @Test
  public void testProductFullConstructor() {
    Product prod = new Product("cp_test-label", "variant", owner, "version", "arch", "", "SVC");
    productCurator.create(prod);

    productCurator.find(prod.getUuid());
  }
예제 #4
0
 @Test(expected = BadRequestException.class)
 public void testProductAttributeUpdateFailNumberBool() {
   Product original = createTestProduct();
   productCurator.create(original);
   assertTrue(original.getUuid() != null);
   original.addAttribute(new ProductAttribute("product.bool_val_num", "6"));
   productCurator.createOrUpdate(original);
 }
예제 #5
0
 @Test(expected = BadRequestException.class)
 public void testProductAttributeUpdateFailPosLong() {
   Product original = createTestProduct();
   productCurator.create(original);
   assertTrue(original.getUuid() != null);
   original.addAttribute(new ProductAttribute("product.long_pos_count", "-23"));
   productCurator.createOrUpdate(original);
 }
예제 #6
0
 @Test
 public void testProductAttributeUpdateSuccessZeroInt() {
   Product original = createTestProduct();
   productCurator.create(original);
   assertTrue(original.getUuid() != null);
   original.addAttribute(new ProductAttribute("product.pos_count", "0"));
   productCurator.createOrUpdate(original);
 }
예제 #7
0
  @Test
  public void testDependentProducts() {
    Product prod = new Product("test-label", "test-product-name", owner);
    HashSet<String> dependentProductIds = new HashSet<String>();
    dependentProductIds.add("ProductX");
    prod.setDependentProductIds(dependentProductIds);
    productCurator.create(prod);

    Product lookedUp = productCurator.find(prod.getUuid());
    assertThat(lookedUp.getDependentProductIds(), hasItem("ProductX"));
  }
예제 #8
0
 @Test
 public void testProductAttributeValidationSuccessUpdate() {
   Product original = createTestProduct();
   productCurator.create(original);
   assertTrue(original.getUuid() != null);
   original.setAttribute("product.count", "134");
   original.setAttribute("product.pos_count", "333");
   original.setAttribute(
       "product.long_multiplier", (new Long(Integer.MAX_VALUE * 100)).toString());
   original.setAttribute("product.long_pos_count", "10");
   original.setAttribute("product.bool_val_str", "false");
   original.setAttribute("product.bool_val_num", "1");
   productCurator.createOrUpdate(original);
 }
예제 #9
0
  @Test
  public void testSaveOrUpdateProductNoDuplicateProdContent() {
    Product p = createTestProduct();
    Content content =
        new Content(
            this.owner,
            "best-content",
            "best-content",
            "best-content",
            "yum",
            "us",
            "here",
            "here",
            "test-arch");

    p.addContent(content);
    contentCurator.create(content);
    productCurator.createOrUpdate(p);

    // Technically the same product:
    Product p2 = createTestProduct();

    // The content isn't quite the same. We just care about matching
    // product ids with content ids
    Content contentUpdate =
        new Content(
            this.owner,
            "best-content",
            "best-content",
            "best-content",
            "yum",
            "us",
            "here",
            "differnet",
            "test-arch");

    contentUpdate.setUuid(content.getUuid());

    p2.addContent(contentUpdate);
    productCurator.createOrUpdate(p2);

    Product result = productCurator.find(p.getUuid());
    assertEquals(1, result.getProductContent().size());
  }
예제 #10
0
  @Test
  public void testJsonListOfHashes() throws Exception {
    List<Map<String, String>> data = new LinkedList<Map<String, String>>();
    Map<String, String> contentSet1 = new HashMap<String, String>();
    contentSet1.put("name", "cs1");
    contentSet1.put("url", "url");

    Map<String, String> contentSet2 = new HashMap<String, String>();
    contentSet2.put("name", "cs2");
    contentSet2.put("url", "url2");

    data.add(contentSet1);
    data.add(contentSet2);

    ObjectMapper mapper = new ObjectMapper();
    String jsonData = mapper.writeValueAsString(data);

    Product prod = new Product("cptest-label", "My Product", owner);
    ProductAttribute a = new ProductAttribute("content_sets", jsonData);
    prod.addAttribute(a);
    productCurator.create(prod);
    attributeCurator.create(a);

    Product lookedUp = productCurator.find(prod.getUuid());
    assertEquals(jsonData, lookedUp.getAttribute("content_sets").getValue());

    data =
        mapper.readValue(
            lookedUp.getAttribute("content_sets").getValue(),
            new TypeReference<List<Map<String, String>>>() {});
    Map<String, String> cs1 = data.get(0);
    assertEquals("cs1", cs1.get("name"));

    Map<String, String> cs2 = data.get(1);
    assertEquals("cs2", cs2.get("name"));
  }
예제 #11
0
  @Test
  public void testWithSimpleJsonAttribute() throws Exception {
    Map<String, String> data = new HashMap<String, String>();
    data.put("a", "1");
    data.put("b", "2");
    ObjectMapper mapper = new ObjectMapper();
    String jsonData = mapper.writeValueAsString(data);

    Product prod = new Product("cptest-label", "My Product", owner);
    ProductAttribute a = new ProductAttribute("content_sets", jsonData);
    prod.addAttribute(a);
    productCurator.create(prod);
    attributeCurator.create(a);

    Product lookedUp = productCurator.find(prod.getUuid());
    assertEquals(jsonData, lookedUp.getAttribute("content_sets").getValue());

    data =
        mapper.readValue(
            lookedUp.getAttribute("content_sets").getValue(),
            new TypeReference<Map<String, String>>() {});
    assertEquals("1", data.get("a"));
    assertEquals("2", data.get("b"));
  }