use of org.springframework.beans.testfixture.beans.TestBean 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;
}
use of org.springframework.beans.testfixture.beans.TestBean 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;
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class BindTagTests method bindErrorsTagWithErrors.
@Test
void bindErrorsTagWithErrors() throws JspException {
PageContext pc = createPageContext();
Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
errors.reject("test", null, "test");
pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
BindErrorsTag tag = new BindErrorsTag();
tag.setPageContext(pc);
tag.setName("tb");
assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
assertThat(pc.getAttribute(BindErrorsTag.ERRORS_VARIABLE_NAME, PageContext.REQUEST_SCOPE) == errors).as("Has errors variable").isTrue();
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class BindTagTests method bindTagWithGlobalErrors.
@Test
void bindTagWithGlobalErrors() throws JspException {
PageContext pc = createPageContext();
Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
errors.reject("code1", "message1");
pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
BindTag tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb");
assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertThat(status != null).as("Has status variable").isTrue();
assertThat(status.getExpression() == null).as("Correct expression").isTrue();
assertThat(status.getValue() == null).as("Correct value").isTrue();
assertThat("".equals(status.getDisplayValue())).as("Correct displayValue").isTrue();
assertThat(status.isError()).as("Correct isError").isTrue();
assertThat(status.getErrorCodes().length == 1).as("Correct errorCodes").isTrue();
assertThat(status.getErrorMessages().length == 1).as("Correct errorMessages").isTrue();
assertThat("code1".equals(status.getErrorCode())).as("Correct errorCode").isTrue();
assertThat("message1".equals(status.getErrorMessage())).as("Correct errorMessage").isTrue();
assertThat("message1".equals(status.getErrorMessagesAsString(","))).as("Correct errorMessagesAsString").isTrue();
tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb.*");
assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertThat(status != null).as("Has status variable").isTrue();
assertThat("*".equals(status.getExpression())).as("Correct expression").isTrue();
assertThat(status.getValue() == null).as("Correct value").isTrue();
assertThat("".equals(status.getDisplayValue())).as("Correct displayValue").isTrue();
assertThat(status.isError()).as("Correct isError").isTrue();
assertThat(status.getErrorCodes().length == 1).as("Correct errorCodes").isTrue();
assertThat(status.getErrorMessages().length == 1).as("Correct errorMessages").isTrue();
assertThat("code1".equals(status.getErrorCode())).as("Correct errorCode").isTrue();
assertThat("message1".equals(status.getErrorMessage())).as("Correct errorMessage").isTrue();
assertThat("message1".equals(status.getErrorMessagesAsString(","))).as("Correct errorMessagesAsString").isTrue();
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class BindTagTests method bindTagWithGlobalErrorsAndDefaultMessageOnly.
@Test
void bindTagWithGlobalErrorsAndDefaultMessageOnly() throws JspException {
PageContext pc = createPageContext();
Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
errors.reject(null, "message1");
pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
BindTag tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb");
assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertThat(status != null).as("Has status variable").isTrue();
assertThat(status.getExpression() == null).as("Correct expression").isTrue();
assertThat(status.getValue() == null).as("Correct value").isTrue();
assertThat("".equals(status.getDisplayValue())).as("Correct displayValue").isTrue();
assertThat(status.isError()).as("Correct isError").isTrue();
assertThat(status.getErrorMessages().length == 1).as("Correct errorMessages").isTrue();
assertThat("message1".equals(status.getErrorMessage())).as("Correct errorMessage").isTrue();
assertThat("message1".equals(status.getErrorMessagesAsString(","))).as("Correct errorMessagesAsString").isTrue();
tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb.*");
assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertThat(status != null).as("Has status variable").isTrue();
assertThat("*".equals(status.getExpression())).as("Correct expression").isTrue();
assertThat(status.getValue() == null).as("Correct value").isTrue();
assertThat("".equals(status.getDisplayValue())).as("Correct displayValue").isTrue();
assertThat(status.isError()).as("Correct isError").isTrue();
assertThat(status.getErrorMessages().length == 1).as("Correct errorMessages").isTrue();
assertThat("message1".equals(status.getErrorMessage())).as("Correct errorMessage").isTrue();
assertThat("message1".equals(status.getErrorMessagesAsString(","))).as("Correct errorMessagesAsString").isTrue();
}
Aggregations