Search in sources :

Example 36 with WCheckBox

use of com.github.bordertech.wcomponents.WCheckBox in project wcomponents by BorderTech.

the class WSubordinateControlRenderer_Test method testOrCondition.

@Test
public void testOrCondition() throws IOException, SAXException, XpathException {
    SubordinateTrigger condTrigger1 = new WCheckBox();
    SubordinateTrigger condTrigger2 = new WCheckBox();
    SubordinateTrigger condTrigger3 = new WCheckBox();
    // Create OR condition
    Condition cond1 = new Equal(condTrigger1, Boolean.TRUE);
    Condition cond2 = new Equal(condTrigger2, Boolean.TRUE);
    Condition cond3 = new Equal(condTrigger3, Boolean.TRUE);
    Condition orTest = new Or(cond1, cond2, cond3);
    SubordinateTarget actionTarget = new WTextField();
    // Setup rule with OR condition
    Rule rule = new Rule();
    rule.setCondition(orTest);
    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(condTrigger1);
    root.add(condTrigger2);
    root.add(condTrigger3);
    root.add(actionTarget);
    root.add(control);
    // Apply the controls
    control.applyTheControls();
    // Validate Schema
    assertSchemaMatch(root);
    // Check OR
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:or)", root);
    assertXpathEvaluatesTo("3", "count(//ui:subordinate/ui:or/ui:condition)", root);
    assertXpathEvaluatesTo(condTrigger1.getId(), "//ui:subordinate/ui:or/ui:condition[position()=1]/@controller", root);
    assertXpathEvaluatesTo(condTrigger2.getId(), "//ui:subordinate/ui:or/ui:condition[position()=2]/@controller", root);
    assertXpathEvaluatesTo(condTrigger3.getId(), "//ui:subordinate/ui:or/ui:condition[position()=3]/@controller", root);
    // Check action target
    assertXpathEvaluatesTo("true", "//ui:textfield/@hidden", root);
}
Also used : Condition(com.github.bordertech.wcomponents.subordinate.Condition) Hide(com.github.bordertech.wcomponents.subordinate.Hide) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WContainer(com.github.bordertech.wcomponents.WContainer) Or(com.github.bordertech.wcomponents.subordinate.Or) Equal(com.github.bordertech.wcomponents.subordinate.Equal) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) Show(com.github.bordertech.wcomponents.subordinate.Show) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 37 with WCheckBox

use of com.github.bordertech.wcomponents.WCheckBox in project wcomponents by BorderTech.

the class WSubordinateControlRenderer_Test method testMandatoryOptionalActions.

@Test
public void testMandatoryOptionalActions() throws IOException, SAXException, XpathException {
    WCheckBox condTrigger = new WCheckBox();
    // Setup Group
    SubordinateTarget actionTarget = new WTextField();
    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);
    // Setup Rule with Mandatory/Optional actions
    Rule rule = new Rule();
    rule.setCondition(new Equal(condTrigger, Boolean.TRUE));
    // Single Component Target
    rule.addActionOnTrue(new Mandatory(actionTarget));
    rule.addActionOnFalse(new Optional(actionTarget));
    // Group Target
    rule.addActionOnTrue(new Mandatory(group1));
    rule.addActionOnFalse(new Optional(group1));
    // Setup Subordinate
    WSubordinateControl control = new WSubordinateControl();
    control.addRule(rule);
    WContainer root = new WContainer();
    root.add(condTrigger);
    root.add(actionTarget);
    root.add(actionTarget1);
    root.add(actionTarget2);
    root.add(actionTarget3);
    root.add(control);
    root.add(group1);
    setActiveContext(createUIContext());
    condTrigger.setSelected(true);
    // Apply the controls
    control.applyTheControls();
    // Validate Schema
    assertSchemaMatch(root);
    // Check onTrue
    assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:onTrue)", root);
    // Check onTrue - Component
    assertXpathEvaluatesTo("mandatory", "//ui:subordinate/ui:onTrue[position()=1]/@action", root);
    assertXpathEvaluatesTo(actionTarget.getId(), "//ui:subordinate/ui:onTrue[position()=1]/ui:target/@id", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onTrue[position()=1]/ui:target/@groupId", root);
    // Check onTrue - Group
    assertXpathEvaluatesTo("mandatory", "//ui:subordinate/ui:onTrue[position()=2]/@action", root);
    assertXpathEvaluatesTo(group1.getId(), "//ui:subordinate/ui:onTrue[position()=2]/ui:target/@groupId", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onTrue[position()=2]/ui:target/@id", root);
    // Check onFalse
    assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:onFalse)", root);
    // Check onFalse - Component
    assertXpathEvaluatesTo("optional", "//ui:subordinate/ui:onFalse[position()=1]/@action", root);
    assertXpathEvaluatesTo(actionTarget.getId(), "//ui:subordinate/ui:onFalse[position()=1]/ui:target/@id", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onFalse[position()=1]/ui:target/@groupId", root);
    // Check onFalse - Group
    assertXpathEvaluatesTo("optional", "//ui:subordinate/ui:onFalse[position()=2]/@action", root);
    assertXpathEvaluatesTo(group1.getId(), "//ui:subordinate/ui:onFalse[position()=2]/ui:target/@groupId", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onFalse[position()=2]/ui:target/@id", root);
    // Check action target
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget.getId() + "']/@required", root);
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget1.getId() + "']/@required", root);
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget2.getId() + "']/@required", root);
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget3.getId() + "']/@required", root);
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WContainer(com.github.bordertech.wcomponents.WContainer) Optional(com.github.bordertech.wcomponents.subordinate.Optional) Equal(com.github.bordertech.wcomponents.subordinate.Equal) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) Mandatory(com.github.bordertech.wcomponents.subordinate.Mandatory) Test(org.junit.Test)

