Search in sources :

Example 16 with ObjectError

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

the class DefaultDistributedStatusServiceTest method testCreateStatusNoLocationMonitor.

public void testCreateStatusNoLocationMonitor() {
    DistributedStatusDetailsCommand command = new DistributedStatusDetailsCommand();
    Errors errors = new BindException(command, "command");
    command.setLocation(m_locationDefinition3.getLocationName());
    command.setApplication(m_application2.getName());
    expect(m_applicationDao.findByName("Application 2")).andReturn(m_application2);
    expect(m_monitoringLocationDao.get(m_locationDefinition3.getLocationName())).andReturn(m_locationDefinition3);
    expect(m_locationMonitorDao.findByLocationDefinition(m_locationDefinition3)).andReturn(new HashSet<OnmsLocationMonitor>());
    m_easyMockUtils.replayAll();
    SimpleWebTable table = m_service.createStatusTable(command, errors);
    Errors errorsOut = table.getErrors();
    assertEquals("Number of errors", 1, errorsOut.getErrorCount());
    assertEquals("Number of global errors", 1, errorsOut.getGlobalErrorCount());
    assertEquals("Number of field errors", 0, errorsOut.getFieldErrorCount());
    ObjectError e = (ObjectError) errorsOut.getGlobalErrors().get(0);
    assertEquals("Error code 0", "location.no-monitors", e.getCode());
    assertEquals("Error 0 argument count", 2, e.getArguments().length);
    assertEquals("Error argument 0.0", "Application 2", e.getArguments()[0]);
    assertEquals("Error argument 0.0", "Columbus", e.getArguments()[1]);
    m_easyMockUtils.verifyAll();
}
Also used : Errors(org.springframework.validation.Errors) ObjectError(org.springframework.validation.ObjectError) DistributedStatusDetailsCommand(org.opennms.web.svclayer.model.DistributedStatusDetailsCommand) BindException(org.springframework.validation.BindException) SimpleWebTable(org.opennms.web.svclayer.model.SimpleWebTable) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor)

Example 17 with ObjectError

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

the class DefaultDistributedPollerServiceTest method testDeleteLocationMonitorBindingErrors.

public void testDeleteLocationMonitorBindingErrors() {
    LocationMonitorIdCommand command = new LocationMonitorIdCommand();
    BindException errors = new BindException(command, "command");
    errors.addError(new ObjectError("foo", null, null, "foo"));
    assertEquals("error count before pause", 1, errors.getErrorCount());
    replayMocks();
    m_distributedPollerService.deleteLocationMonitor(command, errors);
    verifyMocks();
    assertEquals("error count after pause", 1, errors.getErrorCount());
}
Also used : LocationMonitorIdCommand(org.opennms.web.svclayer.model.LocationMonitorIdCommand) ObjectError(org.springframework.validation.ObjectError) BindException(org.springframework.validation.BindException)

Example 18 with ObjectError

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

the class DefaultDistributedPollerServiceTest method testPauseLocationMonitorAlreadyPaused.

public void testPauseLocationMonitorAlreadyPaused() {
    OnmsLocationMonitor locationMonitor = new OnmsLocationMonitor();
    locationMonitor.setId(LOCATION_MONITOR_ID);
    locationMonitor.setStatus(MonitorStatus.PAUSED);
    expect(m_locationMonitorDao.load(locationMonitor.getId())).andReturn(locationMonitor);
    LocationMonitorIdCommand command = new LocationMonitorIdCommand();
    command.setMonitorId(LOCATION_MONITOR_ID);
    BindException errors = new BindException(command, "command");
    replayMocks();
    m_distributedPollerService.pauseLocationMonitor(command, errors);
    verifyMocks();
    assertEquals("error count", 1, errors.getErrorCount());
    List<ObjectError> errorList = getErrorList(errors);
    assertEquals("error list count", 1, errorList.size());
    assertEquals("error 0 code", "distributed.locationMonitor.alreadyPaused", errorList.get(0).getCode());
}
Also used : LocationMonitorIdCommand(org.opennms.web.svclayer.model.LocationMonitorIdCommand) ObjectError(org.springframework.validation.ObjectError) BindException(org.springframework.validation.BindException) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor)

Example 19 with ObjectError

use of org.springframework.validation.ObjectError in project OpenClinica by OpenClinica.

the class EventEndpoint method mapFailConfirmation.

/**
     * Create Error Response
     * 
     * @param confirmation
     * @return
     * @throws Exception
     */
private Element mapFailConfirmation(Errors errors) throws Exception {
    DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
    Document document = docBuilder.newDocument();
    Element responseElement = document.createElementNS(NAMESPACE_URI_V1, "scheduleResponse");
    Element resultElement = document.createElementNS(NAMESPACE_URI_V1, "result");
    resultElement.setTextContent(messages.getMessage("eventEndpoint.fail", null, "Fail", locale));
    responseElement.appendChild(resultElement);
    for (ObjectError error : errors.getAllErrors()) {
        Element errorElement = document.createElementNS(NAMESPACE_URI_V1, "error");
        String theMessage = messages.getMessage(error.getCode(), error.getArguments(), locale);
        errorElement.setTextContent(theMessage);
        responseElement.appendChild(errorElement);
    }
    return responseElement;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ObjectError(org.springframework.validation.ObjectError) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 20 with ObjectError

use of org.springframework.validation.ObjectError in project OpenClinica by OpenClinica.

the class StudyEndpoint method mapConfirmation.

private Element mapConfirmation(String confirmation, Errors errors) throws Exception {
    DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
    Document document = docBuilder.newDocument();
    Element responseElement = document.createElementNS(NAMESPACE_URI_V1, "createResponse");
    Element resultElement = document.createElementNS(NAMESPACE_URI_V1, "result");
    resultElement.setTextContent(confirmation);
    responseElement.appendChild(resultElement);
    for (ObjectError error : errors.getAllErrors()) {
        Element errorElement = document.createElementNS(NAMESPACE_URI_V1, "error");
        String theMessage = messages.getMessage(error.getCode(), error.getArguments(), locale);
        errorElement.setTextContent(theMessage);
        responseElement.appendChild(errorElement);
    }
    return responseElement;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ObjectError(org.springframework.validation.ObjectError) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Aggregations

ObjectError (org.springframework.validation.ObjectError)57 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 BindException (org.springframework.validation.BindException)10 FieldError (org.springframework.validation.FieldError)8 BusinessRuleException (org.mifos.service.BusinessRuleException)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 BindingResult (org.springframework.validation.BindingResult)6 DocumentBuilder (javax.xml.parsers.DocumentBuilder)5 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)5 Test (org.junit.Test)5 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)5 LocationMonitorIdCommand (org.opennms.web.svclayer.model.LocationMonitorIdCommand)5 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)5 MapBindingResult (org.springframework.validation.MapBindingResult)5 Document (org.w3c.dom.Document)5 Element (org.w3c.dom.Element)5 ArrayList (java.util.ArrayList)3 Errors (org.springframework.validation.Errors)3 MethodArgumentNotValidException (org.springframework.web.bind.MethodArgumentNotValidException)3 ServletException (javax.servlet.ServletException)2