use of org.opennms.netmgt.model.OnmsLocationMonitor 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.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.
the class DefaultDistributedPollerServiceTest method testResumeLocationMonitorSuccess.
public void testResumeLocationMonitorSuccess() {
OnmsLocationMonitor locationMonitor = new OnmsLocationMonitor();
locationMonitor.setId(LOCATION_MONITOR_ID);
locationMonitor.setStatus(MonitorStatus.PAUSED);
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.resumeLocationMonitor(command, errors);
verifyMocks();
assertEquals("error count", 0, errors.getErrorCount());
assertEquals("new monitor status", MonitorStatus.STARTED, locationMonitor.getStatus());
}
use of org.opennms.netmgt.model.OnmsLocationMonitor in project opennms by OpenNMS.
the class DefaultDistributedStatusServiceTest method testCreateFacilityStatusTableLayoutApplicationsVertically.
/*
* XXX need to check sorting
*/
public void testCreateFacilityStatusTableLayoutApplicationsVertically() throws Exception {
// No need to shuffle, since this is a list
List<OnmsMonitoringLocation> locationDefinitions = new LinkedList<OnmsMonitoringLocation>();
locationDefinitions.add(m_locationDefinition1);
locationDefinitions.add(m_locationDefinition2);
locationDefinitions.add(m_locationDefinition3);
List<OnmsApplication> applications = new LinkedList<OnmsApplication>();
applications.add(m_application1);
applications.add(m_application2);
Collections.shuffle(applications);
OnmsMonitoredService httpService = findMonitoredService(m_services, m_ip, "HTTP");
OnmsMonitoredService httpsService = findMonitoredService(m_services, m_ip, "HTTPS");
OnmsMonitoredService icmpService = findMonitoredService(m_services, m_ip, "ICMP");
Collection<OnmsLocationSpecificStatus> mostRecentStatuses = new LinkedList<OnmsLocationSpecificStatus>();
mostRecentStatuses.add(createStatus(m_locationMonitor1_1, httpService, PollStatus.available(), "20061011-00:00:00"));
mostRecentStatuses.add(createStatus(m_locationMonitor1_1, httpsService, PollStatus.available(), "20061012-06:00:00"));
mostRecentStatuses.add(createStatus(m_locationMonitor2_1, httpService, PollStatus.available(), "20061011-00:00:00"));
mostRecentStatuses.add(createStatus(m_locationMonitor2_1, httpsService, PollStatus.available(), "20061012-06:00:00"));
mostRecentStatuses.add(createStatus(m_locationMonitor2_2, httpService, PollStatus.available(), "20061011-00:00:00"));
mostRecentStatuses.add(createStatus(m_locationMonitor2_2, httpsService, PollStatus.available(), "20061012-06:00:00"));
Collection<OnmsLocationSpecificStatus> statusChanges = new LinkedList<OnmsLocationSpecificStatus>();
statusChanges.add(createStatus(m_locationMonitor1_1, httpService, PollStatus.available(), "20061011-00:00:00"));
statusChanges.add(createStatus(m_locationMonitor1_1, httpsService, PollStatus.unavailable(), "20061012-00:00:00"));
statusChanges.add(createStatus(m_locationMonitor1_1, httpsService, PollStatus.available(), "20061012-06:00:00"));
statusChanges.add(createStatus(m_locationMonitor1_1, icmpService, PollStatus.down(), "20061010-06:00:00"));
Date startDate = s_dbDate.parse("2006-10-12 00:00:00.0");
Date endDate = s_dbDate.parse("2006-10-13 00:00:00.0");
expect(m_monitoringLocationDao.findAll()).andReturn(locationDefinitions);
expect(m_applicationDao.findAll()).andReturn(applications);
expect(m_locationMonitorDao.getAllMostRecentStatusChanges()).andReturn(mostRecentStatuses);
expect(m_locationMonitorDao.findByLocationDefinition(locationDefinitions.get(0))).andReturn(Collections.singleton(m_locationMonitor1_1));
Collection<OnmsLocationMonitor> monitors2 = new HashSet<OnmsLocationMonitor>();
monitors2.add(m_locationMonitor2_1);
monitors2.add(m_locationMonitor2_2);
expect(m_locationMonitorDao.findByLocationDefinition(locationDefinitions.get(1))).andReturn(monitors2);
expect(m_locationMonitorDao.findByLocationDefinition(locationDefinitions.get(2))).andReturn(new HashSet<OnmsLocationMonitor>());
expect(m_locationMonitorDao.getStatusChangesBetween(startDate, endDate)).andReturn(statusChanges);
expect(m_locationMonitorDao.getAllStatusChangesAt(startDate)).andReturn(new HashSet<OnmsLocationSpecificStatus>());
expect(m_monitoredServiceDao.findByApplication(m_application1)).andReturn(m_applicationServices1).times(3);
expect(m_monitoredServiceDao.findByApplication(m_application2)).andReturn(m_applicationServices2).times(3);
m_service.setLayoutApplicationsVertically(true);
m_easyMockUtils.replayAll();
SimpleWebTable table = m_service.createFacilityStatusTable(startDate, endDate);
m_easyMockUtils.verifyAll();
SimpleWebTable expectedTable = new SimpleWebTable();
expectedTable.setTitle("Distributed Status Summary");
expectedTable.addColumn("Application", "");
expectedTable.addColumn("Raleigh", "");
expectedTable.addColumn("Durham", "");
expectedTable.addColumn("Columbus", "");
expectedTable.newRow();
expectedTable.addCell("Application 1", "");
expectedTable.addCell("75.000%", "Normal", "distributedStatusHistory.htm?location=Raleigh&application=Application+1");
expectedTable.addCell("No data", "Normal");
expectedTable.addCell("No data", "Indeterminate");
expectedTable.newRow();
expectedTable.addCell("Application 2", "");
expectedTable.addCell("75.000%", "Normal", "distributedStatusHistory.htm?location=Raleigh&application=Application+2");
expectedTable.addCell("No data", "Normal");
expectedTable.addCell("No data", "Indeterminate");
assertTableEquals(expectedTable, table);
}
use of org.opennms.netmgt.model.OnmsLocationMonitor 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.netmgt.model.OnmsLocationMonitor 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());
}
Aggregations