Search in sources :

Example 16 with BindException

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

the class DefaultDistributedStatusServiceTest method testFindLocationSpecificStatusInvalidApplication.

public void testFindLocationSpecificStatusInvalidApplication() {
    DistributedStatusDetailsCommand command = new DistributedStatusDetailsCommand();
    Errors errors = new BindException(command, "command");
    command.setLocation(m_locationDefinition1.getLocationName());
    command.setApplication("invalid application");
    expect(m_monitoringLocationDao.get(m_locationDefinition1.getLocationName())).andReturn(m_locationDefinition1);
    expect(m_applicationDao.findByName(command.getApplication())).andReturn(null);
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalArgumentException("Could not find application for application name \"" + command.getApplication() + "\""));
    m_easyMockUtils.replayAll();
    try {
        m_service.findLocationSpecificStatus(command, errors);
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    m_easyMockUtils.verifyAll();
    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)

Example 17 with BindException

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

the class DefaultDistributedStatusServiceTest method testFindLocationSpecificStatus.

public void testFindLocationSpecificStatus() {
    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();
    List<OnmsLocationSpecificStatus> status = m_service.findLocationSpecificStatus(command, errors);
    m_easyMockUtils.verifyAll();
    assertEquals("status list size", 2, status.size());
}
Also used : Errors(org.springframework.validation.Errors) DistributedStatusDetailsCommand(org.opennms.web.svclayer.model.DistributedStatusDetailsCommand) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) BindException(org.springframework.validation.BindException)

Example 18 with BindException

use of org.springframework.validation.BindException 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 19 with BindException

use of org.springframework.validation.BindException 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 20 with BindException

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

the class DefaultDistributedPollerServiceTest method testResumeLocationMonitorNullCommand.

public void testResumeLocationMonitorNullCommand() {
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalStateException("command argument cannot be null"));
    LocationMonitorIdCommand command = new LocationMonitorIdCommand();
    BindException errors = new BindException(command, "command");
    replayMocks();
    try {
        m_distributedPollerService.resumeLocationMonitor(null, errors);
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
    verifyMocks();
}
Also used : LocationMonitorIdCommand(org.opennms.web.svclayer.model.LocationMonitorIdCommand) 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