use of com.github.bordertech.wcomponents.WCheckBox 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.WCheckBox 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));
}
use of com.github.bordertech.wcomponents.WCheckBox 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());
}
}
use of com.github.bordertech.wcomponents.WCheckBox in project wcomponents by BorderTech.
the class SubordinateBuilder_Test method testShowIn.
@Test
public void testShowIn() {
SubordinateBuilder builder = new SubordinateBuilder();
WCheckBox input1 = new WCheckBox();
WCheckBox input2 = new WCheckBox();
WCheckBox input3 = new WCheckBox();
WComponentGroup<SubordinateTarget> group = new WComponentGroup<>();
group.addToGroup(input1);
group.addToGroup(input2);
group.addToGroup(input3);
// True Condition
builder.condition().equals(new WCheckBox(), "false");
// ShowIn Action
builder.whenTrue().showIn(input2, group);
setActiveContext(createUIContext());
// Set initial states (opposite to end state)
setFlag(input1, ComponentModel.HIDE_FLAG, false);
setFlag(input2, ComponentModel.HIDE_FLAG, true);
setFlag(input3, ComponentModel.HIDE_FLAG, false);
Assert.assertFalse("showIn - Input1 Component should not be hidden", input1.isHidden());
Assert.assertTrue("showIn - Input2 Component should be initially hidden", input2.isHidden());
Assert.assertFalse("showIn - Input3 Component should not be hidden", input3.isHidden());
builder.build().applyTheControls();
Assert.assertTrue("showIn - Input1 Component should be hidden", input1.isHidden());
Assert.assertFalse("showIn - Input2 Component should not be hidden", input2.isHidden());
Assert.assertTrue("showIn - Input3 Component should be hidden", input3.isHidden());
}
use of com.github.bordertech.wcomponents.WCheckBox in project wcomponents by BorderTech.
the class SubordinateBuilder_Test method testEnableIn.
@Test
public void testEnableIn() {
SubordinateBuilder builder = new SubordinateBuilder();
WCheckBox input1 = new WCheckBox();
WCheckBox input2 = new WCheckBox();
WCheckBox input3 = new WCheckBox();
WComponentGroup<SubordinateTarget> group = new WComponentGroup<>();
group.addToGroup(input1);
group.addToGroup(input2);
group.addToGroup(input3);
// True Condition
builder.condition().equals(new WCheckBox(), "false");
// EnableIn Action
builder.whenTrue().enableIn(input2, group);
setActiveContext(createUIContext());
// Set initial states (opposite to end state)
input1.setDisabled(false);
input2.setDisabled(true);
input3.setDisabled(false);
Assert.assertFalse("enableIn - Input1 Component should be enabled", input1.isDisabled());
Assert.assertTrue("enableIn - Input2 Component should be disabled", input2.isDisabled());
Assert.assertFalse("enableIn - Input3 Component should be enabled", input3.isDisabled());
builder.build().applyTheControls();
Assert.assertTrue("enableIn - Input1 Component should be disabled", input1.isDisabled());
Assert.assertFalse("enableIn - Input2 Component should be enabled", input2.isDisabled());
Assert.assertTrue("enableIn - Input3 Component should be disabled", input3.isDisabled());
}
Aggregations