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);
}
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);
}
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());
}
}
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());
}
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());
}
Aggregations