Search in sources :

Example 11 with SubordinateTrigger

use of com.github.bordertech.wcomponents.SubordinateTrigger in project wcomponents by BorderTech.

the class WSubordinateControlRenderer_Test method testBasicConditionWithGroup.

@Test
public void testBasicConditionWithGroup() throws IOException, SAXException, XpathException {
    SubordinateTrigger condTrigger = new WCheckBox();
    // Setup Group
    SubordinateTarget actionTarget1 = new WTextField();
    SubordinateTarget actionTarget2 = new WTextField();
    SubordinateTarget actionTarget3 = new WTextField();
    WComponentGroup<SubordinateTarget> group1 = new WComponentGroup<>();
    group1.addToGroup(actionTarget1);
    group1.addToGroup(actionTarget2);
    group1.addToGroup(actionTarget3);
    // Basic Condition
    Rule rule = new Rule();
    rule.setCondition(new Equal(condTrigger, Boolean.TRUE));
    rule.addActionOnTrue(new Show(group1));
    rule.addActionOnFalse(new Hide(group1));
    // Setup Subordinate
    WSubordinateControl control = new WSubordinateControl();
    control.addRule(rule);
    WContainer root = new WContainer();
    root.add(condTrigger);
    root.add(actionTarget1);
    root.add(actionTarget2);
    root.add(actionTarget3);
    root.add(control);
    root.add(group1);
    setActiveContext(createUIContext());
    // Apply the controls
    control.applyTheControls();
    // Validate Schema
    assertSchemaMatch(root);
    // Check for basic elements
    assertXpathEvaluatesTo("1", "count(//ui:subordinate)", root);
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:condition)", root);
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:onTrue)", root);
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:onFalse)", root);
    assertXpathEvaluatesTo("1", "count(//ui:componentGroup)", root);
    assertXpathEvaluatesTo("3", "count(//ui:componentGroup/ui:component)", root);
    // Check id
    assertXpathEvaluatesTo(control.getId() + "-c0", "//ui:subordinate/@id", root);
    // Check condition
    assertXpathEvaluatesTo(condTrigger.getId(), "//ui:subordinate/ui:condition/@controller", root);
    assertXpathEvaluatesTo("true", "//ui:subordinate/ui:condition/@value", root);
    // Check onTrue
    assertXpathEvaluatesTo("show", "//ui:subordinate/ui:onTrue/@action", root);
    assertXpathEvaluatesTo(group1.getId(), "//ui:subordinate/ui:onTrue/ui:target/@groupId", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onTrue/ui:target/@id", root);
    // Check onFalse
    assertXpathEvaluatesTo("hide", "//ui:subordinate/ui:onFalse/@action", root);
    assertXpathEvaluatesTo(group1.getId(), "//ui:subordinate/ui:onFalse/ui:target/@groupId", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onFalse/ui:target/@id", root);
    // Check group
    assertXpathEvaluatesTo(group1.getId(), "//ui:componentGroup/@id", root);
    assertXpathEvaluatesTo(actionTarget1.getId(), "//ui:componentGroup/ui:component[position()=1]/@id", root);
    assertXpathEvaluatesTo(actionTarget2.getId(), "//ui:componentGroup/ui:component[position()=2]/@id", root);
    assertXpathEvaluatesTo(actionTarget3.getId(), "//ui:componentGroup/ui:component[position()=3]/@id", root);
    // Check action target
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget1.getId() + "']/@hidden", root);
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget2.getId() + "']/@hidden", root);
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget3.getId() + "']/@hidden", root);
}
Also used : Hide(com.github.bordertech.wcomponents.subordinate.Hide) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WContainer(com.github.bordertech.wcomponents.WContainer) Equal(com.github.bordertech.wcomponents.subordinate.Equal) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) Show(com.github.bordertech.wcomponents.subordinate.Show) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 12 with SubordinateTrigger

use of com.github.bordertech.wcomponents.SubordinateTrigger in project wcomponents by BorderTech.

the class WSubordinateControlRenderer_Test method testAllConditions.

