package org.opennms.web.svclayer;

import static org.easymock.EasyMock.createMock;

import java.io.FileReader;

import org.opennms.netmgt.config.CategoryFactory;
import org.opennms.netmgt.config.SiteStatusViewsFactory;
import org.opennms.netmgt.config.SurveillanceViewsFactory;
import org.opennms.netmgt.config.ViewsDisplayFactory;
import org.opennms.netmgt.model.DemandPoll;
import org.opennms.web.services.PollerService;
import org.opennms.web.svclayer.support.DefaultDemandPollService;
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
import org.springframework.transaction.annotation.Transactional;

public class DefaultPollServiceIntegrationTest extends AbstractTransactionalDataSourceSpringContextTests{

	private DemandPollService m_demandPollService;
        
        public DefaultPollServiceIntegrationTest() throws Exception {
            System.setProperty("opennms.home", "src/test/opennms-home");

            SurveillanceViewsFactory.setInstance(new SurveillanceViewsFactory("../opennms-daemon/src/main/filtered/etc/surveillance-views.xml"));
            SiteStatusViewsFactory.setInstance(new SiteStatusViewsFactory("../opennms-daemon/src/main/filtered/etc/site-status-views.xml"));
            
            CategoryFactory.setInstance(new CategoryFactory(new FileReader("../opennms-daemon/src/main/filtered/etc/categories.xml")));
            ViewsDisplayFactory.setInstance(new ViewsDisplayFactory("../opennms-daemon/src/main/filtered/etc/viewsdisplay.xml"));

        }
	
	@Override
	protected String[] getConfigLocations() {
		return new String[] {
				"META-INF/opennms/applicationContext-dao.xml",
				"org/opennms/web/svclayer/applicationContext-svclayer.xml",
                                "org/opennms/web/svclayer/applicationContext-svclayer-test.xml"
		};
	}

	public DemandPollService getDemandPollService() {
		return m_demandPollService;
	}

	public void setDemandPollService(DemandPollService pollService) {
		m_demandPollService = pollService;
	}
        
        public void testBogus() {
            // Empty test to keep JUnit from complaining about no tests
        }
	
	@Transactional(readOnly=false)
	public void FIXMEtestPollMonitoredService() {
		PollerService api = createMock(PollerService.class);
		((DefaultDemandPollService)m_demandPollService).setPollerAPI(api);
		
		DemandPoll poll = m_demandPollService.pollMonitoredService(1, "192.168.2.100", 1, 1);
		assertNotNull("DemandPoll should not be null", poll);
		assertTrue("Polled service addr doesn't match...", poll.getId() >= 1);
	}
}

@@ -77,16 +77,37 @@
 eMock;%0A%0A
+import java.io.File;%0A
 import j
@@ -812,32 +812,25 @@
 e;%0A        %0A
-        
+%09
 public Defau
@@ -883,657 +883,365 @@
 n %7B%0A
-            System.setProperty(%22opennms.home%22, %22src/test/opennms-home%22);%0A%0A            SurveillanceViewsFactory.setInstance(new SurveillanceViewsFactory(%22../opennms-daemon/src/main/filtered/etc/surveillance-views.xml%22));%0A            SiteStatusViewsFactory.setInstance(new SiteStatusViewsFactory(%22../opennms-daemon/src/main/filtered/etc/site-status-views.xml%22));%0A            %0A            CategoryFactory.setInstance(new CategoryFactory(new FileReader(%22../opennms-daemon/src/main/filtered/etc/categories.xml%22)));%0A            ViewsDisplayFactory.setInstance(new ViewsDisplayFactory(%22../opennms-daemon/src/main/filtered/etc/viewsdisplay.xml%22));%0A%0A        
+%09%09File f = new File(%22src/test/opennms-home%22);%0A%09%09System.setProperty(%22opennms.home%22, f.getAbsolutePath());%0A%0A%09%09File rrdDir = new File(%22target/test/opennms-home/share/rrd%22);%0A%09%09if (!rrdDir.exists()) %7B%0A%09%09%09rrdDir.mkdirs();%0A%09%09%7D%0A%09%09System.setProperty(%22opennms.logs.dir%22, %22src/test/opennms-home/logs%22);%0A%09%09System.setProperty(%22rrd.base.dir%22, rrdDir.getAbsolutePath());%0A%09
 %7D%0A%09%0A
@@ -1437,104 +1437,8 @@
 l%22,%0A
-                                %22org/opennms/web/svclayer/applicationContext-svclayer-test.xml%22%0A
 %09%09%7D;

make tests pass -- reviewed by joed