Search in sources :

Example 81 with WTextField

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

the class Rule_Test method testAccessors.

@Test
public void testAccessors() {
    Condition cond = new Equal(new WCheckBox(), null);
    Action onTrue1 = new Hide(new WTextField());
    Action onTrue2 = new Hide(new WTextField());
    Action onFalse1 = new Hide(new WTextField());
    Action onFalse2 = new Hide(new WTextField());
    Rule rule = new Rule();
    // Condition
    Assert.assertNull("Condition should be null", rule.getCondition());
    rule.setCondition(cond);
    Assert.assertEquals("Incorrect condition returned", cond, rule.getCondition());
    // OnTrue Actions
    Assert.assertTrue("onTrue actions should be empty", rule.getOnTrue().isEmpty());
    rule.addActionOnTrue(onTrue1);
    Assert.assertEquals("onTrue actions list should have 1 item", 1, rule.getOnTrue().size());
    Assert.assertEquals("Item 1 in onTrue actions list is incorrect", onTrue1, rule.getOnTrue().get(0));
    rule.addActionOnTrue(onTrue2);
    Assert.assertEquals("onTrue actions list should have 2 items", 2, rule.getOnTrue().size());
    Assert.assertEquals("Item 1 in onTrue actions list is incorrect", onTrue1, rule.getOnTrue().get(0));
    Assert.assertEquals("Item 2 in onTrue actions list is incorrect", onTrue2, rule.getOnTrue().get(1));
    try {
        rule.addActionOnTrue(null);
        Assert.fail("Should not be able to add a null action.");
    } catch (IllegalArgumentException e) {
        Assert.assertNotNull("Invalid exception message for adding null action", e.getMessage());
    }
    // OnFalse Actions
    Assert.assertTrue("onFalse actions should be empty", rule.getOnFalse().isEmpty());
    rule.addActionOnFalse(onFalse1);
    Assert.assertEquals("onFalse actions list should have 1 item", 1, rule.getOnFalse().size());
    Assert.assertEquals("Item 1 in onFalse actions list is incorrect", onFalse1, rule.getOnFalse().get(0));
    rule.addActionOnFalse(onFalse2);
    Assert.assertEquals("onFalse actions list should have 2 item", 2, rule.getOnFalse().size());
    Assert.assertEquals("Item 1 in onFalse actions list is incorrect", onFalse1, rule.getOnFalse().get(0));
    Assert.assertEquals("Item 2 in onFalse actions list is incorrect", onFalse2, rule.getOnFalse().get(1));
    try {
        rule.addActionOnFalse(null);
        Assert.fail("Should not be able to add a null action.");
    } catch (IllegalArgumentException e) {
        Assert.assertNotNull("Invalid exception message for adding null action", e.getMessage());
    }
}
Also used : WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 82 with WTextField

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

the class CompareExpression_Test method testConstructor.

@Test
public void testConstructor() {
    SubordinateTrigger trigger = new WTextField();
    String value = "test";
    CompareExpression expr = new CompareExpression(CompareType.MATCH, trigger, value);
    Assert.assertEquals("Incorrect type", CompareType.MATCH, expr.getType());
    Assert.assertEquals("Incorrect trigger", trigger, expr.getTrigger());
    Assert.assertEquals("Incorrect value", value, expr.getValue());
}
Also used : SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 83 with WTextField

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

the class CompareExpression_Test method testEvaluate.

@Test
public void testEvaluate() {
    // Setup a true "equals" condition
    CompareExpression expr = new CompareExpression(CompareType.EQUAL, new WTextField(), null);
    Assert.assertTrue("Evaluate for true compare should be true", expr.evaluate());
    // Setup a false "equals" condition
    expr = new CompareExpression(CompareType.EQUAL, new WTextField(), "not true");
    Assert.assertFalse("Evaluate for false compare should be false", expr.evaluate());
}
Also used : WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 84 with WTextField

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

the class ExpressionBuilder_Test method testBuildLessThanOrEquals.

@Test
public void testBuildLessThanOrEquals() {
    builder.lessThanOrEquals(new WTextField(), "1");
    Assert.assertEquals("Incorrect condition", "WTextField<=\"1\"", builder.build().toString());
}
Also used : WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 85 with WTextField

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

the class ExpressionBuilder_Test method testThreeArgOrCondition.

@Test
public void testThreeArgOrCondition() {
    builder.equals(new WTextField(), "1").or().equals(new WTextArea(), "2").or().equals(new WDropdown(), "3");
    Assert.assertEquals("Incorrect condition", "(WTextField=\"1\" or WTextArea=\"2\" or WDropdown=\"3\")", builder.build().toString());
}
Also used : WTextArea(com.github.bordertech.wcomponents.WTextArea) WDropdown(com.github.bordertech.wcomponents.WDropdown) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Aggregations

WTextField (com.github.bordertech.wcomponents.WTextField)117 Test (org.junit.Test)90 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)21 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)21 WContainer (com.github.bordertech.wcomponents.WContainer)21 Equal (com.github.bordertech.wcomponents.subordinate.Equal)16 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)15 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)15 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)15 Rule (com.github.bordertech.wcomponents.subordinate.Rule)15 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)15 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)14 WTextArea (com.github.bordertech.wcomponents.WTextArea)14 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)12 WDropdown (com.github.bordertech.wcomponents.WDropdown)12 WButton (com.github.bordertech.wcomponents.WButton)11 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)11 WHeading (com.github.bordertech.wcomponents.WHeading)10 WLabel (com.github.bordertech.wcomponents.WLabel)10 Hide (com.github.bordertech.wcomponents.subordinate.Hide)10