@Test
public void testAllConditions() throws IOException, SAXException, XpathException {
    SubordinateTrigger condTrigger = new WNumberField();
    SubordinateTrigger condTrigger2 = new WTextField();
    SubordinateTarget actionTarget = new WTextField();
    BigDecimal value = BigDecimal.valueOf(2);
    Condition cond1 = new Equal(condTrigger, value);
    Condition cond2 = new NotEqual(condTrigger, value);
    Condition cond3 = new LessThan(condTrigger, value);
    Condition cond4 = new LessThanOrEqual(condTrigger, value);
    Condition cond5 = new GreaterThan(condTrigger, value);
    Condition cond6 = new GreaterThanOrEqual(condTrigger, value);
    Condition cond7 = new Match(condTrigger2, "[abc]");
    // Basic Condition
    Rule rule = new Rule();
    rule.setCondition(new And(cond1, cond2, cond3, cond4, cond5, cond6, cond7));
    rule.addActionOnTrue(new Show(actionTarget));
    rule.addActionOnFalse(new Hide(actionTarget));
    // Setup Subordinate
    WSubordinateControl control = new WSubordinateControl();
    control.addRule(rule);
    WContainer root = new WContainer();
    root.add(condTrigger);
    root.add(condTrigger2);
    root.add(actionTarget);
    root.add(control);
    setActiveContext(createUIContext());
    // Validate Schema
    assertSchemaMatch(root);
    assertXpathNotExists("//ui:subordinate/ui:and/ui:condition[1]/@operator", root);
    assertXpathEvaluatesTo("ne", "//ui:subordinate/ui:and/ui:condition[2]/@operator", root);
    assertXpathEvaluatesTo("lt", "//ui:subordinate/ui:and/ui:condition[3]/@operator", root);
    assertXpathEvaluatesTo("le", "//ui:subordinate/ui:and/ui:condition[4]/@operator", root);
    assertXpathEvaluatesTo("gt", "//ui:subordinate/ui:and/ui:condition[5]/@operator", root);
    assertXpathEvaluatesTo("ge", "//ui:subordinate/ui:and/ui:condition[6]/@operator", root);
    assertXpathEvaluatesTo("rx", "//ui:subordinate/ui:and/ui:condition[7]/@operator", root);
}
Also used : Condition(com.github.bordertech.wcomponents.subordinate.Condition) Hide(com.github.bordertech.wcomponents.subordinate.Hide) WContainer(com.github.bordertech.wcomponents.WContainer) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) WNumberField(com.github.bordertech.wcomponents.WNumberField) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) BigDecimal(java.math.BigDecimal) Match(com.github.bordertech.wcomponents.subordinate.Match) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) LessThan(com.github.bordertech.wcomponents.subordinate.LessThan) Equal(com.github.bordertech.wcomponents.subordinate.Equal) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) GreaterThan(com.github.bordertech.wcomponents.subordinate.GreaterThan) And(com.github.bordertech.wcomponents.subordinate.And) SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) Show(com.github.bordertech.wcomponents.subordinate.Show) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 13 with SubordinateTrigger

use of com.github.bordertech.wcomponents.SubordinateTrigger in project wcomponents by BorderTech.

the class AbstractCompare_Test method testConstructors.

