Search in sources :

Example 1 with Pet

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

the class CheckboxesTagTests 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"));
    Set someObjects = new HashSet();
    someObjects.add(new ItemPet("PET1"));
    someObjects.add(new ItemPet("PET2"));
    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[] { 2, 1 });
    this.bean.setOtherColours(colours);
    this.bean.setPets(pets);
    this.bean.setSomeSet(someObjects);
    List list = new ArrayList();
    list.add("foo");
    list.add("bar");
    this.bean.setSomeList(list);
    return this.bean;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) TestBean(org.springframework.beans.testfixture.beans.TestBean) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Pet(org.springframework.beans.testfixture.beans.Pet) HashSet(java.util.HashSet)

Example 2 with Pet

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

the class RadioButtonTagTests method createTestBean.

@Override
protected TestBean createTestBean() {
    this.bean = new TestBean();
    bean.setSex("M");
    bean.setMyFloat(getFloat());
    bean.setPets(Collections.singletonList(new Pet("Rudiger")));
    return bean;
}
Also used : TestBean(org.springframework.beans.testfixture.beans.TestBean) Pet(org.springframework.beans.testfixture.beans.Pet)

Example 3 with Pet

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

the class RadioButtonTagTests method collectionOfPetsNotSelected.

@Test
void collectionOfPetsNotSelected() throws Exception {
    this.tag.setPath("pets");
    this.tag.setValue(new Pet("Santa's Little Helper"));
    int result = this.tag.doStartTag();
    assertThat(result).isEqualTo(Tag.SKIP_BODY);
    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 = document.getRootElement().elements().get(0);
    assertThat(checkboxElement.getName()).isEqualTo("input");
    assertThat(checkboxElement.attribute("type").getValue()).isEqualTo("radio");
    assertThat(checkboxElement.attribute("name").getValue()).isEqualTo("pets");
    assertThat(checkboxElement.attribute("value").getValue()).isEqualTo("Santa's Little Helper");
    assertThat(checkboxElement.attribute("checked")).isNull();
}
Also used : SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) StringReader(java.io.StringReader) Document(org.dom4j.Document) Pet(org.springframework.beans.testfixture.beans.Pet) Test(org.junit.jupiter.api.Test)

Example 4 with Pet

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

the class CheckboxTagTests 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"));
    List someList = new ArrayList();
    someList.add("foo");
    someList.add("bar");
    Map someMap = new LinkedHashMap();
    someMap.put("key", Boolean.TRUE);
    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[] { 2, 1 });
    this.bean.setOtherColours(colours);
    this.bean.setPets(pets);
    this.bean.setSomeList(someList);
    this.bean.setSomeMap(someMap);
    return this.bean;
}
Also used : TestBean(org.springframework.beans.testfixture.beans.TestBean) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Pet(org.springframework.beans.testfixture.beans.Pet) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with Pet

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

the class GroovyControlGroupTests method verifyScriptUsingGenericGroovyApplicationContext.

@Test
@SuppressWarnings("resource")
void verifyScriptUsingGenericGroovyApplicationContext() {
    ApplicationContext ctx = new GenericGroovyApplicationContext(getClass(), "context.groovy");
    String foo = ctx.getBean("foo", String.class);
    assertThat(foo).isEqualTo("Foo");
    String bar = ctx.getBean("bar", String.class);
    assertThat(bar).isEqualTo("Bar");
    Pet pet = ctx.getBean(Pet.class);
    assertThat(pet).as("pet").isNotNull();
    assertThat(pet.getName()).isEqualTo("Dogbert");
    Employee employee = ctx.getBean(Employee.class);
    assertThat(employee).as("employee").isNotNull();
    assertThat(employee.getName()).isEqualTo("Dilbert");
    assertThat(employee.getCompany()).isEqualTo("???");
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) GenericGroovyApplicationContext(org.springframework.context.support.GenericGroovyApplicationContext) GenericGroovyApplicationContext(org.springframework.context.support.GenericGroovyApplicationContext) Employee(org.springframework.beans.testfixture.beans.Employee) Pet(org.springframework.beans.testfixture.beans.Pet) Test(org.junit.jupiter.api.Test)

Aggregations

Pet (org.springframework.beans.testfixture.beans.Pet)9 Test (org.junit.jupiter.api.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.beans.testfixture.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 Employee (org.springframework.beans.testfixture.beans.Employee)1 ApplicationContext (org.springframework.context.ApplicationContext)1 GenericGroovyApplicationContext (org.springframework.context.support.GenericGroovyApplicationContext)1