Search in sources :

Example 1 with SubordinateTrigger

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

the class AbstractCompare_Test method testGetTriggerValueInvalidTrigger.

@Test
public void testGetTriggerValueInvalidTrigger() {
    SubordinateTrigger trigger = new MyInvalidTrigger();
    AbstractCompare compare = new MyCompare(trigger, null);
    try {
        compare.execute();
        Assert.fail("Should have thrown exception for invalid subordinate trigger.");
    } catch (SystemException e) {
        Assert.assertNotNull("Exception for invalid subordinate trigger should have a message", e.getMessage());
    }
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) Test(org.junit.Test)

Example 2 with SubordinateTrigger

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

the class NotEqual_Test method testConstructor.

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

Example 3 with SubordinateTrigger

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

the class CompareExpression_Test method testBuild.

@Test
public void testBuild() {
    SubordinateTrigger trigger = new WTextField();
    String value = "test";
    // Build Equal
    CompareExpression expr = new CompareExpression(CompareType.EQUAL, trigger, value);
    Equal equal = (Equal) expr.build();
    Assert.assertEquals("Equal condition returned invalid trigger", trigger, equal.getTrigger());
    Assert.assertEquals("Equal condition returned invalid value", value, equal.getValue());
    // Build NotEqual
    expr = new CompareExpression(CompareType.NOT_EQUAL, trigger, value);
    NotEqual notEqual = (NotEqual) expr.build();
    Assert.assertEquals("NotEqual condition returned invalid trigger", trigger, notEqual.getTrigger());
    Assert.assertEquals("NotEqual condition returned invalid value", value, notEqual.getValue());
    // Build LessThan
    expr = new CompareExpression(CompareType.LESS_THAN, trigger, value);
    LessThan lessThan = (LessThan) expr.build();
    Assert.assertEquals("LessThan condition returned invalid trigger", trigger, lessThan.getTrigger());
    Assert.assertEquals("LessThan condition returned invalid value", value, lessThan.getValue());
    // Build LessThanOrEqual
    expr = new CompareExpression(CompareType.LESS_THAN_OR_EQUAL, trigger, value);
    LessThanOrEqual lessThanOrEqual = (LessThanOrEqual) expr.build();
    Assert.assertEquals("LessThanOrEqual condition returned invalid trigger", trigger, lessThanOrEqual.getTrigger());
    Assert.assertEquals("LessThanOrEqual condition returned invalid value", value, lessThanOrEqual.getValue());
    // Build GreaterThan
    expr = new CompareExpression(CompareType.GREATER_THAN, trigger, value);
    GreaterThan greaterThan = (GreaterThan) expr.build();
    Assert.assertEquals("GreaterThan condition returned invalid trigger", trigger, greaterThan.getTrigger());
    Assert.assertEquals("GreaterThan condition returned invalid value", value, greaterThan.getValue());
    // Build GreaterThanOrEqual
    expr = new CompareExpression(CompareType.GREATER_THAN_OR_EQUAL, trigger, value);
    GreaterThanOrEqual greaterThanOrEqual = (GreaterThanOrEqual) expr.build();
    Assert.assertEquals("GreaterThanOrEqual condition returned invalid trigger", trigger, greaterThanOrEqual.getTrigger());
    Assert.assertEquals("GreaterThanOrEqual condition returned invalid value", value, greaterThanOrEqual.getValue());
    // Build Match
    expr = new CompareExpression(CompareType.MATCH, trigger, value);
    Match match = (Match) expr.build();
    Assert.assertEquals("Match condition returned invalid trigger", trigger, match.getTrigger());
    Assert.assertEquals("Match condition returned invalid value", value, match.getValue());
}
Also used : LessThan(com.github.bordertech.wcomponents.subordinate.LessThan) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) Equal(com.github.bordertech.wcomponents.subordinate.Equal) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) GreaterThan(com.github.bordertech.wcomponents.subordinate.GreaterThan) SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) WTextField(com.github.bordertech.wcomponents.WTextField) Match(com.github.bordertech.wcomponents.subordinate.Match) Test(org.junit.Test)

Example 4 with SubordinateTrigger

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

the class CompareExpression_Test method testToString.

