Search in sources :

Example 31 with BindException

use of org.springframework.validation.BindException in project spring-framework by spring-projects.

the class BindTagTests method propertyExposing.

@Test
public void propertyExposing() throws JspException {
    PageContext pc = createPageContext();
    TestBean tb = new TestBean();
    tb.setName("name1");
    Errors errors = new BindException(tb, "tb");
    errors.rejectValue("name", "code1", null, "message & 1");
    errors.rejectValue("name", "code2", null, "message2");
    pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
    // test global property (should be null)
    BindTag tag = new BindTag();
    tag.setPageContext(pc);
    tag.setPath("tb");
    assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
    assertNull(tag.getProperty());
    // test property set (tb.name)
    tag.release();
    tag.setPageContext(pc);
    tag.setPath("tb.name");
    assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
    assertEquals("name", tag.getProperty());
}
Also used : Errors(org.springframework.validation.Errors) IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) BindException(org.springframework.validation.BindException) PageContext(javax.servlet.jsp.PageContext) Test(org.junit.Test)

Example 32 with BindException

use of org.springframework.validation.BindException in project spring-framework by spring-projects.

the class DefaultHandlerExceptionResolverTests method handleBindException.

@Test
public void handleBindException() throws Exception {
    BindException ex = new BindException(new Object(), "name");
    ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
    assertNotNull("No ModelAndView returned", mav);
    assertTrue("No Empty ModelAndView returned", mav.isEmpty());
    assertEquals("Invalid status code", 400, response.getStatus());
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) BindException(org.springframework.validation.BindException) Test(org.junit.Test)

Example 33 with BindException

use of org.springframework.validation.BindException in project spring-boot by spring-projects.

the class DefaultErrorAttributesTests method extractBindingResultErrors.

@Test
public void extractBindingResultErrors() throws Exception {
    BindingResult bindingResult = new MapBindingResult(Collections.singletonMap("a", "b"), "objectName");
    bindingResult.addError(new ObjectError("c", "d"));
    Exception ex = new BindException(bindingResult);
    testBindingResult(bindingResult, ex);
}
Also used : BindingResult(org.springframework.validation.BindingResult) MapBindingResult(org.springframework.validation.MapBindingResult) ObjectError(org.springframework.validation.ObjectError) BindException(org.springframework.validation.BindException) MapBindingResult(org.springframework.validation.MapBindingResult) ServletException(javax.servlet.ServletException) MethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException) BindException(org.springframework.validation.BindException) Test(org.junit.Test)

Example 34 with BindException

use of org.springframework.validation.BindException in project opennms by OpenNMS.

the class DefaultDistributedStatusServiceTest method runTestCreateStatus.

public void runTestCreateStatus() {
    DistributedStatusDetailsCommand command = new DistributedStatusDetailsCommand();
    Errors errors = new BindException(command, "command");
    command.setLocation(m_locationDefinition1.getLocationName());
    command.setApplication(m_application1.getName());
    expectEverything();
    expect(m_monitoredServiceDao.findByApplication(m_application1)).andReturn(m_applicationServices1);
    m_easyMockUtils.replayAll();
    SimpleWebTable table = m_service.createStatusTable(command, errors);
    m_easyMockUtils.verifyAll();
    SimpleWebTable expectedTable = new SimpleWebTable();
    expectedTable.setTitle("Distributed status view for Application 1 from Raleigh location");
    expectedTable.addColumn("Node", "");
    expectedTable.addColumn("Monitor", "");
    expectedTable.addColumn("Service", "");
    expectedTable.addColumn("Status", "");
    expectedTable.addColumn("Response", "");
    expectedTable.addColumn("Last Status Change", "");
    expectedTable.addColumn("Last Update", "");
    expectedTable.newRow();
    expectedTable.addCell("Node 1", "Normal", "element/node.jsp?node=1");
    expectedTable.addCell("Raleigh-" + LOCATION_MONITOR_ID_A, "", "distributed/locationMonitorDetails.htm?monitorId=" + LOCATION_MONITOR_ID_A);
    expectedTable.addCell("HTTP", "", "element/service.jsp?ifserviceid=null");
    expectedTable.addCell("Up", "bright");
    expectedTable.addCell("", "");
    expectedTable.addCell(IGNORE_MATCH, "");
    expectedTable.addCell(IGNORE_MATCH, "");
    expectedTable.newRow();
    expectedTable.addCell("Node 1", "Indeterminate", "element/node.jsp?node=1");
    expectedTable.addCell("Raleigh-" + LOCATION_MONITOR_ID_A, "", "distributed/locationMonitorDetails.htm?monitorId=" + LOCATION_MONITOR_ID_A);
    expectedTable.addCell("HTTPS", "", "element/service.jsp?ifserviceid=null");
    expectedTable.addCell("Unknown", "bright");
    expectedTable.addCell("No status recorded for this service from this location", "");
    expectedTable.addCell(IGNORE_MATCH, "");
    expectedTable.addCell(IGNORE_MATCH, "");
    assertTableEquals(expectedTable, table);
}
Also used : Errors(org.springframework.validation.Errors) DistributedStatusDetailsCommand(org.opennms.web.svclayer.model.DistributedStatusDetailsCommand) BindException(org.springframework.validation.BindException) SimpleWebTable(org.opennms.web.svclayer.model.SimpleWebTable)

Example 35 with BindException

use of org.springframework.validation.BindException in project opennms by OpenNMS.

the class DefaultDistributedStatusServiceTest method testFindLocationSpecificStatusNullLocation.

public void testFindLocationSpecificStatusNullLocation() {
    DistributedStatusDetailsCommand command = new DistributedStatusDetailsCommand();
    Errors errors = new BindException(command, "command");
    command.setApplication(m_application1.getName());
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalArgumentException("location cannot be null"));
    try {
        m_service.findLocationSpecificStatus(command, errors);
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
}
Also used : Errors(org.springframework.validation.Errors) DistributedStatusDetailsCommand(org.opennms.web.svclayer.model.DistributedStatusDetailsCommand) BindException(org.springframework.validation.BindException) ThrowableAnticipator(org.opennms.test.ThrowableAnticipator)

Aggregations

BindException (org.springframework.validation.BindException)40 Errors (org.springframework.validation.Errors)15 LocationMonitorIdCommand (org.opennms.web.svclayer.model.LocationMonitorIdCommand)11 Test (org.junit.Test)9 ObjectError (org.springframework.validation.ObjectError)9 ThrowableAnticipator (org.opennms.test.ThrowableAnticipator)8 DistributedStatusDetailsCommand (org.opennms.web.svclayer.model.DistributedStatusDetailsCommand)8 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)6 Map (java.util.Map)3 SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)3 BindingResult (org.springframework.validation.BindingResult)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 HashMap (java.util.HashMap)2 List (java.util.List)2 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)2 StatisticsReportCommand (org.opennms.web.svclayer.model.StatisticsReportCommand)2 BeanWrapper (org.springframework.beans.BeanWrapper)2 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)2 TypeMismatchException (org.springframework.beans.TypeMismatchException)2 FieldError (org.springframework.validation.FieldError)2