Example #1
0
  protected Entity addItem(Entity parentEntity, Integer qtyValue, Double priceValue) {
    EntityDefinition rootEntityDefn = parentEntity.getDefinition();
    EntityDefinition itemDefn = (EntityDefinition) rootEntityDefn.getChildDefinition("item");
    Entity item = (Entity) itemDefn.createNode();

    if (qtyValue != null) {
      NodeDefinition qtyDefn = itemDefn.getChildDefinition("qty");
      IntegerAttribute qty = (IntegerAttribute) qtyDefn.createNode();
      qty.setValue(new IntegerValue(qtyValue, null));
      item.add(qty);
    }
    if (priceValue != null) {
      NumericAttributeDefinition priceDefn =
          (NumericAttributeDefinition) itemDefn.getChildDefinition("price");
      RealAttribute price = (RealAttribute) priceDefn.createNode();
      price.setValue(new RealValue(priceValue, null));
      item.add(price);
    }
    NumberAttributeDefinition totalDefn =
        (NumberAttributeDefinition) itemDefn.getChildDefinition("total");
    RealAttribute total = (RealAttribute) totalDefn.createNode();
    item.add(total);

    NumberAttributeDefinition discountDefn =
        (NumberAttributeDefinition) itemDefn.getChildDefinition("discount_percent");
    IntegerAttribute discount = (IntegerAttribute) discountDefn.createNode();
    item.add(discount);

    parentEntity.add(item);
    return item;
  }
Example #2
0
 @Test
 @Ignore
 public void testNullValue() throws InvalidExpressionException {
   Entity rootEntity = record.getRootEntity();
   Entity item = addItem(rootEntity, null, 5.5d);
   RealAttribute total = (RealAttribute) item.get("total", 0);
   assertEquals(Double.valueOf(0d), total.getValue().getValue());
 }
Example #3
0
 @Test
 @Ignore
 public void testNotNullValues() throws InvalidExpressionException {
   Entity rootEntity = record.getRootEntity();
   Entity item = addItem(rootEntity, 10, 5.5d);
   RealAttribute total = (RealAttribute) item.get("total", 0);
   RealValue calculatedTotal = total.getValue();
   assertEquals(new RealValue(55d, null), calculatedTotal);
 }
Example #4
0
  @Test
  @Ignore
  public void testUpdateAttribute() throws InvalidExpressionException {
    Entity rootEntity = record.getRootEntity();
    Entity item = addItem(rootEntity, 10, 5.5d);

    RealAttribute total = (RealAttribute) item.get("total", 0);
    RealValue calculatedTotal = total.getValue();
    assertEquals(new RealValue(55d, null), calculatedTotal);

    // change dependent attribute
    IntegerAttribute qty = (IntegerAttribute) item.get("qty", 0);
    qty.setNumber(20);
    //		qty.clearDependentCalculatedAttributes();

    calculatedTotal = total.getValue();
    assertEquals(new RealValue(110d, null), calculatedTotal);
  }