Search in sources :

Example 6 with Pet

use of org.springframework.tests.sample.beans.Pet in project spring-framework by spring-projects.

the class RadioButtonTagTests method collectionOfPets.

@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());
}
Also used : SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) StringReader(java.io.StringReader) Document(org.dom4j.Document) Pet(org.springframework.tests.sample.beans.Pet) Test(org.junit.Test)

Example 7 with Pet

use of org.springframework.tests.sample.beans.Pet in project spring-framework by spring-projects.

the class RadioButtonsTagTests method createTestBean.

@Override
protected TestBean createTestBean() {
    List colours = new ArrayList();
    colours.add(Colour.BLUE);
    colours.add(Colour.RED);
    colours.add(Colour.GREEN);
    List pets = new ArrayList();
    pets.add(new Pet("Rudiger"));
    pets.add(new Pet("Spot"));
    pets.add(new Pet("Fluffy"));
    pets.add(new Pet("Mufty"));
    this.bean = new TestBean();
    this.bean.setDate(getDate());
    this.bean.setName("Rob Harrop");
    this.bean.setJedi(true);
    this.bean.setSomeBoolean(Boolean.TRUE);
    this.bean.setStringArray(new String[] { "bar", "foo" });
    this.bean.setSomeIntegerArray(new Integer[] { new Integer(2), new Integer(1) });
    this.bean.setOtherColours(colours);
    this.bean.setPets(pets);
    List list = new ArrayList();
    list.add("foo");
    list.add("bar");
    this.bean.setSomeList(list);
    return this.bean;
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Pet(org.springframework.tests.sample.beans.Pet)

Example 8 with Pet

use of org.springframework.tests.sample.beans.Pet in project spring-framework by spring-projects.

the class CheckboxTagTests method collectionOfPets.

@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());
}
Also used : SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) StringReader(java.io.StringReader) Document(org.dom4j.Document) Pet(org.springframework.tests.sample.beans.Pet) Test(org.junit.Test)

Example 9 with Pet

use of org.springframework.tests.sample.beans.Pet in project spring-framework by spring-projects.

the class CheckboxTagTests method collectionOfPetsNotSelected.

@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"));
}
Also used : SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) StringReader(java.io.StringReader) Document(org.dom4j.Document) Pet(org.springframework.tests.sample.beans.Pet) Test(org.junit.Test)

Aggregations

Pet (org.springframework.tests.sample.beans.Pet)9 Test (org.junit.Test)5 StringReader (java.io.StringReader)4 Document (org.dom4j.Document)4 Element (org.dom4j.Element)4 SAXReader (org.dom4j.io.SAXReader)4 TestBean (org.springframework.tests.sample.beans.TestBean)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 ApplicationContext (org.springframework.context.ApplicationContext)1 GenericGroovyApplicationContext (org.springframework.context.support.GenericGroovyApplicationContext)1 Employee (org.springframework.tests.sample.beans.Employee)1