Search in sources :

Example 1 with BasePropertyImpl

use of com.dexels.navajo.document.base.BasePropertyImpl in project navajo by Dexels.

the class TestProperty method tesSelectionEqualsUpdateFix.

@Test
public void tesSelectionEqualsUpdateFix() {
    BaseNavajoImpl n = new BaseNavajoImpl(NavajoFactory.getInstance());
    BasePropertyImpl p1 = new BasePropertyImpl(n, "Noot");
    p1.setType("selection");
    p1.setCardinality("1");
    p1.addSelection(new BaseSelectionImpl(n, "opt1", "1", false));
    p1.addSelection(new BaseSelectionImpl(n, "opt2", "2", true));
    p1.addPropertyChangeListener(e -> {
        logger.info("Old: {}", e.getOldValue());
        logger.info("New: {}", e.getNewValue());
        // no real change.
        Assert.fail();
    });
    p1.setSelected(p1.getSelection("opt2"));
}
Also used : BaseNavajoImpl(com.dexels.navajo.document.base.BaseNavajoImpl) BasePropertyImpl(com.dexels.navajo.document.base.BasePropertyImpl) BaseSelectionImpl(com.dexels.navajo.document.base.BaseSelectionImpl) Test(org.junit.Test)

Example 2 with BasePropertyImpl

use of com.dexels.navajo.document.base.BasePropertyImpl in project navajo by Dexels.

the class TestProperty method tesSelections.

@Test
@Deprecated
public void tesSelections() {
    BaseNavajoImpl n = new BaseNavajoImpl(NavajoFactory.getInstance());
    BasePropertyImpl p1 = new BasePropertyImpl(n, "Noot");
    p1.setType("selection");
    p1.setCardinality("1");
    p1.addSelection(new BaseSelectionImpl(n, "opt1", "1", false));
    p1.addSelection(new BaseSelectionImpl(n, "opt2", "2", false));
    p1.addSelection(new BaseSelectionImpl(n, "opt3", "3", false));
    assertEquals("___DUMMY_ELEMENT___", p1.getSelected().getValue());
    // Cardinality 1
    p1.setSelected("1");
    assertEquals("1", p1.getSelected().getValue());
    assertFalse("2".equals(p1.getSelected().getValue()));
    assertFalse("3".equals(p1.getSelected().getValue()));
    p1.setSelected("2");
    assertEquals("2", p1.getSelected().getValue());
    assertFalse("1".equals(p1.getSelected().getValue()));
    assertFalse("3".equals(p1.getSelected().getValue()));
    p1.setSelected("3");
    assertEquals("3", p1.getSelected().getValue());
    assertFalse("1".equals(p1.getSelected().getValue()));
    assertFalse("2".equals(p1.getSelected().getValue()));
    // Cardinality +
    p1.setCardinality("+");
    p1.clearSelections();
    assertFalse("1".equals(p1.getSelected().getValue()));
    assertFalse("2".equals(p1.getSelected().getValue()));
    assertFalse("3".equals(p1.getSelected().getValue()));
    p1.setSelected("1");
    p1.setSelected("2");
    List<Selection> all = p1.getAllSelectedSelections();
    for (int i = 0; i < all.size(); i++) {
        assertTrue(all.get(i).getValue().equals("1") || all.get(i).getValue().equals("2"));
        assertFalse(all.get(i).getValue().equals("3"));
    }
}
Also used : BaseNavajoImpl(com.dexels.navajo.document.base.BaseNavajoImpl) BasePropertyImpl(com.dexels.navajo.document.base.BasePropertyImpl) Selection(com.dexels.navajo.document.Selection) BaseSelectionImpl(com.dexels.navajo.document.base.BaseSelectionImpl) Test(org.junit.Test)

Example 3 with BasePropertyImpl

use of com.dexels.navajo.document.base.BasePropertyImpl in project navajo by Dexels.

the class TestProperty method tesMoneyProperty.

@Test
public void tesMoneyProperty() {
    BaseNavajoImpl n = new BaseNavajoImpl(NavajoFactory.getInstance());
    BaseMessageImpl m = new BaseMessageImpl(n, "Aap");
    n.addMessage(m);
    BasePropertyImpl p1 = new BasePropertyImpl(n, "Noot");
    m.addProperty(p1);
    p1.setType(Property.MONEY_PROPERTY);
    p1.setValue("10.30");
    StringWriter sw = new StringWriter();
    n.write(sw);
    StringReader sr = new StringReader(sw.toString());
    Navajo n2 = NavajoFactory.getInstance().createNavajo(sr);
    Property p2 = n2.getProperty("Aap/Noot");
    Money mon = (Money) p2.getTypedValue();
    logger.info("m: " + mon.toTmlString() + " :: " + mon.editingString() + " :: " + mon.toString());
    Assert.assertEquals(mon.toTmlString(), "10.30");
    Assert.assertEquals(mon.doubleValue(), 10.30d, 0.1);
}
Also used : BaseMessageImpl(com.dexels.navajo.document.base.BaseMessageImpl) Money(com.dexels.navajo.document.types.Money) StringWriter(java.io.StringWriter) BaseNavajoImpl(com.dexels.navajo.document.base.BaseNavajoImpl) BasePropertyImpl(com.dexels.navajo.document.base.BasePropertyImpl) StringReader(java.io.StringReader) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property) Test(org.junit.Test)

