Refine search
private void validateOutput(String output, boolean selected) throws DocumentException { SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals("select", rootElement.getName()); assertEquals("country", rootElement.attribute("name").getValue()); List children = rootElement.elements(); assertEquals("Incorrect number of children", 4, children.size()); Element e = (Element) rootElement.selectSingleNode("option[@value = 'UK']"); Attribute selectedAttr = e.attribute("selected"); if (selected) { assertTrue(selectedAttr != null && "selected".equals(selectedAttr.getValue())); } else { assertNull(selectedAttr); } }
@Test public void withSingleValueBooleanChecked() throws Exception { this.tag.setPath("jedi"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element checkboxElement = (Element) document.getRootElement().elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("jedi", checkboxElement.attribute("name").getValue()); assertEquals("checked", checkboxElement.attribute("checked").getValue()); assertEquals("true", checkboxElement.attribute("value").getValue()); }
@Test public void withSingleValueBooleanObjectChecked() throws Exception { this.tag.setPath("someBoolean"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals("Both tag and hidden element not rendered", 2, rootElement.elements().size()); Element checkboxElement = (Element) rootElement.elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("someBoolean1", checkboxElement.attribute("id").getValue()); assertEquals("someBoolean", checkboxElement.attribute("name").getValue()); assertEquals("checked", checkboxElement.attribute("checked").getValue()); assertEquals("true", checkboxElement.attribute("value").getValue()); }
@Test public void withIndexedBooleanObjectNotChecked() throws Exception { this.tag.setPath("someMap[key]"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals("Both tag and hidden element not rendered", 2, rootElement.elements().size()); Element checkboxElement = (Element) rootElement.elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("someMapkey1", checkboxElement.attribute("id").getValue()); assertEquals("someMap[key]", checkboxElement.attribute("name").getValue()); assertEquals("checked", checkboxElement.attribute("checked").getValue()); assertEquals("true", checkboxElement.attribute("value").getValue()); }
@Test public void withObjectUnchecked() throws Exception { this.tag.setPath("date"); Date date = new Date(); this.tag.setValue(date); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element checkboxElement = (Element) document.getRootElement().elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("date", checkboxElement.attribute("name").getValue()); assertNull(checkboxElement.attribute("checked")); assertEquals(date.toString(), checkboxElement.attribute("value").getValue()); }
@Test public void withMultiValueChecked() throws Exception { this.tag.setPath("stringArray"); this.tag.setValue("foo"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element checkboxElement = (Element) document.getRootElement().elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("stringArray", checkboxElement.attribute("name").getValue()); assertEquals("checked", checkboxElement.attribute("checked").getValue()); assertEquals("foo", checkboxElement.attribute("value").getValue()); }
@Test public void withSingleValueBooleanUnchecked() throws Exception { this.bean.setJedi(false); this.tag.setPath("jedi"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element checkboxElement = (Element) document.getRootElement().elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("jedi", checkboxElement.attribute("name").getValue()); assertNull(checkboxElement.attribute("checked")); assertEquals("true", checkboxElement.attribute("value").getValue()); }
@Test public void withMultiValueUnchecked() throws Exception { this.tag.setPath("stringArray"); this.tag.setValue("abc"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element checkboxElement = (Element) document.getRootElement().elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("stringArray", checkboxElement.attribute("name").getValue()); assertNull(checkboxElement.attribute("checked")); assertEquals("abc", checkboxElement.attribute("value").getValue()); }
@Test public void withCollection() throws Exception { this.tag.setPath("someList"); this.tag.setValue("foo"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element checkboxElement = (Element) document.getRootElement().elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("someList", checkboxElement.attribute("name").getValue()); assertEquals("checked", checkboxElement.attribute("checked").getValue()); assertEquals("foo", checkboxElement.attribute("value").getValue()); }
@Test public void withSingleValueBooleanObjectUnchecked() throws Exception { this.bean.setSomeBoolean(Boolean.FALSE); this.tag.setPath("someBoolean"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element checkboxElement = (Element) document.getRootElement().elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("someBoolean", checkboxElement.attribute("name").getValue()); assertNull(checkboxElement.attribute("checked")); assertEquals("true", checkboxElement.attribute("value").getValue()); }
@Test public void collectionOfColoursSelected() throws Exception { this.tag.setPath("otherColours"); this.tag.setValue("RED"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element checkboxElement = (Element) document.getRootElement().elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("otherColours", checkboxElement.attribute("name").getValue()); assertEquals("checked", checkboxElement.attribute("checked").getValue()); }
@Test public void collectionOfPetsAsStringNotSelected() throws Exception { this.tag.setPath("pets"); this.tag.setValue("Santa's Little Helper"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element checkboxElement = (Element) document.getRootElement().elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("pets", checkboxElement.attribute("name").getValue()); assertNull(checkboxElement.attribute("checked")); }
@Test public void collectionOfPetsAsString() throws Exception { this.tag.setPath("pets"); this.tag.setValue("Spot"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element checkboxElement = (Element) document.getRootElement().elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("pets", checkboxElement.attribute("name").getValue()); assertEquals("checked", checkboxElement.attribute("checked").getValue()); }
@Test public void collectionOfPets() throws Exception { this.tag.setPath("pets"); this.tag.setValue(new Pet("Rudiger")); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element checkboxElement = (Element) document.getRootElement().elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("radio", checkboxElement.attribute("type").getValue()); assertEquals("pets", checkboxElement.attribute("name").getValue()); assertEquals("Rudiger", checkboxElement.attribute("value").getValue()); assertEquals("checked", checkboxElement.attribute("checked").getValue()); }
@Test public void collectionOfColoursNotSelected() throws Exception { this.tag.setPath("otherColours"); this.tag.setValue("PURPLE"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element checkboxElement = (Element) document.getRootElement().elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("otherColours", checkboxElement.attribute("name").getValue()); assertNull(checkboxElement.attribute("checked")); }
@Test public void collectionOfPetsNotSelected() throws Exception { this.tag.setPath("pets"); this.tag.setValue(new Pet("Santa's Little Helper")); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element checkboxElement = (Element) document.getRootElement().elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("radio", checkboxElement.attribute("type").getValue()); assertEquals("pets", checkboxElement.attribute("name").getValue()); assertEquals("Santa's Little Helper", checkboxElement.attribute("value").getValue()); assertNull(checkboxElement.attribute("checked")); }
@Test public void collectionOfPets() throws Exception { this.tag.setPath("pets"); this.tag.setValue(new Pet("Rudiger")); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element checkboxElement = (Element) document.getRootElement().elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("pets", checkboxElement.attribute("name").getValue()); assertEquals("Rudiger", checkboxElement.attribute("value").getValue()); assertEquals("checked", checkboxElement.attribute("checked").getValue()); }
@Test public void collectionOfPetsNotSelected() throws Exception { this.tag.setPath("pets"); this.tag.setValue(new Pet("Santa's Little Helper")); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element checkboxElement = (Element) document.getRootElement().elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("pets", checkboxElement.attribute("name").getValue()); assertEquals("Santa's Little Helper", checkboxElement.attribute("value").getValue()); assertNull(checkboxElement.attribute("checked")); }
@Test public void hiddenElementOmittedOnDisabled() throws Exception { this.tag.setPath("stringArray"); this.tag.setItems(new Object[] {"foo", "bar", "baz"}); this.tag.setDisabled(true); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals("Both tag and hidden element rendered incorrectly", 3, rootElement.elements().size()); Element spanElement = (Element) document.getRootElement().elements().get(0); Element radioButtonElement = (Element) spanElement.elements().get(0); assertEquals("input", radioButtonElement.getName()); assertEquals("radio", radioButtonElement.attribute("type").getValue()); assertEquals("stringArray", radioButtonElement.attribute("name").getValue()); assertEquals("checked", radioButtonElement.attribute("checked").getValue()); assertEquals("disabled", radioButtonElement.attribute("disabled").getValue()); assertEquals("foo", radioButtonElement.attribute("value").getValue()); }
@Test public void withObjectChecked() throws Exception { this.tag.setPath("date"); this.tag.setValue(getDate()); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element checkboxElement = (Element) document.getRootElement().elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("date", checkboxElement.attribute("name").getValue()); assertEquals("checked", checkboxElement.attribute("checked").getValue()); assertEquals(getDate().toString(), checkboxElement.attribute("value").getValue()); }