Example 38 with WCheckBox

use of com.github.bordertech.wcomponents.WCheckBox in project wcomponents by BorderTech.

the class WCheckBoxRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WCheckBox wcbTest = new WCheckBox();
    WComponentGroup<WCheckBox> group = new WComponentGroup<>();
    WButton button = new WButton("test");
    WContainer root = new WContainer();
    root.add(wcbTest);
    root.add(group);
    root.add(button);
    setActiveContext(createUIContext());
    assertSchemaMatch(wcbTest);
    assertXpathExists("//ui:checkbox", wcbTest);
    assertXpathEvaluatesTo(wcbTest.getId(), "//ui:checkbox/@id", wcbTest);
    // Check groupName
    assertXpathNotExists("//ui:checkbox/@groupName", wcbTest);
    wcbTest.setGroup(group);
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo(group.getId(), "//ui:checkbox/@groupName", wcbTest);
    // Check disabled
    assertXpathNotExists("//ui:checkbox/@disabled", wcbTest);
    wcbTest.setDisabled(true);
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo("true", "//ui:checkbox/@disabled", wcbTest);
    // Check hidden
    assertXpathNotExists("//ui:checkbox/@hidden", wcbTest);
    setFlag(wcbTest, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo("true", "//ui:checkbox/@hidden", wcbTest);
    // Check required
    assertXpathNotExists("//ui:checkbox/@required", wcbTest);
    wcbTest.setMandatory(true);
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo("true", "//ui:checkbox/@required", wcbTest);
    // Check selected
    assertXpathNotExists("//ui:checkbox/@selected", wcbTest);
    wcbTest.setSelected(true);
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo("true", "//ui:checkbox/@selected", wcbTest);
    // Check submitOnChange
    assertXpathNotExists("//ui:checkbox/@submitOnChange", wcbTest);
    wcbTest.setSubmitOnChange(true);
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo("true", "//ui:checkbox/@submitOnChange", wcbTest);
    // Check toolTip
    assertXpathNotExists("//ui:checkbox/@toolTip", wcbTest);
    wcbTest.setToolTip("WCheckBox_Test.testRenderedFormat.title");
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo(wcbTest.getToolTip(), "//ui:checkbox/@toolTip", wcbTest);
    // Check accessibleText
    assertXpathNotExists("//ui:checkbox/@accessibleText", wcbTest);
    wcbTest.setAccessibleText("WCheckBox_Test.testRenderedFormat.accessibleText");
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo(wcbTest.getAccessibleText(), "//ui:checkbox/@accessibleText", wcbTest);
    // Check button id
    assertXpathNotExists("//ui:checkbox/@buttonId", wcbTest);
    wcbTest.setDefaultSubmitButton(button);
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo(button.getId(), "//ui:checkbox/@buttonId", wcbTest);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 39 with WCheckBox

use of com.github.bordertech.wcomponents.WCheckBox in project wcomponents by BorderTech.

the class WCheckBoxRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WCheckBox component = new WCheckBox();
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(component) instanceof WCheckBoxRenderer);
}
Also used : WCheckBox(com.github.bordertech.wcomponents.WCheckBox) Test(org.junit.Test)

Example 40 with WCheckBox

use of com.github.bordertech.wcomponents.WCheckBox in project wcomponents by BorderTech.

the class WCheckBoxRenderer_Test method testReadOnly.

@Test
public void testReadOnly() throws IOException, SAXException, XpathException {
    WCheckBox wcbTest = new WCheckBox();
    // Check readOnly
    assertXpathNotExists("//ui:checkbox/@readOnly", wcbTest);
    wcbTest.setReadOnly(true);
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo("true", "//ui:checkbox/@readOnly", wcbTest);
}
Also used : WCheckBox(com.github.bordertech.wcomponents.WCheckBox) Test(org.junit.Test)

Aggregations

WCheckBox (com.github.bordertech.wcomponents.WCheckBox)42 Test (org.junit.Test)35 WTextField (com.github.bordertech.wcomponents.WTextField)21 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)18 WContainer (com.github.bordertech.wcomponents.WContainer)17 Equal (com.github.bordertech.wcomponents.subordinate.Equal)13 Rule (com.github.bordertech.wcomponents.subordinate.Rule)13 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)13 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)12 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)11 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)11 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)11 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)10 Hide (com.github.bordertech.wcomponents.subordinate.Hide)7 Show (com.github.bordertech.wcomponents.subordinate.Show)7 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)5 WHeading (com.github.bordertech.wcomponents.WHeading)3 WLabel (com.github.bordertech.wcomponents.WLabel)3 Condition (com.github.bordertech.wcomponents.subordinate.Condition)3 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)3