package org.opennms.netmgt.threshd;

import java.io.FileReader;
import java.net.InetAddress;
import java.util.HashMap;
import java.util.Properties;

import org.jmock.Mock;
import org.opennms.netmgt.config.ThresholdingConfigFactory;
import org.opennms.netmgt.mock.MockLogAppender;
import org.opennms.netmgt.mock.MockNetwork;
import org.opennms.netmgt.poller.IPv4NetworkInterface;
import org.opennms.netmgt.rrd.RrdConfig;
import org.opennms.netmgt.rrd.RrdStrategy;
import org.opennms.netmgt.rrd.RrdUtils;

public class SnmpThresholderTest extends ThresholderTestCase {

	private IPv4NetworkInterface m_iface;
	private HashMap m_serviceParameters;
	private HashMap m_parameters;
	private Mock m_mockRrdStrategy;
	private MockNetwork m_network;

	public void testCreate() {
	}
	
	protected void setUp() throws Exception {
		super.setUp();
        
        MockLogAppender.setupLogging();
//	TODO: Finish pulling up into ThresholderTestCase like LatencyThresholderTest and finish writing the test case!!
        setupDatabase();

		// set this so we don't get exceptions in the log
        RrdConfig.setProperties(new Properties());
        m_mockRrdStrategy = mock(RrdStrategy.class);
        RrdUtils.setStrategy((RrdStrategy)m_mockRrdStrategy.proxy());
        m_mockRrdStrategy.expects(atLeastOnce()).method("initialize");

		FileReader r = new FileReader("etc/examples/thresholds.xml");
        ThresholdingConfigFactory.setInstance(new ThresholdingConfigFactory(r));
        r.close();

        m_iface = new IPv4NetworkInterface(InetAddress.getByName("192.168.1.1"));
        m_serviceParameters = new HashMap();
        m_serviceParameters.put("svcName", "ICMP");
        m_parameters = new HashMap();
        m_parameters.put("thresholding-group", "icmp-latency");
        
        ThresholdingConfigFactory.getInstance().getGroup("icmp-latency").setRrdRepository("/tmp");

		SnmpThresholder m_thresholder = new SnmpThresholder();  
        m_thresholder.initialize(m_serviceParameters);
        m_thresholder.initialize(m_iface, m_parameters);

	}

	protected void tearDown() throws Exception {
		super.tearDown();
        MockLogAppender.assertNoWarningsOrGreater();
		
	}

}

@@ -53,24 +53,81 @@
 FileReader;%0A
+import java.io.InputStreamReader;%0Aimport java.io.Reader;%0A
 import java.
@@ -552,16 +552,115 @@
 rdUtils;
+%0Aimport org.springframework.core.io.ClassPathResource;%0Aimport org.springframework.core.io.Resource;
 %0A%0Apublic
@@ -1478,78 +1478,136 @@
 %0A%0A%09%09
-FileReader r = new FileReader(%22etc/examples/thresholds.xml%22);%0A        
+Resource config = new ClassPathResource(%22/test-thresholds.xml%22);%0A%09%09Reader r = new InputStreamReader(config.getInputStream());%0A%09%09
 Thre
@@ -1675,24 +1675,18 @@
 ry(r));%0A
-        
+%09%09
 r.close(

fix SnmpThresholderTest failuer due to inability to find config file