@Test
public void testConstructors() {
    AbstractCompare compare;
    // --------------------------
    // Constructor - Valid Value
    SubordinateTrigger trigger = new MyInput();
    String value = "test";
    compare = new MyCompare(trigger, value);
    Assert.assertEquals("Invalid trigger returned", trigger, compare.getTrigger());
    Assert.assertEquals("Invalid compare value returned", value, compare.getValue());
    // --------------------------
    // Constructor - Null Value
    trigger = new MyInput();
    compare = new MyCompare(trigger, null);
    Assert.assertEquals("Invalid trigger returned", trigger, compare.getTrigger());
    Assert.assertNull("Invalid compare value returned", compare.getValue());
    // Constructor - Null Trigger
    try {
        compare = new MyCompare(null, "Test");
        Assert.fail("A null trigger should not be allowed");
    } catch (IllegalArgumentException e) {
        Assert.assertNotNull("Exception message for null trigger should not be null", e.getMessage());
    }
    // --------------------------
    // Constructor - DateField and Valid Value
    SubordinateTrigger dateTrigger = new WDateField();
    Date dateValue = new Date();
    compare = new MyCompare(dateTrigger, dateValue);
    Assert.assertEquals("Invalid date trigger returned", dateTrigger, compare.getTrigger());
    Assert.assertEquals("Invalid date compare value returned", dateValue, compare.getValue());
    // Constructor - DateField and Invalid Value
    try {
        compare = new MyCompare(new WDateField(), "Invalid Date");
        Assert.fail("A datefield trigger and invalid date value should not be allowed");
    } catch (IllegalArgumentException e) {
        Assert.assertNotNull("Exception message for datefield trigger and invalid date should not be null", e.getMessage());
    }
    // --------------------------
    // Constructor - NumberField and Valid Value
    SubordinateTrigger numberTrigger = new WNumberField();
    BigDecimal numberValue = BigDecimal.valueOf(5);
    compare = new MyCompare(numberTrigger, numberValue);
    Assert.assertEquals("Invalid number trigger returned", numberTrigger, compare.getTrigger());
    Assert.assertEquals("Invalid number compare value returned", numberValue, compare.getValue());
    // Constructor - NumberField and Invalid Value
    try {
        compare = new MyCompare(new WNumberField(), "Invalid Number");
        Assert.fail("A numberField trigger and invalid number value should not be allowed");
    } catch (IllegalArgumentException e) {
        Assert.assertNotNull("Exception message for numberField trigger and invalid number should not be null", e.getMessage());
    }
}
Also used : WNumberField(com.github.bordertech.wcomponents.WNumberField) SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) WDateField(com.github.bordertech.wcomponents.WDateField) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 14 with SubordinateTrigger

use of com.github.bordertech.wcomponents.SubordinateTrigger in project wcomponents by BorderTech.

the class Equal_Test method testConstructor.

@Test
public void testConstructor() {
    SubordinateTrigger trigger = new MyTrigger();
    Object value = new Object();
    Equal compare = new Equal(trigger, value);
    Assert.assertEquals("Value for Equal is incorrect", value, compare.getValue());
    Assert.assertEquals("Trigger for Equal should be the trigger", trigger, compare.getTrigger());
}
Also used : SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) Test(org.junit.Test)

Example 15 with SubordinateTrigger

use of com.github.bordertech.wcomponents.SubordinateTrigger in project wcomponents by BorderTech.

the class GreaterThanOrEqual_Test method testConstructor.

@Test
public void testConstructor() {
    SubordinateTrigger trigger = new MyTrigger();
    Object value = new Object();
    GreaterThanOrEqual compare = new GreaterThanOrEqual(trigger, value);
    Assert.assertEquals("Value for GreaterThanOrEqual is incorrect", value, compare.getValue());
    Assert.assertEquals("Trigger for GreaterThanOrEqual should be the trigger", trigger, compare.getTrigger());
}
Also used : SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) Test(org.junit.Test)

Aggregations

SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)23 Test (org.junit.Test)23 WTextField (com.github.bordertech.wcomponents.WTextField)14 Equal (com.github.bordertech.wcomponents.subordinate.Equal)12 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)12 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)12 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)12 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)11 WContainer (com.github.bordertech.wcomponents.WContainer)11 Rule (com.github.bordertech.wcomponents.subordinate.Rule)11 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)11 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)10 Hide (com.github.bordertech.wcomponents.subordinate.Hide)8 Show (com.github.bordertech.wcomponents.subordinate.Show)8 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)6 Condition (com.github.bordertech.wcomponents.subordinate.Condition)4 And (com.github.bordertech.wcomponents.subordinate.And)3 WNumberField (com.github.bordertech.wcomponents.WNumberField)2 GreaterThan (com.github.bordertech.wcomponents.subordinate.GreaterThan)2 LessThan (com.github.bordertech.wcomponents.subordinate.LessThan)2