Search in sources :

Example 16 with FileAnticipator

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<>();
}
Also used : FileWriter(java.io.FileWriter) PollOutagesConfigFactory(org.opennms.netmgt.config.PollOutagesConfigFactory) FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) FileSystemResource(org.springframework.core.io.FileSystemResource) Date(java.util.Date) FilterDao(org.opennms.netmgt.filter.api.FilterDao) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) FileAnticipator(org.opennms.test.FileAnticipator) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Before(org.junit.Before)

Example 17 with FileAnticipator

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<>();
}
Also used : MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) FileWriter(java.io.FileWriter) PollOutagesConfigFactory(org.opennms.netmgt.config.PollOutagesConfigFactory) FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) FileSystemResource(org.springframework.core.io.FileSystemResource) Date(java.util.Date) EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator) BigInteger(java.math.BigInteger) FilterDao(org.opennms.netmgt.filter.api.FilterDao) JdbcFilterDao(org.opennms.netmgt.filter.JdbcFilterDao) EventIpcManager(org.opennms.netmgt.events.api.EventIpcManager) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) FileAnticipator(org.opennms.test.FileAnticipator) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Before(org.junit.Before)

Example 18 with FileAnticipator

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();
}
Also used : ResourceTypesDao(org.opennms.netmgt.config.api.ResourceTypesDao) ArrayList(java.util.ArrayList) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) EasyMockUtils(org.opennms.test.mock.EasyMockUtils) LocationMonitorDao(org.opennms.netmgt.dao.api.LocationMonitorDao) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) NodeDao(org.opennms.netmgt.dao.api.NodeDao) FilterDao(org.opennms.netmgt.filter.api.FilterDao) JRobinRrdStrategy(org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy) FileAnticipator(org.opennms.test.FileAnticipator) Before(org.junit.Before)

Example 19 with FileAnticipator

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();
}
Also used : FileAnticipator(org.opennms.test.FileAnticipator) File(java.io.File)

Example 20 with FileAnticipator

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);
}
Also used : HttpCollectionConfigFactory(org.opennms.netmgt.config.HttpCollectionConfigFactory) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) DatabaseSchemaConfigFactory(org.opennms.netmgt.config.DatabaseSchemaConfigFactory) FileAnticipator(org.opennms.test.FileAnticipator) DefaultDataCollectionConfigDao(org.opennms.netmgt.config.DefaultDataCollectionConfigDao)

Aggregations

FileAnticipator (org.opennms.test.FileAnticipator)24 Before (org.junit.Before)15 File (java.io.File)7 JRobinRrdStrategy (org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy)6 FilterDao (org.opennms.netmgt.filter.api.FilterDao)4 ArrayList (java.util.ArrayList)3 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)3 FilesystemResourceStorageDao (org.opennms.netmgt.dao.support.FilesystemResourceStorageDao)3 EasyMockUtils (org.opennms.test.mock.EasyMockUtils)3 FileSystemResource (org.springframework.core.io.FileSystemResource)3 FileWriter (java.io.FileWriter)2 InputStream (java.io.InputStream)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 PollOutagesConfigFactory (org.opennms.netmgt.config.PollOutagesConfigFactory)2 ResourceTypesDao (org.opennms.netmgt.config.api.ResourceTypesDao)2 LocationMonitorDao (org.opennms.netmgt.dao.api.LocationMonitorDao)2 NodeDao (org.opennms.netmgt.dao.api.NodeDao)2 MockEventIpcManager (org.opennms.netmgt.dao.mock.MockEventIpcManager)2