package org.opennms.report.availability;

import java.beans.PropertyVetoException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Date;

import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.ValidationException;
import org.opennms.netmgt.config.C3P0ConnectionFactory;
import org.opennms.netmgt.config.DataSourceFactory;
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
import org.springframework.transaction.annotation.Transactional;

public class AvailabilityReportSchedulerServiceTest extends AbstractTransactionalDataSourceSpringContextTests{
        private AvailabilityReportLocatorService m_locatorService;
        private AvailabilityReportSchedulerService m_schedulerService;
        
        public AvailabilityReportSchedulerServiceTest() throws MarshalException, ValidationException, IOException, PropertyVetoException, SQLException {
            /*
             * Note: I'm using the opennms-database.xml file in target/classes/etc
             * so that it has been filtered first.
             */
            DataSourceFactory.setInstance(new C3P0ConnectionFactory("../opennms-daemon/target/classes/etc/opennms-database.xml"));
        }
	
	@Override
	protected String[] getConfigLocations() {
		return new String[] {
				"META-INF/opennms/applicationContext-dao.xml",
				"org/opennms/report/svclayer/applicationContext-svclayer.xml" };
	}
        
	public void testBogus() {
	    // this is just here so that JUnit doesn't complain about not having any tests
        }
	
	@Transactional(readOnly=false)
	public void FIXMEtestScheduleReport() {
		Date date = new Date();
		m_schedulerService.Schedule("all", "html", "classic", date);
		assertNotNull(m_locatorService.locateReports());
		
		
	}


	public AvailabilityReportLocatorService getLocatorService() {
		return m_locatorService;
	}


	public void setLocatorService(AvailabilityReportLocatorService locatorService) {
		m_locatorService = locatorService;
	}


	public AvailabilityReportSchedulerService getSchedulerService() {
		return m_schedulerService;
	}


	public void setSchedulerService(
			AvailabilityReportSchedulerService schedulerService) {
		m_schedulerService = schedulerService;
	}
}

@@ -355,32 +355,77 @@
 aSourceFactory;%0A
+import org.opennms.netmgt.mock.MockDatabase;%0A
 import org.sprin
@@ -491,16 +491,16 @@
 tTests;%0A
-
 import o
@@ -798,32 +798,67 @@
 hedulerService;%0A
+        private MockDatabase m_db;%0A
         %0A       
@@ -1180,16 +1180,18 @@
         
+//
 DataSour
@@ -1301,16 +1301,104 @@
 xml%22));%0A
+            m_db = new MockDatabase();%0A            DataSourceFactory.setInstance(m_db);%0A
         
@@ -1599,16 +1599,16 @@
 xml%22 %7D;%0A
-
 %09%7D%0A     
@@ -1611,16 +1611,197 @@
        %0A
+        @Override%0A        protected void onTearDownAfterTransaction() throws Exception %7B%0A            super.onTearDownAfterTransaction();%0A            m_db.drop();%0A        %7D%0A        %0A
 %09public 

Use MockDatabase for the test database... otherwise I would have had to add postgres as a test dependency (which maybe is the way it should be done....)