@Test
  public void testTextareaElementWithValue() throws Exception {

    TemplateFunctions functions =
        new TemplateFunctions(applicationContext, viewResolver, localeResolver);

    TextareaElement element = new TextareaElement();
    element.setHtmlId("string");
    element.setDefaultValue("Default Value");
    element.setName("string");
    element.setLabel("String");
    element.setValue("not default");

    String output = functions.render(new MockHttpServletRequest(), element);
    Document doc = Jsoup.parse(output);
    assertEquals(
        "Name does not match", "string[0].value", doc.getElementById("string").attr("name"));
    assertEquals(
        "Textarea Value does not match", "not default", doc.getElementById("string").text());
    assertEquals(
        "Label for attribute does not match element id",
        element.getHtmlId(),
        doc.select("label").first().attr("for"));
    assertEquals("Label value does not match", "String", doc.select("label").first().text());
  }
  @Test
  public void testTextareaElementWithNoAttributes() throws Exception {

    TemplateFunctions functions =
        new TemplateFunctions(applicationContext, viewResolver, localeResolver);

    TextareaElement element = new TextareaElement();
    element.setValue("Test");
    element.setName("string");
    element.setLabel("String");
    element.setRows(20);
    element.setColumns(80);

    String output = functions.render(new MockHttpServletRequest(), element);
    System.out.println(output);
    Document doc = Jsoup.parse(output);

    assertEquals("Attributes has content", "", element.getAttributesAsString());
    assertEquals(
        "Name does not match", "string[0].value", doc.select("textarea").first().attr("name"));
    assertEquals("String Value does not match", "Test", doc.select("textarea").first().text());
    assertEquals(
        "Textarea element rows is not 20", "20", doc.select("textarea").first().attr("rows"));
    assertEquals(
        "Textarea element columns is not 80", "80", doc.select("textarea").first().attr("cols"));
  }
Пример #3
0
  @Test
  public void testPageElement() throws Exception {

    TemplateFunctions functions =
        new TemplateFunctions(applicationContext, viewResolver, localeResolver);

    PageElement pageElement = new PageElement();
    assertTrue(pageElement.excludedAttributes().isEmpty());

    pageElement.addRegion("region_list", Arrays.asList(new PlainTextElement("List")));
    pageElement.addRegion("region_single", new PlainTextElement("Single"));
    pageElement.addRegion("region_add", new PlainTextElement("Add"));
    pageElement.addRegion("region_add", new PlainTextElement(" "));
    pageElement.addRegion("region_add", new PlainTextElement("This"));

    String output = functions.render(new MockHttpServletRequest(), pageElement);
    Document doc = Jsoup.parse(output);

    assertEquals("List", doc.select(".region-region_list").text());
    assertEquals("Single", doc.select(".region-region_single").text());
    assertEquals("Add This", doc.select(".region-region_add").text());
  }