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