use of org.opennms.test.FileAnticipator in project opennms by OpenNMS.
the class LatencyThresholdingSetIT method setUp.
@Before
public void setUp() throws Exception {
BeanUtils.setStaticApplicationContext(m_context);
// Resets Counters Cache Data
CollectionResourceWrapper.s_cache.clear();
MockLogAppender.setupLogging();
m_fileAnticipator = new FileAnticipator();
m_resourceStorageDao = new FilesystemResourceStorageDao();
m_resourceStorageDao.setRrdDirectory(m_fileAnticipator.getTempDir());
// Use a mock FilterDao that always returns 127.0.0.1 in the active IP list
FilterDao filterDao = EasyMock.createMock(FilterDao.class);
EasyMock.expect(filterDao.getActiveIPAddressList((String) EasyMock.anyObject())).andReturn(Collections.singletonList(addr("127.0.0.1"))).anyTimes();
filterDao.flushActiveIpAddressListCache();
EasyMock.expectLastCall().anyTimes();
FilterDaoFactory.setInstance(filterDao);
EasyMock.replay(filterDao);
DateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
final StringBuilder sb = new StringBuilder("<?xml version=\"1.0\"?>");
sb.append("<outages>");
sb.append("<outage name=\"junit outage\" type=\"specific\">");
sb.append("<time begins=\"");
sb.append(formatter.format(new Date(System.currentTimeMillis() - 3600000)));
sb.append("\" ends=\"");
sb.append(formatter.format(new Date(System.currentTimeMillis() + 3600000)));
sb.append("\"/>");
sb.append("<interface address=\"match-any\"/>");
sb.append("</outage>");
sb.append("</outages>");
File file = new File("target/poll-outages.xml");
FileWriter writer = new FileWriter(file);
writer.write(sb.toString());
writer.close();
PollOutagesConfigFactory.setInstance(new PollOutagesConfigFactory(new FileSystemResource(file)));
PollOutagesConfigFactory.getInstance().afterPropertiesSet();
initFactories("/threshd-configuration.xml", "/test-thresholds.xml");
m_anticipatedEvents = new ArrayList<>();
}
use of org.opennms.test.FileAnticipator in project opennms by OpenNMS.
the class ThresholdingVisitorIT method setUp.
@Before
public void setUp() throws Exception {
// Resets Counters Cache Data
CollectionResourceWrapper.s_cache.clear();
MockLogAppender.setupLogging();
m_fileAnticipator = new FileAnticipator();
m_hrStorageProperties = new HashMap<Integer, File>();
m_resourceStorageDao = new FilesystemResourceStorageDao();
m_resourceStorageDao.setRrdDirectory(new File(m_fileAnticipator.getTempDir(), "snmp"));
m_filterDao = EasyMock.createMock(FilterDao.class);
EasyMock.expect(m_filterDao.getActiveIPAddressList((String) EasyMock.anyObject())).andReturn(Collections.singletonList(addr("127.0.0.1"))).anyTimes();
m_filterDao.flushActiveIpAddressListCache();
EasyMock.expectLastCall().anyTimes();
FilterDaoFactory.setInstance(m_filterDao);
EasyMock.replay(m_filterDao);
m_anticipator = new EventAnticipator();
MockEventIpcManager eventMgr = new MockEventIpcManager();
eventMgr.setEventAnticipator(m_anticipator);
eventMgr.setSynchronous(true);
EventIpcManager eventdIpcMgr = (EventIpcManager) eventMgr;
EventIpcManagerFactory.setIpcManager(eventdIpcMgr);
DateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
final StringBuilder sb = new StringBuilder("<?xml version=\"1.0\"?>");
sb.append("<outages>");
sb.append("<outage name=\"junit outage\" type=\"specific\">");
sb.append("<time begins=\"");
sb.append(formatter.format(new Date(System.currentTimeMillis() - 3600000)));
sb.append("\" ends=\"");
sb.append(formatter.format(new Date(System.currentTimeMillis() + 3600000)));
sb.append("\"/>");
sb.append("<interface address=\"match-any\"/>");
sb.append("</outage>");
sb.append("</outages>");
File file = new File("target/poll-outages.xml");
FileWriter writer = new FileWriter(file);
writer.write(sb.toString());
writer.close();
PollOutagesConfigFactory.setInstance(new PollOutagesConfigFactory(new FileSystemResource(file)));
PollOutagesConfigFactory.getInstance().afterPropertiesSet();
initFactories("/threshd-configuration.xml", "/test-thresholds.xml");
m_anticipatedEvents = new ArrayList<>();
}
use of org.opennms.test.FileAnticipator in project opennms by OpenNMS.
the class DefaultResourceDaoTest method setUp.
@Before
public void setUp() throws Exception {
m_fileAnticipator = new FileAnticipator();
m_easyMockUtils = new EasyMockUtils();
m_nodeDao = m_easyMockUtils.createMock(NodeDao.class);
m_locationMonitorDao = m_easyMockUtils.createMock(LocationMonitorDao.class);
m_resourceTypesDao = m_easyMockUtils.createMock(ResourceTypesDao.class);
m_filterDao = m_easyMockUtils.createMock(FilterDao.class);
m_ipInterfaceDao = m_easyMockUtils.createMock(IpInterfaceDao.class);
FilterDaoFactory.setInstance(m_filterDao);
expect(m_filterDao.getActiveIPAddressList("IPADDR IPLIKE *.*.*.*")).andReturn(new ArrayList<InetAddress>(0)).anyTimes();
m_easyMockUtils.replayAll();
setUpCollectdConfigFactory();
m_easyMockUtils.verifyAll();
RrdStrategy<?, ?> rrdStrategy = new JRobinRrdStrategy();
m_rrdFileExtension = rrdStrategy.getDefaultFileExtension();
m_resourceStorageDao.setRrdDirectory(m_fileAnticipator.getTempDir());
m_resourceStorageDao.setRrdStrategy(rrdStrategy);
m_resourceDao = new DefaultResourceDao();
m_resourceDao.setNodeDao(m_nodeDao);
m_resourceDao.setLocationMonitorDao(m_locationMonitorDao);
m_resourceDao.setIpInterfaceDao(m_ipInterfaceDao);
m_resourceDao.setCollectdConfig(m_collectdConfig);
m_resourceDao.setResourceTypesDao(m_resourceTypesDao);
m_resourceDao.setResourceStorageDao(m_resourceStorageDao);
expect(m_resourceTypesDao.getResourceTypes()).andReturn(new HashMap<String, ResourceType>());
expect(m_resourceTypesDao.getLastUpdate()).andReturn(m_lastUpdateTime);
m_easyMockUtils.replayAll();
m_resourceDao.afterPropertiesSet();
m_easyMockUtils.verifyAll();
}
use of org.opennms.test.FileAnticipator in project opennms by OpenNMS.
the class InstallerWebappTest method setUp.
public void setUp() throws IOException, SQLException {
m_anticipator = new FileAnticipator();
File dist = m_anticipator.tempDir("dist");
File dist_webapps = m_anticipator.tempDir(dist, "webapps");
File opennms_webapp = m_anticipator.tempDir(dist_webapps, "opennms");
File meta_inf = m_anticipator.tempDir(opennms_webapp, "META-INF");
m_anticipator.tempFile(meta_inf, "context.xml");
File web_inf = m_anticipator.tempDir(opennms_webapp, "WEB-INF");
File lib = m_anticipator.tempDir(web_inf, "lib");
m_anticipator.tempFile(lib, "log4j.jar");
m_anticipator.tempFile(lib, "opennms_core.jar");
m_anticipator.tempFile(lib, "opennms_services.jar");
m_anticipator.tempFile(lib, "opennms_web.jar");
m_tomcat = m_anticipator.tempDir("tomcat");
m_tomcat_webapps = m_anticipator.tempDir(m_tomcat, "webapps");
m_tomcat_conf_dir = m_anticipator.tempDir(m_tomcat, "conf");
File tomcat_server = m_anticipator.tempDir(m_tomcat, "server");
File tomcat_lib = m_anticipator.tempDir(tomcat_server, "lib");
m_anticipator.expecting(m_tomcat_webapps, "opennms.xml");
m_anticipator.expecting(tomcat_lib, "log4j.jar");
m_anticipator.expecting(tomcat_lib, "opennms_core.jar");
m_anticipator.expecting(tomcat_lib, "opennms_services.jar");
m_anticipator.expecting(tomcat_lib, "opennms_web.jar");
m_installer = new Installer();
m_installer.m_install_servletdir = opennms_webapp.getAbsolutePath();
m_installer.m_webappdir = m_tomcat_webapps.getAbsolutePath();
}
use of org.opennms.test.FileAnticipator in project opennms by OpenNMS.
the class JUnitCollectorExecutionListener method beforeTestMethod.
@Override
public void beforeTestMethod(TestContext testContext) throws Exception {
m_fileAnticipator = new FileAnticipator();
JUnitCollector config = findCollectorAnnotation(testContext);
if (config == null) {
return;
}
// make a fake database schema with hibernate
InputStream is = ConfigurationTestUtils.getInputStreamForResource(testContext.getTestInstance(), config.schemaConfig());
DatabaseSchemaConfigFactory.setInstance(new DatabaseSchemaConfigFactory(is));
is.close();
// set up temporary directories for RRD files
m_snmpRrdDirectory = m_fileAnticipator.tempDir("snmp");
m_snmpRrdDirectory.mkdirs();
testContext.setAttribute("fileAnticipator", m_fileAnticipator);
testContext.setAttribute("rrdDirectory", m_snmpRrdDirectory);
// set up the collection configuration factory
if ("http".equalsIgnoreCase(config.datacollectionType()) || "https".equalsIgnoreCase(config.datacollectionType())) {
is = ConfigurationTestUtils.getInputStreamForResourceWithReplacements(testContext.getTestInstance(), config.datacollectionConfig(), new String[] { "%rrdRepository%", m_snmpRrdDirectory.getAbsolutePath() });
HttpCollectionConfigFactory factory = new HttpCollectionConfigFactory(is);
HttpCollectionConfigFactory.setInstance(factory);
HttpCollectionConfigFactory.init();
} else if ("snmp".equalsIgnoreCase(config.datacollectionType())) {
Resource r = ConfigurationTestUtils.getSpringResourceForResourceWithReplacements(testContext.getTestInstance(), config.datacollectionConfig(), new String[] { "%rrdRepository%", m_snmpRrdDirectory.getAbsolutePath() });
DefaultDataCollectionConfigDao dataCollectionDao = new DefaultDataCollectionConfigDao();
dataCollectionDao.setConfigResource(r);
dataCollectionDao.afterPropertiesSet();
DataCollectionConfigFactory.setInstance(dataCollectionDao);
} else {
throw new UnsupportedOperationException("data collection type '" + config.datacollectionType() + "' not supported");
}
IOUtils.closeQuietly(is);
}
Aggregations