Merge "Issue #1543 Clean up test files after changing to Spring transactions" into development

Former-commit-id: 9f5b5f5346 [formerly 5152c8f857] [formerly 9f5b5f5346 [formerly 5152c8f857] [formerly 583f76b366 [formerly add04e9858bcbd7a503c11606e1d4a820885f980]]]
Former-commit-id: 583f76b366
Former-commit-id: 85dfef2c57 [formerly f1f06d0b02]
Former-commit-id: 46cb88afb4
This commit is contained in:
Dustin Johnson 2013-02-12 12:12:40 -06:00 committed by Gerrit Code Review
commit 3574181ae7
17 changed files with 190 additions and 107 deletions

View file

@ -13,6 +13,7 @@
<classpathentry exported="true" kind="lib" path="spring-jms.jar" sourcepath="spring-framework-2.5.6.zip"/> <classpathentry exported="true" kind="lib" path="spring-jms.jar" sourcepath="spring-framework-2.5.6.zip"/>
<classpathentry exported="true" kind="lib" path="spring-orm.jar" sourcepath="spring-framework-2.5.6.zip"/> <classpathentry exported="true" kind="lib" path="spring-orm.jar" sourcepath="spring-framework-2.5.6.zip"/>
<classpathentry exported="true" kind="lib" path="spring-tx.jar" sourcepath="spring-framework-2.5.6.zip"/> <classpathentry exported="true" kind="lib" path="spring-tx.jar" sourcepath="spring-framework-2.5.6.zip"/>
<classpathentry exported="true" kind="lib" path="spring-test.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>

Binary file not shown.

View file

@ -0,0 +1,25 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:util="http://www.springframework.org/schema/util" xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="bandwidthAllocationDao"
class="com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.BandwidthAllocationDao">
<property name="sessionFactory" ref="metadataSessionFactory" />
</bean>
<bean id="bandwidthSubscriptionDao"
class="com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.BandwidthSubscriptionDao">
<property name="sessionFactory" ref="metadataSessionFactory" />
</bean>
<bean id="hibernateBandwidthDao"
class="com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.HibernateBandwidthDao">
<property name="sessionFactory" ref="metadataSessionFactory" />
<property name="bandwidthAllocationDao" ref="bandwidthAllocationDao" />
<property name="bandwidthSubscriptionDao" ref="bandwidthSubscriptionDao" />
</bean>
</beans>

View file

@ -3,7 +3,6 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<!-- Stores beans that are used in bandwidth-datadelivery.xml, but that <!-- Stores beans that are used in bandwidth-datadelivery.xml, but that
@ -19,20 +18,6 @@
<!-- Used as the context for creating the BandwidthManager --> <!-- Used as the context for creating the BandwidthManager -->
<constructor-arg ref="hibernateBandwidthDao" /> <constructor-arg ref="hibernateBandwidthDao" />
</bean> </bean>
<bean id="bandwidthAllocationDao" class="com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.BandwidthAllocationDao">
<property name="sessionFactory" ref="metadataSessionFactory" />
</bean>
<bean id="bandwidthSubscriptionDao" class="com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.BandwidthSubscriptionDao">
<property name="sessionFactory" ref="metadataSessionFactory" />
</bean>
<bean id="hibernateBandwidthDao" class="com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.HibernateBandwidthDao">
<property name="sessionFactory" ref="metadataSessionFactory" />
<property name="bandwidthAllocationDao" ref="bandwidthAllocationDao" />
<property name="bandwidthSubscriptionDao" ref="bandwidthSubscriptionDao" />
</bean>
<util:map id="retrievalAgents"> <util:map id="retrievalAgents">
<entry key="Retrievals-1" value-ref="subscriptionRetrievalAgentPrototype" /> <entry key="Retrievals-1" value-ref="subscriptionRetrievalAgentPrototype" />

View file

@ -3,5 +3,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="res"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View file

@ -0,0 +1,12 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="retrievalDao"
class="com.raytheon.uf.edex.datadelivery.retrieval.db.RetrievalDao">
<property name="sessionFactory" ref="metadataSessionFactory" />
</bean>
</beans>

View file

@ -13,10 +13,6 @@
<constructor-arg ref="ddRetrievalDatabaseProperties"/> <constructor-arg ref="ddRetrievalDatabaseProperties"/>
</bean> </bean>
<bean id="retrievalDao" class="com.raytheon.uf.edex.datadelivery.retrieval.db.RetrievalDao">
<property name="sessionFactory" ref="metadataSessionFactory" />
</bean>
<bean id="subNotifyTask" class="com.raytheon.uf.edex.datadelivery.retrieval.handlers.SubscriptionNotifyTask" /> <bean id="subNotifyTask" class="com.raytheon.uf.edex.datadelivery.retrieval.handlers.SubscriptionNotifyTask" />
<!-- A RetrievalTask takes three constructor arguments: <!-- A RetrievalTask takes three constructor arguments:

