/** * Creates a WSection with the given heading. * * @param heading the section's heading. */ public WSection(final String heading) { this(new WPanel(), new WDecoratedLabel(heading)); }
@Test public void testConstructors() { // Constructor - 1 WPanel panel = new WPanel(); Assert.assertEquals("Incorrect default type returned", WPanel.Type.PLAIN, panel.getType()); // Constructor - 2 panel = new WPanel(WPanel.Type.CHROME); Assert.assertEquals("Incorrect type returned", WPanel.Type.CHROME, panel.getType()); }
/** * Creates a DisplayComponent. */ public DisplayComponent() { add(name); add(count); // Add a "Close" button, to return to the previous view. WPanel buttonPanel = new WPanel(WPanel.Type.ACTION); WButton closeBtn = new WButton("Close", 'C'); buttonPanel.add(closeBtn); add(buttonPanel); }
@Test public void testTypeAccessors() { assertAccessorsCorrect(new WPanel(), "type", WPanel.Type.PLAIN, WPanel.Type.CHROME, WPanel.Type.BOX); }
/** * Creates an ExamplePanel. */ ExampleSection() { super(new WPanel(), new WDecoratedLabel(null, new WText("No Selection"), new WContainer())); buildUI(); }
@Test public void testDefaultSubmitButtonAccessors() { WPanel panel = new WPanel(); WButton button = new WButton(); panel.setDefaultSubmitButton(button); Assert.assertEquals("Incorrect button returned", button, panel.getDefaultSubmitButton()); }
@Test public void testAddTarget() { AjaxTarget target1 = new WPanel(); AjaxTarget target2 = new WPanel(); WAjaxControl control = new WAjaxControl(new WButton()); Assert.assertTrue("Targets should be empty", control.getTargets().isEmpty()); control.addTarget(target1); Assert.assertEquals("Incorrect targets", Arrays.asList(target1), control.getTargets()); control.addTarget(target2); Assert.assertEquals("Incorrect targets", Arrays.asList(target1, target2), control. getTargets()); }
@Test public void testMarginAccessors() { assertAccessorsCorrect(new WPanel(), "margin", null, new Margin(Size.SMALL), new Margin(Size.LARGE)); } }
@Test public void testXssEscaping() throws IOException, SAXException, XpathException { WPanel panel = new WPanel(); panel.setTitleText(getMaliciousAttribute("ui:panel")); assertSafeContent(panel); }
@Test public void testDoRenderWhenEmpty() throws IOException, SAXException, XpathException { WPanel container = new WPanel(); container.setLayout(new ColumnLayout(new int[]{50, 50})); assertSchemaMatch(container); assertXpathNotExists("//ui:panel/ui:columnlayout/ui:cell", container); }
@Test public void testConstructor2() { WPanel panel = new WPanel(); WSection section = new WSection(panel, "label"); WText txt = (WText) section.getDecoratedLabel().getBody(); Assert.assertEquals("Constructor - Incorrect label", "label", txt.getText()); Assert.assertSame("Constructor - Incorrect content", panel, section.getContent()); }
@Test public void testRenderedFormatWithAccessKey() throws IOException, SAXException, XpathException { WPanel panel = new WPanel(); assertXpathNotExists("//ui:panel/@accessKey", panel); panel.setAccessKey('x'); assertSchemaMatch(panel); assertXpathEvaluatesTo("X", "//ui:panel/@accessKey", panel); }
@Test public void testDuplicateComponentModels() { WSelectToggle selectToggle = new WSelectToggle(); assertNoDuplicateComponentModels(selectToggle, "target", new WPanel()); assertNoDuplicateComponentModels(selectToggle, "renderAsText", true); assertNoDuplicateComponentModels(selectToggle,"state", WSelectToggle.State.SOME); assertNoDuplicateComponentModels(selectToggle, "disabled", true); }
@Test public void testRenderedFormatWithButton() throws IOException, SAXException, XpathException { WPanel panel = new WPanel(); WButton button = new WButton("submit"); panel.add(button); panel.setDefaultSubmitButton(button); assertSchemaMatch(panel); assertXpathEvaluatesTo(button.getId(), "//ui:panel/@buttonId", panel); }
@Test public void testRenderAllPanelTypes() throws IOException, SAXException, XpathException { // Tests that all panel types are schema valid for (WPanel.Type type : WPanel.Type.values()) { WPanel panel = new WPanel(type); WButton button = new WButton("submit"); panel.add(button); panel.setDefaultSubmitButton(button); panel.setTitleText("Panel title"); assertSchemaMatch(panel); } }
@Test public void testRenderGap() throws IOException, SAXException, XpathException { WPanel panel = new WPanel(); for (FlowLayout.Alignment a : FlowLayout.Alignment.values()) { panel.setLayout(new FlowLayout(a, GAP)); assertSchemaMatch(panel); assertXpathEvaluatesTo(GAP.toString(), "//ui:panel/ui:flowlayout/@gap", panel); } }
@Test public void testTriggerTargetArrayConstructor() { AjaxTrigger trigger = new WCheckBox(); AjaxTarget[] targets = new AjaxTarget[]{new WPanel(), new WTextField()}; WAjaxControl control = new WAjaxControl(trigger, targets); Assert.assertSame("Incorrect trigger", trigger, control.getTrigger()); Assert.assertFalse("Should not be load once", control.isLoadOnce()); Assert.assertEquals("Delay should not be set", 0, control.getDelay()); Assert.assertEquals("Incorrect targets list", Arrays.asList(targets), control.getTargets()); Assert.assertTrue("Incorrect targets array", Arrays.equals(targets, control. getTargetsArray())); }
@Test public void testTriggerTargetConstructor() { AjaxTrigger trigger = new WDropdown(); AjaxTarget target = new WPanel(); WAjaxControl control = new WAjaxControl(trigger, target); Assert.assertSame("Incorrect trigger", trigger, control.getTrigger()); Assert.assertFalse("Should not be load once", control.isLoadOnce()); Assert.assertEquals("Delay should not be set", 0, control.getDelay()); Assert.assertEquals("Incorrect target", Arrays.asList(target), control.getTargets()); }
@Test public void testHVGaps() throws IOException, SAXException, XpathException { WPanel panel = new WPanel(); String expected; for (FlowLayout.Alignment a : FlowLayout.Alignment.values()) { panel.setLayout(new FlowLayout(a, 3, 16)); assertSchemaMatch(panel); expected = a == FlowLayout.VERTICAL ? BIG_GAP.toString() : GAP.toString(); assertXpathEvaluatesTo(expected, "//ui:panel/ui:flowlayout/@gap", panel); } }