Example 4 with BasePropertyImpl

use of com.dexels.navajo.document.base.BasePropertyImpl in project navajo by Dexels.

the class TestProperty method tesEqualProperties.

@Test
public void tesEqualProperties() {
    BaseNavajoImpl n = new BaseNavajoImpl(NavajoFactory.getInstance());
    BasePropertyImpl p1 = new BasePropertyImpl(n, "Noot");
    BasePropertyImpl p2 = new BasePropertyImpl(n, "Noot");
    // Strings
    p1.setAnyValue("Aap");
    p2.setAnyValue("Aap");
    assertTrue(p1.isEqual(p2));
    p2.setAnyValue("Kip");
    assertFalse(p1.isEqual(p2));
    // Selections
    p1.setType("selection");
    p1.setCardinality("1");
    p1.addSelection(new BaseSelectionImpl(n, "opt1", "1", false));
    p1.addSelection(new BaseSelectionImpl(n, "opt2", "2", true));
    p1.addSelection(new BaseSelectionImpl(n, "opt3", "3", false));
    p2.setType("selection");
    p2.setCardinality("1");
    p2.addSelection(new BaseSelectionImpl(n, "opt1", "1", false));
    p2.addSelection(new BaseSelectionImpl(n, "opt2", "2", true));
    p2.addSelection(new BaseSelectionImpl(n, "opt3", "3", false));
    assertTrue(p1.isEqual(p2));
    p2.setSelected(new BaseSelectionImpl(n, "opt2", "2", true), false);
    p2.setSelected(new BaseSelectionImpl(n, "opt2", "3", true), true);
    assertFalse(p1.isEqual(p2));
    p1.setSelected(new BaseSelectionImpl(n, "opt2", "2", true), false);
    p1.setSelected(new BaseSelectionImpl(n, "opt2", "3", true), true);
    assertTrue(p1.isEqual(p2));
    // Date
    p1.setType("date");
    p1.removeAllSelections();
    p2.setType("date");
    p2.removeAllSelections();
    // these could be non-equal, right?
    p1.setAnyValue(new java.util.Date());
    p2.setAnyValue(new java.util.Date());
    assertTrue(p1.isEqual(p2));
    p2.setAnyValue(new java.util.Date(32131332L));
    assertFalse(p1.isEqual(p2));
}
Also used : BaseNavajoImpl(com.dexels.navajo.document.base.BaseNavajoImpl) BasePropertyImpl(com.dexels.navajo.document.base.BasePropertyImpl) Date(java.util.Date) BaseSelectionImpl(com.dexels.navajo.document.base.BaseSelectionImpl) Test(org.junit.Test)

Example 5 with BasePropertyImpl

use of com.dexels.navajo.document.base.BasePropertyImpl in project navajo by Dexels.

the class TestProperty method tesExpression.

@Test
public void tesExpression() {
    BaseNavajoImpl n = new BaseNavajoImpl(NavajoFactory.getInstance());
    BaseMessageImpl m = new BaseMessageImpl(n, "Aap");
    n.addMessage(m);
    BasePropertyImpl p1 = new BasePropertyImpl(n, "Noot");
    m.addProperty(p1);
    p1.setType(Property.EXPRESSION_PROPERTY);
    String illegalExpression = "123";
    p1.setValue(illegalExpression);
    String res = p1.getValue();
    assertEquals(illegalExpression, res);
// Can't really test, need an expression evaluator, which has a dep to
// Navajo
}
Also used : BaseMessageImpl(com.dexels.navajo.document.base.BaseMessageImpl) BaseNavajoImpl(com.dexels.navajo.document.base.BaseNavajoImpl) BasePropertyImpl(com.dexels.navajo.document.base.BasePropertyImpl) Test(org.junit.Test)

Aggregations

BaseNavajoImpl (com.dexels.navajo.document.base.BaseNavajoImpl)5 BasePropertyImpl (com.dexels.navajo.document.base.BasePropertyImpl)5 Test (org.junit.Test)5 BaseSelectionImpl (com.dexels.navajo.document.base.BaseSelectionImpl)3 BaseMessageImpl (com.dexels.navajo.document.base.BaseMessageImpl)2 Navajo (com.dexels.navajo.document.Navajo)1 Property (com.dexels.navajo.document.Property)1 Selection (com.dexels.navajo.document.Selection)1 Money (com.dexels.navajo.document.types.Money)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Date (java.util.Date)1