Java 类org.springframework.web.servlet.support.BindStatus 实例源码

项目:spring4-understanding    文件:SelectedValueComparator.java   
private static boolean exhaustiveCollectionCompare(
        Collection<?> collection, Object candidateValue, BindStatus bindStatus) {

    Map<PropertyEditor, Object> convertedValueCache = new HashMap<PropertyEditor, Object>(1);
    PropertyEditor editor = null;
    boolean candidateIsString = (candidateValue instanceof String);
    if (!candidateIsString) {
        editor = bindStatus.findEditor(candidateValue.getClass());
    }
    for (Object element : collection) {
        if (editor == null && element != null && candidateIsString) {
            editor = bindStatus.findEditor(element.getClass());
        }
        if (exhaustiveCompare(element, candidateValue, editor, convertedValueCache)) {
            return true;
        }
    }
    return false;
}
项目:spring4-understanding    文件:VelocityMacroTests.java   
@Test
public void exposeSpringMacroHelpers() throws Exception {
    VelocityView vv = new VelocityView() {
        @Override
        protected void mergeTemplate(Template template, Context context, HttpServletResponse response) {
            assertTrue(context.get(VelocityView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE) instanceof RequestContext);
            RequestContext rc = (RequestContext) context.get(VelocityView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE);
            BindStatus status = rc.getBindStatus("tb.name");
            assertEquals("name", status.getExpression());
            assertEquals("juergen", status.getValue());
        }
    };
    vv.setUrl(TEMPLATE_FILE);
    vv.setApplicationContext(wac);
    vv.setExposeSpringMacroHelpers(true);

    Map<String, Object> model = new HashMap<String, Object>();
    model.put("tb", new TestBean("juergen", 99));
    vv.render(model, request, response);
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void canBeDisabledEvenWhenSelected() throws Exception {
    String selectName = "testBean.name";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue("bar");
    this.tag.setLabel("Bar");
    this.tag.setDisabled(true);
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "bar");
    assertContainsAttribute(output, "disabled", "disabled");
    assertBlockTagContains(output, "Bar");
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void renderNotSelected() throws Exception {
    String selectName = "testBean.name";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue("bar");
    this.tag.setLabel("Bar");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "bar");
    assertBlockTagContains(output, "Bar");
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void renderWithDynamicAttributes() throws Exception {
    String dynamicAttribute1 = "attr1";
    String dynamicAttribute2 = "attr2";

    String selectName = "testBean.name";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue("bar");
    this.tag.setLabel("Bar");
    this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1);
    this.tag.setDynamicAttribute(null, dynamicAttribute2, dynamicAttribute2);

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "bar");
    assertContainsAttribute(output, dynamicAttribute1, dynamicAttribute1);
    assertContainsAttribute(output, dynamicAttribute2, dynamicAttribute2);
    assertBlockTagContains(output, "Bar");
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void renderSelected() throws Exception {
    String selectName = "testBean.name";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setId("myOption");
    this.tag.setValue("foo");
    this.tag.setLabel("Foo");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "id", "myOption");
    assertContainsAttribute(output, "value", "foo");
    assertContainsAttribute(output, "selected", "selected");
    assertBlockTagContains(output, "Foo");
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void withNoLabel() throws Exception {
    String selectName = "testBean.name";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue("bar");
    this.tag.setCssClass("myClass");
    this.tag.setOnclick("CLICK");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "bar");
    assertContainsAttribute(output, "class", "myClass");
    assertContainsAttribute(output, "onclick", "CLICK");
    assertBlockTagContains(output, "bar");
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void withCustomObjectSelected() throws Exception {
    String selectName = "testBean.someNumber";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue(new Float(12.34));
    this.tag.setLabel("GBP 12.34");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "12.34");
    assertContainsAttribute(output, "selected", "selected");
    assertBlockTagContains(output, "GBP 12.34");
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void withCustomObjectNotSelected() throws Exception {
    String selectName = "testBean.someNumber";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue(new Float(12.35));
    this.tag.setLabel("GBP 12.35");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "12.35");
    assertAttributeNotPresent(output, "selected");
    assertBlockTagContains(output, "GBP 12.35");
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void withCustomObjectAndEditorNotSelected() throws Exception {
    final PropertyEditor floatEditor = new SimpleFloatEditor();
    String selectName = "testBean.someNumber";
    BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
        @Override
        public PropertyEditor getEditor() {
            return floatEditor;
        }
    };
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    this.tag.setValue(new Float(12.35));
    this.tag.setLabel("12.35f");

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertAttributeNotPresent(output, "selected");
    assertBlockTagContains(output, "12.35f");
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void asBodyTag() throws Exception {
    String selectName = "testBean.name";
    BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    String bodyContent = "some content";

    this.tag.setValue("foo");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "selected", "selected");
    assertBlockTagContains(output, bodyContent);
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void asBodyTagSelected() throws Exception {
    String selectName = "testBean.name";
    BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    String bodyContent = "some content";

    this.tag.setValue("Rob Harrop");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertBlockTagContains(output, bodyContent);
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void asBodyTagCollapsed() throws Exception {
    String selectName = "testBean.name";
    BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    String bodyContent = "some content";

    this.tag.setValue(bodyContent);
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", bodyContent);
    assertBlockTagContains(output, bodyContent);
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void asBodyTagWithEditor() throws Exception {
    String selectName = "testBean.stringArray";
    BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
        @Override
        public PropertyEditor getEditor() {
            return new RulesVariantEditor();
        }
    };
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    RulesVariant rulesVariant = new RulesVariant("someRules", "someVariant");
    this.tag.setValue(rulesVariant);

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);

    assertEquals(rulesVariant, getPageContext().getAttribute("value"));
    assertEquals(rulesVariant.toId(), getPageContext().getAttribute("displayValue"));

    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);
}
项目:spring4-understanding    文件:OptionTagEnumTests.java   
@Test
@SuppressWarnings("rawtypes")
public void withJavaEnum() throws Exception {
    GenericBean testBean = new GenericBean();
    testBean.setCustomEnum(CustomEnum.VALUE_1);
    getPageContext().getRequest().setAttribute("testBean", testBean);
    String selectName = "testBean.customEnum";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));

    this.tag.setValue("VALUE_1");

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getWriter().toString();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "VALUE_1");
    assertContainsAttribute(output, "selected", "selected");
}
项目:spring4-understanding    文件:SelectTagTests.java   
@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");
}
项目:spring4-understanding    文件:OptionsTagTests.java   
@Test
public void withItemsNullReference() throws Exception {
    getPageContext().setAttribute(
            SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.country", false));

    this.tag.setItems(Collections.emptyList());
    this.tag.setItemValue("isoCode");
    this.tag.setItemLabel("name");
    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);
    String output = getOutput();
    output = "<doc>" + output + "</doc>";

    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());
}
项目:spring4-understanding    文件:BindTagTests.java   
@Test
public void bindTagWithoutErrors() throws JspException {
    PageContext pc = createPageContext();
    Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
    pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
    BindTag tag = new BindTag();
    tag.setPageContext(pc);
    tag.setPath("tb");
    assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
    BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
    assertTrue("Has status variable", status != null);
    assertTrue("Correct expression", status.getExpression() == null);
    assertTrue("Correct value", status.getValue() == null);
    assertTrue("Correct displayValue", "".equals(status.getDisplayValue()));
    assertTrue("Correct isError", !status.isError());
    assertTrue("Correct errorCodes", status.getErrorCodes().length == 0);
    assertTrue("Correct errorMessages", status.getErrorMessages().length == 0);
    assertTrue("Correct errorCode", "".equals(status.getErrorCode()));
    assertTrue("Correct errorMessage", "".equals(status.getErrorMessage()));
    assertTrue("Correct errorMessagesAsString", "".equals(status.getErrorMessagesAsString(",")));
}
项目:spring4-understanding    文件:BindTagTests.java   
@Test
public void bindTagWithIndexedProperties() throws JspException {
    PageContext pc = createPageContext();
    IndexedTestBean tb = new IndexedTestBean();
    Errors errors = new ServletRequestDataBinder(tb, "tb").getBindingResult();
    errors.rejectValue("array[0]", "code1", "message1");
    errors.rejectValue("array[0]", "code2", "message2");
    pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);

    BindTag tag = new BindTag();
    tag.setPageContext(pc);
    tag.setPath("tb.array[0]");
    assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
    BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
    assertTrue("Has status variable", status != null);
    assertTrue("Correct expression", "array[0]".equals(status.getExpression()));
    assertTrue("Value is TestBean", status.getValue() instanceof TestBean);
    assertTrue("Correct value", "name0".equals(((TestBean) status.getValue()).getName()));
    assertTrue("Correct isError", status.isError());
    assertTrue("Correct errorCodes", status.getErrorCodes().length == 2);
    assertTrue("Correct errorMessages", status.getErrorMessages().length == 2);
    assertTrue("Correct errorCode", "code1".equals(status.getErrorCodes()[0]));
    assertTrue("Correct errorCode", "code2".equals(status.getErrorCodes()[1]));
    assertTrue("Correct errorMessage", "message1".equals(status.getErrorMessages()[0]));
    assertTrue("Correct errorMessage", "message2".equals(status.getErrorMessages()[1]));
}
项目:spring4-understanding    文件:BindTagTests.java   
@Test
public void bindTagWithMappedProperties() throws JspException {
    PageContext pc = createPageContext();
    IndexedTestBean tb = new IndexedTestBean();
    Errors errors = new ServletRequestDataBinder(tb, "tb").getBindingResult();
    errors.rejectValue("map[key1]", "code1", "message1");
    errors.rejectValue("map[key1]", "code2", "message2");
    pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);

    BindTag tag = new BindTag();
    tag.setPageContext(pc);
    tag.setPath("tb.map[key1]");
    assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
    BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
    assertTrue("Has status variable", status != null);
    assertTrue("Correct expression", "map[key1]".equals(status.getExpression()));
    assertTrue("Value is TestBean", status.getValue() instanceof TestBean);
    assertTrue("Correct value", "name4".equals(((TestBean) status.getValue()).getName()));
    assertTrue("Correct isError", status.isError());
    assertTrue("Correct errorCodes", status.getErrorCodes().length == 2);
    assertTrue("Correct errorMessages", status.getErrorMessages().length == 2);
    assertTrue("Correct errorCode", "code1".equals(status.getErrorCodes()[0]));
    assertTrue("Correct errorCode", "code2".equals(status.getErrorCodes()[1]));
    assertTrue("Correct errorMessage", "message1".equals(status.getErrorMessages()[0]));
    assertTrue("Correct errorMessage", "message2".equals(status.getErrorMessages()[1]));
}
项目:spring4-understanding    文件:BindTagTests.java   
@Test
public void bindTagWithToStringAndHtmlEscaping() throws JspException {
    PageContext pc = createPageContext();
    BindTag tag = new BindTag();
    tag.setPageContext(pc);
    tag.setPath("tb.doctor");
    tag.setHtmlEscape(true);
    TestBean tb = new TestBean("somebody", 99);
    NestedTestBean ntb = new NestedTestBean("juergen&eva");
    tb.setDoctor(ntb);
    pc.getRequest().setAttribute("tb", tb);
    tag.doStartTag();
    BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
    assertEquals("doctor", status.getExpression());
    assertTrue(status.getValue() instanceof NestedTestBean);
    assertTrue(status.getDisplayValue().indexOf("juergen&amp;eva") != -1);
}
项目:spring4-understanding    文件:BindTagTests.java   
@Test
public void nestedPathWithBindTagWithIgnoreNestedPath() throws JspException {
    PageContext pc = createPageContext();
    Errors errors = new ServletRequestDataBinder(new TestBean(), "tb2").getBindingResult();
    pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb2", errors);

    NestedPathTag tag = new NestedPathTag();
    tag.setPath("tb");
    tag.setPageContext(pc);
    tag.doStartTag();

    BindTag bindTag = new BindTag();
    bindTag.setPageContext(pc);
    bindTag.setIgnoreNestedPath(true);
    bindTag.setPath("tb2.name");

    assertTrue("Correct doStartTag return value", bindTag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
    BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
    assertTrue("Has status variable", status != null);
    assertEquals("tb2.name", status.getPath());
}
项目:class-guard    文件:SelectedValueComparator.java   
private static boolean exhaustiveCollectionCompare(
        Collection collection, Object candidateValue, BindStatus bindStatus) {

    Map<PropertyEditor, Object> convertedValueCache = new HashMap<PropertyEditor, Object>(1);
    PropertyEditor editor = null;
    boolean candidateIsString = (candidateValue instanceof String);
    if (!candidateIsString) {
        editor = bindStatus.findEditor(candidateValue.getClass());
    }
    for (Object element : collection) {
        if (editor == null && element != null && candidateIsString) {
            editor = bindStatus.findEditor(element.getClass());
        }
        if (exhaustiveCompare(element, candidateValue, editor, convertedValueCache)) {
            return true;
        }
    }
    return false;
}
项目:class-guard    文件:VelocityMacroTests.java   
public void testExposeSpringMacroHelpers() throws Exception {
    VelocityView vv = new VelocityView() {
        @Override
        protected void mergeTemplate(Template template, Context context, HttpServletResponse response) {
            assertTrue(context.get(VelocityView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE) instanceof RequestContext);
            RequestContext rc = (RequestContext) context.get(VelocityView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE);
            BindStatus status = rc.getBindStatus("tb.name");
            assertEquals("name", status.getExpression());
            assertEquals("juergen", status.getValue());
        }
    };
    vv.setUrl(TEMPLATE_FILE);
    vv.setApplicationContext(wac);
    vv.setExposeSpringMacroHelpers(true);

    Map<String, Object> model = new HashMap<String, Object>();
    model.put("tb", new TestBean("juergen", 99));
    vv.render(model, request, response);
}
项目:class-guard    文件:OptionTagTests.java   
public void testCanBeDisabledEvenWhenSelected() throws Exception {
    String selectName = "testBean.name";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue("bar");
    this.tag.setLabel("Bar");
    this.tag.setDisabled("true");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "bar");
    assertContainsAttribute(output, "disabled", "disabled");
    assertBlockTagContains(output, "Bar");
}
项目:class-guard    文件:OptionTagTests.java   
public void testRenderNotSelected() throws Exception {
    String selectName = "testBean.name";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue("bar");
    this.tag.setLabel("Bar");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "bar");
    assertBlockTagContains(output, "Bar");
}
项目:class-guard    文件:OptionTagTests.java   
public void testRenderWithDynamicAttributes() throws Exception {
    String dynamicAttribute1 = "attr1";
    String dynamicAttribute2 = "attr2";

    String selectName = "testBean.name";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue("bar");
    this.tag.setLabel("Bar");
    this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1);
    this.tag.setDynamicAttribute(null, dynamicAttribute2, dynamicAttribute2);

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "bar");
    assertContainsAttribute(output, dynamicAttribute1, dynamicAttribute1);
    assertContainsAttribute(output, dynamicAttribute2, dynamicAttribute2);
    assertBlockTagContains(output, "Bar");
}
项目:class-guard    文件:OptionTagTests.java   
public void testRenderSelected() throws Exception {
    String selectName = "testBean.name";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setId("myOption");
    this.tag.setValue("foo");
    this.tag.setLabel("Foo");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "id", "myOption");
    assertContainsAttribute(output, "value", "foo");
    assertContainsAttribute(output, "selected", "selected");
    assertBlockTagContains(output, "Foo");
}
项目:class-guard    文件:OptionTagTests.java   
public void testWithNoLabel() throws Exception {
    String selectName = "testBean.name";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue("bar");
    this.tag.setCssClass("myClass");
    this.tag.setOnclick("CLICK");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "bar");
    assertContainsAttribute(output, "class", "myClass");
    assertContainsAttribute(output, "onclick", "CLICK");
    assertBlockTagContains(output, "bar");
}
项目:class-guard    文件:OptionTagTests.java   
public void testWithEnum() throws Exception {
    String selectName = "testBean.favouriteColour";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));

    String value = Colour.GREEN.getCode().toString();
    String label = Colour.GREEN.getLabel();

    this.tag.setValue(value);
    this.tag.setLabel(label);

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", value);
    assertContainsAttribute(output, "selected", "selected");
    assertBlockTagContains(output, label);
}
项目:class-guard    文件:OptionTagTests.java   
public void testWithEnumNotSelected() throws Exception {
    String selectName = "testBean.favouriteColour";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));

    String value = Colour.BLUE.getCode().toString();
    String label = Colour.BLUE.getLabel();

    this.tag.setValue(value);
    this.tag.setLabel(label);

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", value);
    assertAttributeNotPresent(output, "selected");
    assertBlockTagContains(output, label);
}
项目:class-guard    文件:OptionTagTests.java   
public void testWithPropertyEditorStringComparison() throws Exception {
    final PropertyEditor testBeanEditor = new TestBeanPropertyEditor();
    testBeanEditor.setValue(new TestBean("Sally"));
    String selectName = "testBean.spouse";
    BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
        @Override
        public PropertyEditor getEditor() {
            return testBeanEditor;
        }
    };
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    this.tag.setValue("Sally");

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "Sally");
    assertContainsAttribute(output, "selected", "selected");
    assertBlockTagContains(output, "Sally");
}
项目:class-guard    文件:OptionTagTests.java   
public void testWithCustomObjectSelected() throws Exception {
    String selectName = "testBean.someNumber";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue("${myNumber}");
    this.tag.setLabel("GBP ${myNumber}");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "12.34");
    assertContainsAttribute(output, "selected", "selected");
    assertBlockTagContains(output, "GBP 12.34");
}
项目:class-guard    文件:OptionTagTests.java   
public void testWithCustomObjectNotSelected() throws Exception {
    String selectName = "testBean.someNumber";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue("${myOtherNumber}");
    this.tag.setLabel("GBP ${myOtherNumber}");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "12.35");
    assertAttributeNotPresent(output, "selected");
    assertBlockTagContains(output, "GBP 12.35");
}
项目:class-guard    文件:OptionTagTests.java   
public void testWithCustomObjectAndEditorSelected() throws Exception {
    final PropertyEditor floatEditor = new SimpleFloatEditor();
    floatEditor.setValue(new Float("12.34"));
    String selectName = "testBean.someNumber";
    BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
        @Override
        public PropertyEditor getEditor() {
            return floatEditor;
        }
    };
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    this.tag.setValue("${myNumber}");
    this.tag.setLabel("${myNumber}");

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "selected", "selected");
    assertBlockTagContains(output, "12.34f");
}
项目:class-guard    文件:OptionTagTests.java   
public void testWithCustomObjectAndEditorNotSelected() throws Exception {
    final PropertyEditor floatEditor = new SimpleFloatEditor();
    String selectName = "testBean.someNumber";
    BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
        @Override
        public PropertyEditor getEditor() {
            return floatEditor;
        }
    };
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    this.tag.setValue("${myOtherNumber}");
    this.tag.setLabel("${myOtherNumber}");

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertAttributeNotPresent(output, "selected");
    assertBlockTagContains(output, "12.35f");
}
项目:class-guard    文件:OptionTagTests.java   
public void testAsBodyTag() throws Exception {
    String selectName = "testBean.name";
    BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    String bodyContent = "some content";

    this.tag.setValue("foo");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "selected", "selected");
    assertBlockTagContains(output, bodyContent);
}
项目:class-guard    文件:OptionTagTests.java   
public void testAsBodyTagSelected() throws Exception {
    String selectName = "testBean.name";
    BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    String bodyContent = "some content";

    this.tag.setValue("Rob Harrop");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertBlockTagContains(output, bodyContent);
}
项目:class-guard    文件:OptionTagTests.java   
public void testAsBodyTagCollapsed() throws Exception {
    String selectName = "testBean.name";
    BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    String bodyContent = "some content";

    this.tag.setValue(bodyContent);
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", bodyContent);
    assertBlockTagContains(output, bodyContent);
}
项目:class-guard    文件:OptionTagTests.java   
public void testAsBodyTagWithEditor() throws Exception {
    String selectName = "testBean.stringArray";
    BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
        @Override
        public PropertyEditor getEditor() {
            return new RulesVariantEditor();
        }
    };
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    RulesVariant rulesVariant = new RulesVariant("someRules", "someVariant");
    getPageContext().getRequest().setAttribute("rule", rulesVariant);

    this.tag.setValue("${rule}");

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);

    assertEquals(rulesVariant, getPageContext().getAttribute("value"));
    assertEquals(rulesVariant.toId(), getPageContext().getAttribute("displayValue"));

    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);
}