use of org.opennms.web.svclayer.model.LocationMonitorIdCommand 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.opennms.web.svclayer.model.LocationMonitorIdCommand 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();
}
use of org.opennms.web.svclayer.model.LocationMonitorIdCommand in project opennms by OpenNMS.
the class DefaultDistributedPollerServiceTest method testPauseLocationMonitorSuccess.
public void testPauseLocationMonitorSuccess() {
OnmsLocationMonitor locationMonitor = new OnmsLocationMonitor();
locationMonitor.setId(LOCATION_MONITOR_ID);
locationMonitor.setStatus(MonitorStatus.STARTED);
expect(m_locationMonitorDao.load(locationMonitor.getId())).andReturn(locationMonitor);
m_locationMonitorDao.update(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", 0, errors.getErrorCount());
assertEquals("new monitor status", MonitorStatus.PAUSED, locationMonitor.getStatus());
}
use of org.opennms.web.svclayer.model.LocationMonitorIdCommand in project opennms by OpenNMS.
the class LocationMonitorIdValidator method validate.
/** {@inheritDoc} */
@Override
public void validate(Object obj, Errors errors) {
LocationMonitorIdCommand cmd = (LocationMonitorIdCommand) obj;
if (cmd.getMonitorId() == null) {
errors.rejectValue("monitorId", "monitorId.notSpecified", new Object[] { "monitorId" }, "Value required.");
} else {
try {
String monitorId = cmd.getMonitorId();
OnmsLocationMonitor monitor = m_locationMonitorDao.get(monitorId);
if (monitor == null) {
throw new ObjectRetrievalFailureException(OnmsLocationMonitor.class, monitorId, "Could not find location monitor with id " + monitorId, null);
}
} catch (DataAccessException e) {
errors.rejectValue("monitorId", "monitorId.notFound", new Object[] { "monitorId", cmd.getMonitorId() }, "Valid location monitor ID required.");
}
}
}
use of org.opennms.web.svclayer.model.LocationMonitorIdCommand in project opennms by OpenNMS.
the class DefaultDistributedPollerServiceTest method testDeleteLocationMonitorNullBindException.
public void testDeleteLocationMonitorNullBindException() {
ThrowableAnticipator ta = new ThrowableAnticipator();
ta.anticipate(new IllegalStateException("errors argument cannot be null"));
LocationMonitorIdCommand command = new LocationMonitorIdCommand();
replayMocks();
try {
m_distributedPollerService.deleteLocationMonitor(command, null);
} catch (Throwable t) {
ta.throwableReceived(t);
}
ta.verifyAnticipated();
verifyMocks();
}
Aggregations