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();
}
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());
}
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());
}
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;
}
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;
}
Aggregations