View file

@ -27,8 +27,8 @@ import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Ignore; import org.junit.Ignore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.raytheon.uf.common.datadelivery.registry.Network; import com.raytheon.uf.common.datadelivery.registry.Network;
import com.raytheon.uf.common.datadelivery.registry.Subscription; import com.raytheon.uf.common.datadelivery.registry.Subscription;
@ -37,8 +37,6 @@ import com.raytheon.uf.common.localization.PathManagerFactoryTest;
import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.common.time.util.TimeUtilTest; import com.raytheon.uf.common.time.util.TimeUtilTest;
import com.raytheon.uf.common.util.PropertiesUtil; import com.raytheon.uf.common.util.PropertiesUtil;
import com.raytheon.uf.edex.core.EDEXUtil;
import com.raytheon.uf.edex.database.dao.DatabaseUtil;
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao;
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager; import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager;
import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
@ -66,10 +64,13 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
@Ignore @Ignore
public abstract class AbstractBandwidthManagerIntTest { public abstract class AbstractBandwidthManagerIntTest {
@Autowired
protected ApplicationContext context; protected ApplicationContext context;
@Autowired
protected BandwidthManager bandwidthManager; protected BandwidthManager bandwidthManager;
@Autowired
protected RetrievalManager retrievalManager; protected RetrievalManager retrievalManager;
protected IBandwidthDao bandwidthDao; protected IBandwidthDao bandwidthDao;
@ -97,6 +98,7 @@ public abstract class AbstractBandwidthManagerIntTest {
@BeforeClass @BeforeClass
public static void staticSetup() throws IOException { public static void staticSetup() throws IOException {
PathManagerFactoryTest.initLocalization();
Properties properties = PropertiesUtil Properties properties = PropertiesUtil
.read(AbstractBandwidthManagerIntTest.class .read(AbstractBandwidthManagerIntTest.class
.getResourceAsStream("/com.raytheon.uf.edex.datadelivery.bandwidth.properties")); .getResourceAsStream("/com.raytheon.uf.edex.datadelivery.bandwidth.properties"));
@ -112,17 +114,9 @@ public abstract class AbstractBandwidthManagerIntTest {
@Before @Before
public void setUp() { public void setUp() {
PathManagerFactoryTest.initLocalization();
DatabaseUtil.start();
context = new ClassPathXmlApplicationContext(
IntegrationTestBandwidthManager.INTEGRATION_TEST_SPRING_FILES,
BandwidthManagerIntTest.class, EDEXUtil.getSpringContext());
bandwidthDao = (IBandwidthDao) context.getBean("bandwidthDao",
IBandwidthDao.class);
bandwidthManager = (BandwidthManager) context.getBean(
"bandwidthManager",
BandwidthManager.class);
retrievalManager = bandwidthManager.retrievalManager; retrievalManager = bandwidthManager.retrievalManager;
bandwidthDao = IBandwidthDao.class
.cast(context.getBean("bandwidthDao"));
fullBucketSize = retrievalManager.getPlan(Network.OPSNET) fullBucketSize = retrievalManager.getPlan(Network.OPSNET)
.getBucket(TimeUtil.currentTimeMillis()).getBucketSize(); .getBucket(TimeUtil.currentTimeMillis()).getBucketSize();
@ -132,6 +126,7 @@ public abstract class AbstractBandwidthManagerIntTest {
@After @After
public void tearDown() { public void tearDown() {
PathManagerFactoryTest.initLocalization();
try { try {
bandwidthManager.shutdown(); bandwidthManager.shutdown();
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
@ -139,7 +134,6 @@ public abstract class AbstractBandwidthManagerIntTest {
// event bus handler // event bus handler
iae.printStackTrace(); iae.printStackTrace();
} }
DatabaseUtil.shutdown();
} }
/** /**

View file

@ -42,6 +42,11 @@ import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.raytheon.uf.common.datadelivery.registry.DataDeliveryRegistryObjectTypes; import com.raytheon.uf.common.datadelivery.registry.DataDeliveryRegistryObjectTypes;
import com.raytheon.uf.common.datadelivery.registry.GriddedDataSetMetaData; import com.raytheon.uf.common.datadelivery.registry.GriddedDataSetMetaData;
@ -61,7 +66,9 @@ import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.time.util.ImmutableDate; import com.raytheon.uf.common.time.util.ImmutableDate;
import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.common.time.util.TimeUtilTest; import com.raytheon.uf.common.time.util.TimeUtilTest;
import com.raytheon.uf.common.util.SpringFiles;
import com.raytheon.uf.common.util.TestUtil; import com.raytheon.uf.common.util.TestUtil;
import com.raytheon.uf.edex.database.dao.DatabaseUtil;
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation;
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthSubscription; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthSubscription;
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionRetrieval; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionRetrieval;
@ -94,6 +101,13 @@ import com.raytheon.uf.edex.datadelivery.retrieval.RetrievalManagerNotifyEvent;
* @author djohnson * @author djohnson
* @version 1.0 * @version 1.0
*/ */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { DatabaseUtil.UNIT_TEST_DB_BEANS_XML,
SpringFiles.RETRIEVAL_DATADELIVERY_DAOS_XML,
SpringFiles.BANDWIDTH_DATADELIVERY_DAOS_XML,
SpringFiles.BANDWIDTH_DATADELIVERY_INTEGRATION_TEST_XML,
SpringFiles.BANDWIDTH_DATADELIVERY_XML })
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
public class BandwidthManagerIntTest extends AbstractBandwidthManagerIntTest { public class BandwidthManagerIntTest extends AbstractBandwidthManagerIntTest {
@Test @Test

View file

@ -37,6 +37,11 @@ import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.raytheon.uf.common.datadelivery.bandwidth.BandwidthService; import com.raytheon.uf.common.datadelivery.bandwidth.BandwidthService;
import com.raytheon.uf.common.datadelivery.bandwidth.IBandwidthRequest; import com.raytheon.uf.common.datadelivery.bandwidth.IBandwidthRequest;
@ -50,6 +55,8 @@ import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.registry.Subscription.SubscriptionPriority; import com.raytheon.uf.common.datadelivery.registry.Subscription.SubscriptionPriority;
import com.raytheon.uf.common.serialization.SerializationUtil; import com.raytheon.uf.common.serialization.SerializationUtil;
import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.common.util.SpringFiles;
import com.raytheon.uf.edex.database.dao.DatabaseUtil;
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation;
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionRetrieval; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionRetrieval;
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.BandwidthMap; import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.BandwidthMap;
@ -74,7 +81,13 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
* @author djohnson * @author djohnson
* @version 1.0 * @version 1.0
*/ */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { DatabaseUtil.UNIT_TEST_DB_BEANS_XML,
SpringFiles.RETRIEVAL_DATADELIVERY_DAOS_XML,
SpringFiles.BANDWIDTH_DATADELIVERY_DAOS_XML,
SpringFiles.BANDWIDTH_DATADELIVERY_INTEGRATION_TEST_XML,
SpringFiles.BANDWIDTH_DATADELIVERY_XML })
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
public class BandwidthServiceIntTest extends AbstractBandwidthManagerIntTest { public class BandwidthServiceIntTest extends AbstractBandwidthManagerIntTest {
private static final int ONE_HUNDRED = 100; private static final int ONE_HUNDRED = 100;

View file

@ -40,30 +40,7 @@
<property name="sessionFactory" ref="metadataSessionFactory" /> <property name="sessionFactory" ref="metadataSessionFactory" />
</bean> </bean>
<bean id="bandwidthAllocationDao" <!-- Register the application context with EDEXUtil -->
class="com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.BandwidthAllocationDao"> <bean class="com.raytheon.uf.edex.core.EDEXUtil" />
<property name="sessionFactory" ref="metadataSessionFactory" />
</bean>
<bean id="bandwidthSubscriptionDao"
class="com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.BandwidthSubscriptionDao">
<property name="sessionFactory" ref="metadataSessionFactory" />
</bean>
<bean id="hibernateBandwidthDao"
class="com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.HibernateBandwidthDao">
<property name="sessionFactory" ref="metadataSessionFactory" />
<property name="bandwidthAllocationDao" ref="bandwidthAllocationDao" />
<property name="bandwidthSubscriptionDao" ref="bandwidthSubscriptionDao" />
</bean>
<bean id="retrievalDao" class="com.raytheon.uf.edex.datadelivery.retrieval.db.RetrievalDao">
<property name="sessionFactory" ref="metadataSessionFactory" />
</bean>
<bean id="mockService" class="com.raytheon.uf.edex.database.dao.MockService">
<property name="sessionFactory" ref="metadataSessionFactory" />
<property name="bandwidthService" ref="hibernateBandwidthDao" />
</bean>
</beans> </beans>

View file

@ -0,0 +1,56 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.util;
import org.junit.Ignore;
/**
* Utility class for Spring integration.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 12, 2013 1543 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@Ignore
public class SpringFiles {
/**
* Disabled constructor.
*/
private SpringFiles() {
}
public static final String RETRIEVAL_DATADELIVERY_DAOS_XML = "/spring/retrieval-datadelivery-daos.xml";
public static final String BANDWIDTH_DATADELIVERY_DAOS_XML = "/spring/bandwidth-datadelivery-daos.xml";
public static final String BANDWIDTH_DATADELIVERY_INTEGRATION_TEST_XML = "/bandwidth/bandwidth-datadelivery-integrationtest-impl.xml";
public static final String BANDWIDTH_DATADELIVERY_XML = "/spring/bandwidth-datadelivery.xml";
}

View file

@ -48,7 +48,7 @@ public final class DatabaseUtil {
private static final IUFStatusHandler statusHandler = UFStatus private static final IUFStatusHandler statusHandler = UFStatus
.getHandler(DatabaseUtil.class); .getHandler(DatabaseUtil.class);
private static final String UNIT_TEST_DB_BEANS_XML = "/unit-test-db-beans.xml"; public static final String UNIT_TEST_DB_BEANS_XML = "/unit-test-db-beans.xml";
private static ApplicationContext originalApplicationContext; private static ApplicationContext originalApplicationContext;

View file

@ -24,11 +24,13 @@ import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.raytheon.uf.edex.core.EDEXUtil; import com.raytheon.uf.common.util.SpringFiles;
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthSubscription; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthSubscription;
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionDaoFixture; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionDaoFixture;
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionRetrieval; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionRetrieval;
@ -51,6 +53,11 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.HibernateBandwidthD
* @author djohnson * @author djohnson
* @version 1.0 * @version 1.0
*/ */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { DatabaseUtil.UNIT_TEST_DB_BEANS_XML,
SpringFiles.BANDWIDTH_DATADELIVERY_DAOS_XML,
SpringFiles.RETRIEVAL_DATADELIVERY_DAOS_XML,
"sessionManagedServiceTest.xml" })
public class SessionManagedServiceTest { public class SessionManagedServiceTest {
private final BandwidthSubscription subscription = SubscriptionDaoFixture.INSTANCE private final BandwidthSubscription subscription = SubscriptionDaoFixture.INSTANCE
@ -62,24 +69,12 @@ public class SessionManagedServiceTest {
subscriptionRetrieval.setBandwidthSubscription(subscription); subscriptionRetrieval.setBandwidthSubscription(subscription);
} }
@Autowired
private HibernateBandwidthDao bandwidthService; private HibernateBandwidthDao bandwidthService;
@Autowired
private MockService service; private MockService service;
@Before
public void setUp() {
DatabaseUtil.start();
service = (MockService) EDEXUtil.getESBComponent("mockService");
bandwidthService = (HibernateBandwidthDao) EDEXUtil
.getESBComponent("hibernateBandwidthDao");
}
@After
public void tearDown() {
DatabaseUtil.shutdown();
}
@Test @Test
public void exceptionThrownInDaoWillRollbackTransaction() { public void exceptionThrownInDaoWillRollbackTransaction() {
try { try {

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="mockService" class="com.raytheon.uf.edex.database.dao.MockService">
<property name="sessionFactory" ref="metadataSessionFactory" />
<property name="bandwidthService" ref="hibernateBandwidthDao" />
</bean>
</beans>

View file

@ -19,10 +19,14 @@
**/ **/
package com.raytheon.uf.edex.datadelivery.bandwidth; package com.raytheon.uf.edex.datadelivery.bandwidth;
import org.junit.After; import org.junit.runner.RunWith;
import org.junit.Before; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.raytheon.uf.edex.core.EDEXUtil; import com.raytheon.uf.common.util.SpringFiles;
import com.raytheon.uf.edex.database.dao.DatabaseUtil; import com.raytheon.uf.edex.database.dao.DatabaseUtil;
import com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.HibernateBandwidthDao; import com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.HibernateBandwidthDao;
@ -43,32 +47,23 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.HibernateBandwidthD
* @author djohnson * @author djohnson
* @version 1.0 * @version 1.0
*/ */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { DatabaseUtil.UNIT_TEST_DB_BEANS_XML,
SpringFiles.BANDWIDTH_DATADELIVERY_DAOS_XML,
SpringFiles.RETRIEVAL_DATADELIVERY_DAOS_XML })
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
public class HibernateBandwidthDaoTest extends public class HibernateBandwidthDaoTest extends
AbstractBandwidthDaoTest<HibernateBandwidthDao> { AbstractBandwidthDaoTest<HibernateBandwidthDao> {
@Override @Autowired
@Before private HibernateBandwidthDao dao;
public void setUp() {
DatabaseUtil.start();
// The database must be started before constructing the DAO for
// Hibernate
super.setUp();
}
@After
public void tearDown() {
DatabaseUtil.shutdown();
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
protected HibernateBandwidthDao getDao() { protected HibernateBandwidthDao getDao() {
return (HibernateBandwidthDao) EDEXUtil return dao;
.getESBComponent("hibernateBandwidthDao");
} }
} }

View file

@ -29,9 +29,12 @@ import static org.mockito.Mockito.when;
import java.util.List; import java.util.List;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.raytheon.uf.common.datadelivery.registry.Network; import com.raytheon.uf.common.datadelivery.registry.Network;
import com.raytheon.uf.common.datadelivery.registry.OpenDapGriddedDataSetMetaDataFixture; import com.raytheon.uf.common.datadelivery.registry.OpenDapGriddedDataSetMetaDataFixture;
@ -43,6 +46,7 @@ import com.raytheon.uf.common.localization.PathManagerFactoryTest;
import com.raytheon.uf.common.registry.handler.RegistryHandlerException; import com.raytheon.uf.common.registry.handler.RegistryHandlerException;
import com.raytheon.uf.common.registry.handler.RegistryObjectHandlersUtil; import com.raytheon.uf.common.registry.handler.RegistryObjectHandlersUtil;
import com.raytheon.uf.common.serialization.SerializationException; import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.util.SpringFiles;
import com.raytheon.uf.edex.core.EdexException; import com.raytheon.uf.edex.core.EdexException;
import com.raytheon.uf.edex.database.DataAccessLayerException; import com.raytheon.uf.edex.database.DataAccessLayerException;
import com.raytheon.uf.edex.database.dao.DatabaseUtil; import com.raytheon.uf.edex.database.dao.DatabaseUtil;
@ -68,11 +72,17 @@ import com.raytheon.uf.edex.datadelivery.retrieval.db.RetrievalRequestRecord.Sta
* @author djohnson * @author djohnson
* @version 1.0 * @version 1.0
*/ */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { DatabaseUtil.UNIT_TEST_DB_BEANS_XML,
SpringFiles.BANDWIDTH_DATADELIVERY_DAOS_XML,
SpringFiles.RETRIEVAL_DATADELIVERY_DAOS_XML })
public class SubscriptionRetrievalAgentTest { public class SubscriptionRetrievalAgentTest {
@Autowired
private RetrievalDao retrievalDao;
@Before @Before
public void setUp() throws RegistryHandlerException { public void setUp() throws RegistryHandlerException {
DatabaseUtil.start();
PathManagerFactoryTest.initLocalization(); PathManagerFactoryTest.initLocalization();
RegistryObjectHandlersUtil.initMocks(); RegistryObjectHandlersUtil.initMocks();
when(DataDeliveryHandlers.getProviderHandler().getByName(anyString())) when(DataDeliveryHandlers.getProviderHandler().getByName(anyString()))
@ -83,11 +93,6 @@ public class SubscriptionRetrievalAgentTest {
OpenDapGriddedDataSetMetaDataFixture.INSTANCE.get()); OpenDapGriddedDataSetMetaDataFixture.INSTANCE.get());
} }
@After
public void tearDown() {
DatabaseUtil.shutdown();
}
@Test @Test
public void opsnetRoutedSubscriptionsCreateRetrievalsInPendingState() public void opsnetRoutedSubscriptionsCreateRetrievalsInPendingState()
throws EdexException, SerializationException { throws EdexException, SerializationException {
@ -120,8 +125,7 @@ public class SubscriptionRetrievalAgentTest {
}; };
agent.processAllocation(subscriptionRetrieval); agent.processAllocation(subscriptionRetrieval);
RetrievalDao dao = RetrievalDao.getInstance(); final List<RetrievalRequestRecord> requests = retrievalDao
final List<RetrievalRequestRecord> requests = dao
.getRequests(subscription.getName()); .getRequests(subscription.getName());
assertThat(requests, assertThat(requests,
is(not(emptyCollectionOf(RetrievalRequestRecord.class)))); is(not(emptyCollectionOf(RetrievalRequestRecord.class))));