use of com.github.bordertech.wcomponents.subordinate.GreaterThan 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.subordinate.GreaterThan 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.subordinate.GreaterThan in project wcomponents by BorderTech.
the class SubordinateControlOptionsExample method createCondition.
/**
* @return the condition for the subordinate control.
*/
private Condition createCondition() {
// Compare value
Object value;
switch((TriggerType) drpTriggerType.getSelected()) {
case DATEFIELD:
value = dateCompareValue.getValue();
break;
case NUMBERFIELD:
value = numberCompareValue.getValue();
break;
default:
value = comboCompareValue.getValue();
break;
}
// Create condition
Condition condition;
switch((CompareType) drpCompareType.getSelected()) {
case EQUAL:
condition = new Equal(trigger, value);
break;
case NOT_EQUAL:
condition = new NotEqual(trigger, value);
break;
case LESS_THAN:
condition = new LessThan(trigger, value);
break;
case LESS_THAN_OR_EQUAL:
condition = new LessThanOrEqual(trigger, value);
break;
case GREATER_THAN:
condition = new GreaterThan(trigger, value);
break;
case GREATER_THAN_OR_EQUAL:
condition = new GreaterThanOrEqual(trigger, value);
break;
case MATCH:
condition = new Match(trigger, (String) value);
break;
default:
throw new SystemException("Compare type not valid");
}
return condition;
}
Aggregations