Search in sources :

Example 26 with Selection

use of com.dexels.navajo.document.Selection in project navajo by Dexels.

the class TestProperty method tesClearSelections.

@Test
public void tesClearSelections() {
    Property testSelectionProp = NavajoFactory.getInstance().createProperty(testDoc, "testselectionproperty", "+", "", Property.DIR_IN);
    Selection s1 = NavajoFactory.getInstance().createSelection(testDoc, "firstselection", "0", true);
    Selection s2 = NavajoFactory.getInstance().createSelection(testDoc, "secondselection", "1", false);
    Selection s3 = NavajoFactory.getInstance().createSelection(testDoc, "thirdselection", "2", false);
    testSelectionProp.addSelection(s1);
    testSelectionProp.addSelection(s2);
    testSelectionProp.addSelection(s3);
    testSelectionProp.clearSelections();
    Iterator<Selection> iter = testSelectionProp.getAllSelections().iterator();
    while (iter.hasNext()) {
        Selection s = iter.next();
        Assert.assertTrue(!s.isSelected());
    }
}
Also used : Selection(com.dexels.navajo.document.Selection) Property(com.dexels.navajo.document.Property) Test(org.junit.Test)

Example 27 with Selection

use of com.dexels.navajo.document.Selection in project navajo by Dexels.

the class TestProperty method tesAddSelectionWithoutReplace.

@Test
public void tesAddSelectionWithoutReplace() {
    Property testSelectionProp = NavajoFactory.getInstance().createProperty(testDoc, "testselectionproperty", "+", "", Property.DIR_IN);
    Selection s1 = NavajoFactory.getInstance().createSelection(testDoc, "firstselection", "0", true);
    testSelectionProp.addSelectionWithoutReplace(s1);
    Selection s2 = testSelectionProp.getSelection("firstselection");
    Assert.assertNotNull(s2);
    Assert.assertEquals(s2.isSelected(), s1.isSelected());
    Assert.assertEquals(s2.getName(), s1.getName());
    Assert.assertEquals(s2.getValue(), s1.getValue());
    Selection s3 = NavajoFactory.getInstance().createSelection(testDoc, "firstselection", "1", false);
    testSelectionProp.addSelectionWithoutReplace(s3);
    int count = 0;
    List<Selection> all = testSelectionProp.getAllSelections();
    for (int i = 0; i < all.size(); i++) {
        if ((all.get(i)).getName().equals("firstselection"))
            count++;
    }
    Assert.assertEquals(2, count);
}
Also used : Selection(com.dexels.navajo.document.Selection) Property(com.dexels.navajo.document.Property) Test(org.junit.Test)

Example 28 with Selection

use of com.dexels.navajo.document.Selection 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 29 with Selection

use of com.dexels.navajo.document.Selection in project navajo by Dexels.

the class TestProperty method tesSetSelected1.

@Test
public void tesSetSelected1() {
    Property testSelectionProp1 = NavajoFactory.getInstance().createProperty(testDoc, "testselectionproperty", "+", "mydesc", Property.DIR_IN);
    Selection s1 = NavajoFactory.getInstance().createSelection(testDoc, "myselection1", "0", false);
    Selection s2 = NavajoFactory.getInstance().createSelection(testDoc, "myselection2", "1", false);
    Selection s3 = NavajoFactory.getInstance().createSelection(testDoc, "myselection3", "2", false);
    Selection s4 = NavajoFactory.getInstance().createSelection(testDoc, "myselection4", "3", false);
    testSelectionProp1.addSelection(s1);
    testSelectionProp1.addSelection(s2);
    testSelectionProp1.addSelection(s3);
    testSelectionProp1.addSelection(s4);
    testSelectionProp1.setSelected(new String[] { "0", "3" });
    Assert.assertTrue(s1.isSelected());
    Assert.assertTrue(s4.isSelected());
    Assert.assertTrue(!s2.isSelected());
    Assert.assertTrue(!s3.isSelected());
}
Also used : Selection(com.dexels.navajo.document.Selection) Property(com.dexels.navajo.document.Property) Test(org.junit.Test)

Example 30 with Selection

use of com.dexels.navajo.document.Selection in project navajo by Dexels.

the class TestProperty method testCopy.

@Test
public void testCopy() {
    Navajo n = NavajoFactory.getInstance().createNavajo();
    Selection s1 = NavajoFactory.getInstance().createSelection(n, "aap", "aap", "0");
    Selection s2 = NavajoFactory.getInstance().createSelection(n, "noot", "noot", "1");
    Property p = NavajoFactory.getInstance().createProperty(n, "Selectie", "+", "", "out");
    p.addSelection(s1);
    p.addSelection(s2);
    Message m = NavajoFactory.getInstance().createMessage(n, "Soep");
    n.addMessage(m);
    m.addProperty(p);
    Navajo n2 = NavajoFactory.getInstance().createNavajo();
    p.copy(n2);
}
Also used : Message(com.dexels.navajo.document.Message) Selection(com.dexels.navajo.document.Selection) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property) Test(org.junit.Test)

Aggregations

Selection (com.dexels.navajo.document.Selection)78 Property (com.dexels.navajo.document.Property)36 Test (org.junit.Test)32 Message (com.dexels.navajo.document.Message)24 Navajo (com.dexels.navajo.document.Navajo)21 Access (com.dexels.navajo.script.api.Access)14 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)13 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)12 TipiLink (com.dexels.navajo.expression.api.TipiLink)12 MappableTreeNode (com.dexels.navajo.script.api.MappableTreeNode)12 ArrayList (java.util.ArrayList)12 Optional (java.util.Optional)12 Operand (com.dexels.navajo.document.Operand)11 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)11 List (java.util.List)8 NavajoException (com.dexels.navajo.document.NavajoException)6 UserException (com.dexels.navajo.script.api.UserException)4 Binary (com.dexels.navajo.document.types.Binary)3 FunctionClassification (com.dexels.navajo.expression.api.FunctionClassification)3 StringTokenizer (java.util.StringTokenizer)3