use of com.github.bordertech.wcomponents.WTextField in project wcomponents by BorderTech.
the class EnableInGroup_Test method testActionType.
@Test
public void testActionType() {
SubordinateTarget target = new WTextField();
WComponentGroup<SubordinateTarget> group = new WComponentGroup<>();
group.addToGroup(target);
EnableInGroup action = new EnableInGroup(target, group);
Assert.assertEquals("Incorrect Action Type", action.getActionType(), AbstractAction.ActionType.ENABLEIN);
}
use of com.github.bordertech.wcomponents.WTextField in project wcomponents by BorderTech.
the class Rule_Test method testToString.
@Test
public void testToString() {
WCheckBox box = new WCheckBox();
SubordinateTarget target = new WTextField();
Rule rule = new Rule();
// No condition and actions
Assert.assertEquals("Incorrect toString for RULE with no conditions and actions", "if (null)\nthen\n []\nelse\n []\n", rule.toString());
// With Conditions and actions;
rule.setCondition(new Equal(box, Boolean.TRUE));
rule.addActionOnTrue(new Hide(target));
rule.addActionOnFalse(new Show(target));
Assert.assertEquals("Incorrect toString for RULE", "if (WCheckBox=\"true\")\nthen\n [hide WTextField]\nelse\n [show WTextField]\n", rule.toString());
}
use of com.github.bordertech.wcomponents.WTextField in project wcomponents by BorderTech.
the class Rule_Test method testExecuteRule.
@Test
public void testExecuteRule() {
WCheckBox box = new WCheckBox();
WTextField target = new WTextField();
// Create Rule
Rule rule = new Rule();
rule.setCondition(new Equal(box, Boolean.TRUE));
rule.addActionOnTrue(new Hide(target));
rule.addActionOnFalse(new Show(target));
// Test TRUE Action (Hide target)
setFlag(target, ComponentModel.HIDE_FLAG, false);
box.setSelected(true);
rule.execute();
Assert.assertTrue("True condition should Hide Target", target.isHidden());
// Test FALSE Action (Show target)
setFlag(target, ComponentModel.HIDE_FLAG, true);
box.setSelected(false);
rule.execute();
Assert.assertFalse("False condition should Show Target", target.isHidden());
}
use of com.github.bordertech.wcomponents.WTextField in project wcomponents by BorderTech.
the class Rule_Test method testExecuteRuleWithRequest.
@Test
public void testExecuteRuleWithRequest() {
WCheckBox box = new WCheckBox();
WTextField target = new WTextField();
// Create Rule
Rule rule = new Rule();
rule.setCondition(new Equal(box, Boolean.TRUE));
rule.addActionOnTrue(new Hide(target));
rule.addActionOnFalse(new Show(target));
// Test TRUE Action (Hide target)
setActiveContext(createUIContext());
MockRequest request = new MockRequest();
setFlag(target, ComponentModel.HIDE_FLAG, false);
// CheckBox selected in Request
setupCheckBoxRequest(box, request, true);
rule.execute(request);
Assert.assertTrue("True condition should Hide Target", target.isHidden());
// Test FALSE Action (Show target)
setActiveContext(createUIContext());
request = new MockRequest();
setFlag(target, ComponentModel.HIDE_FLAG, true);
// CheckBox not selected in Request
setupCheckBoxRequest(box, request, false);
rule.execute(request);
Assert.assertFalse("False condition should Show Target", target.isHidden());
}
use of com.github.bordertech.wcomponents.WTextField in project wcomponents by BorderTech.
the class Rule_Test method testConstructors.
@Test
public void testConstructors() {
Condition cond = new Equal(new WCheckBox(), null);
Action onTrue = new Hide(new WTextField());
Action onFalse = new Hide(new WTextField());
// Constructor - 1
Rule rule = new Rule();
Assert.assertNull("Constructor 1: Condition should be null", rule.getCondition());
Assert.assertTrue("Constructor 1: onTrue actions should be empty", rule.getOnTrue().isEmpty());
Assert.assertTrue("Constructor 1: onFalse actions should be empty", rule.getOnFalse().isEmpty());
// Constructor - 2
rule = new Rule(cond);
Assert.assertEquals("Constructor 2: Incorrect condition returned", cond, rule.getCondition());
Assert.assertTrue("Constructor 2: onTrue actions should be empty", rule.getOnTrue().isEmpty());
Assert.assertTrue("Constructor 2: onFalse actions should be empty", rule.getOnFalse().isEmpty());
// Constructor - 3
rule = new Rule(cond, onTrue);
Assert.assertEquals("Constructor 3: Incorrect condition returned", cond, rule.getCondition());
Assert.assertEquals("Constructor 3: onTrue actions list should have 1 item", 1, rule.getOnTrue().size());
Assert.assertEquals("Constructor 3: Item 1 in onTrue actions list is incorrect", onTrue, rule.getOnTrue().get(0));
Assert.assertTrue("Constructor 3: onFalse actions should be empty", rule.getOnFalse().isEmpty());
// Constructor - 4
rule = new Rule(cond, onTrue, onFalse);
Assert.assertEquals("Constructor 4: Incorrect condition returned", cond, rule.getCondition());
Assert.assertEquals("Constructor 4: onTrue actions list should have 1 item", 1, rule.getOnTrue().size());
Assert.assertEquals("Constructor 4: Item 1 in onTrue actions list is incorrect", onTrue, rule.getOnTrue().get(0));
Assert.assertEquals("Constructor 4: onFalse actions list should have 1 item", 1, rule.getOnFalse().size());
Assert.assertEquals("Constructor 4: Item 1 in onFalse actions list is incorrect", onFalse, rule.getOnFalse().get(0));
}
Aggregations