@Test
public void testToString() {
    SubordinateTrigger trigger = new WTextField();
    String value = "test";
    // Equal
    CompareExpression expr = new CompareExpression(CompareType.EQUAL, trigger, value);
    Assert.assertEquals("Incorrect toString for equals compare", "WTextField=\"test\"", expr.toString());
    // NotEqual
    expr = new CompareExpression(CompareType.NOT_EQUAL, trigger, value);
    Assert.assertEquals("Incorrect toString for not equals compare", "WTextField!=\"test\"", expr.toString());
    // LessThan
    expr = new CompareExpression(CompareType.LESS_THAN, trigger, value);
    Assert.assertEquals("Incorrect toString for less than compare", "WTextField<\"test\"", expr.toString());
    // LessThanOrEqual
    expr = new CompareExpression(CompareType.LESS_THAN_OR_EQUAL, trigger, value);
    Assert.assertEquals("Incorrect toString for less than or equal compare", "WTextField<=\"test\"", expr.toString());
    // GreaterThan
    expr = new CompareExpression(CompareType.GREATER_THAN, trigger, value);
    Assert.assertEquals("Incorrect toString for greater than compare", "WTextField>\"test\"", expr.toString());
    // GreaterThanOrEqual
    expr = new CompareExpression(CompareType.GREATER_THAN_OR_EQUAL, trigger, value);
    Assert.assertEquals("Incorrect toString for greater thanor equal compare", "WTextField>=\"test\"", expr.toString());
    // Match
    expr = new CompareExpression(CompareType.MATCH, trigger, value);
    Assert.assertEquals("Incorrect toString for match compare", "WTextField matches \"test\"", expr.toString());
    // Test when a label is associated with the field
    expr = new CompareExpression(CompareType.EQUAL, trigger, value);
    new WLabel("My test field", trigger);
    Assert.assertEquals("Incorrect toString for equals compare with label", "My test field=\"test\"", expr.toString());
}
Also used : SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) WTextField(com.github.bordertech.wcomponents.WTextField) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Example 5 with SubordinateTrigger

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

the class WSubordinateControlRenderer_Test method testMultipleControlsAndGroups.

@Test
public void testMultipleControlsAndGroups() throws IOException, SAXException, XpathException {
    SubordinateTrigger condTrigger = new WCheckBox();
    // Setup Groups
    SubordinateTarget actionTarget1 = new WTextField();
    SubordinateTarget actionTarget2 = new WTextField();
    SubordinateTarget actionTarget3 = new WTextField();
    SubordinateTarget actionTarget4 = new WTextField();
    // Multiple Groups
    WComponentGroup<SubordinateTarget> group1 = new WComponentGroup<>();
    group1.addToGroup(actionTarget1);
    group1.addToGroup(actionTarget2);
    WComponentGroup<SubordinateTarget> group2 = new WComponentGroup<>();
    group2.addToGroup(actionTarget3);
    group2.addToGroup(actionTarget4);
    // Multiple Rules
    Rule rule1 = new Rule();
    rule1.setCondition(new Equal(condTrigger, Boolean.TRUE));
    rule1.addActionOnTrue(new Show(group1));
    rule1.addActionOnFalse(new Hide(group1));
    Rule rule2 = new Rule();
    rule2.setCondition(new Equal(condTrigger, Boolean.FALSE));
    rule2.addActionOnTrue(new Show(group2));
    rule2.addActionOnFalse(new Hide(group2));
    // Setup Subordinate
    WSubordinateControl control = new WSubordinateControl();
    control.addRule(rule1);
    control.addRule(rule2);
    WContainer root = new WContainer();
    root.add(condTrigger);
    root.add(actionTarget1);
    root.add(actionTarget2);
    root.add(actionTarget3);
    root.add(actionTarget4);
    root.add(control);
    root.add(group1);
    root.add(group2);
    setActiveContext(createUIContext());
    // Apply the controls
    control.applyTheControls();
    // Validate Schema
    assertSchemaMatch(root);
    // Check for basic elements
    assertXpathEvaluatesTo("2", "count(//ui:subordinate)", root);
    assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:condition)", root);
    assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:onTrue)", root);
    assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:onFalse)", root);
    assertXpathEvaluatesTo("2", "count(//ui:componentGroup)", root);
    assertXpathEvaluatesTo("2", "count(//ui:componentGroup[position()=1]/ui:component)", root);
    assertXpathEvaluatesTo("2", "count(//ui:componentGroup[position()=2]/ui:component)", root);
    // Check ids
    assertXpathEvaluatesTo(control.getId() + "-c0", "//ui:subordinate[position()=1]/@id", root);
    assertXpathEvaluatesTo(control.getId() + "-c1", "//ui:subordinate[position()=2]/@id", 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)

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