@Test public void withoutItems() throws Exception { this.tag.setItemValue("isoCode"); this.tag.setItemLabel("name"); this.selectTag.setPath("testBean"); this.selectTag.doStartTag(); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); this.tag.doEndTag(); this.selectTag.doEndTag(); String output = getOutput(); SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); List children = rootElement.elements(); assertEquals("Incorrect number of children", 0, children.size()); }
@Test public void withoutItemsEnumParent() throws Exception { BeanWithEnum testBean = new BeanWithEnum(); testBean.setTestEnum(TestEnum.VALUE_2); getPageContext().getRequest().setAttribute("testBean", testBean); this.selectTag.setPath("testBean.testEnum"); this.selectTag.doStartTag(); int result = this.tag.doStartTag(); assertEquals(BodyTag.SKIP_BODY, result); result = this.tag.doEndTag(); assertEquals(Tag.EVAL_PAGE, result); this.selectTag.doEndTag(); String output = getWriter().toString(); SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals(2, rootElement.elements().size()); Node value1 = rootElement.selectSingleNode("option[@value = 'VALUE_1']"); Node value2 = rootElement.selectSingleNode("option[@value = 'VALUE_2']"); assertEquals("TestEnum: VALUE_1", value1.getText()); assertEquals("TestEnum: VALUE_2", value2.getText()); assertEquals(value2, rootElement.selectSingleNode("option[@selected]")); }
@Test public void withoutItemsEnumParentWithExplicitLabelsAndValues() throws Exception { BeanWithEnum testBean = new BeanWithEnum(); testBean.setTestEnum(TestEnum.VALUE_2); getPageContext().getRequest().setAttribute("testBean", testBean); this.selectTag.setPath("testBean.testEnum"); this.tag.setItemLabel("enumLabel"); this.tag.setItemValue("enumValue"); this.selectTag.doStartTag(); int result = this.tag.doStartTag(); assertEquals(BodyTag.SKIP_BODY, result); result = this.tag.doEndTag(); assertEquals(Tag.EVAL_PAGE, result); this.selectTag.doEndTag(); String output = getWriter().toString(); SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals(2, rootElement.elements().size()); Node value1 = rootElement.selectSingleNode("option[@value = 'Value: VALUE_1']"); Node value2 = rootElement.selectSingleNode("option[@value = 'Value: VALUE_2']"); assertEquals("Label: VALUE_1", value1.getText()); assertEquals("Label: VALUE_2", value2.getText()); assertEquals(value2, rootElement.selectSingleNode("option[@selected]")); }
@Test public void withNestedOptions() throws Exception { this.tag.setPath("country"); int result = this.tag.doStartTag(); assertEquals(Tag.EVAL_BODY_INCLUDE, result); BindStatus value = (BindStatus) getPageContext().getAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE); assertEquals("Selected country not exposed in page context", "UK", value.getValue()); result = this.tag.doEndTag(); assertEquals(Tag.EVAL_PAGE, result); this.tag.doFinally(); String output = getOutput(); assertTrue(output.startsWith("<select ")); assertTrue(output.endsWith("</select>")); assertContainsAttribute(output, "name", "country"); }