Issue #2038 Change registry code to use GenericRegistry, use Spring 3 embedded DB feature in tests
Change-Id: Ie9e0a4fa4fb457f1d85326c6c2ddcfa16cdc5b63 Former-commit-id:bc830e67f0
[formerly 121d9a02acfe528c524788a062c2d2034f80afe5] Former-commit-id:d47da65262
This commit is contained in:
parent
f55fa69ea2
commit
d81592b575
26 changed files with 194 additions and 227 deletions
|
@ -75,6 +75,7 @@ import com.raytheon.uf.common.util.ReflectionUtil;
|
|||
* Sep 07, 2012 1102 djohnson Check in hanging around encoding strategy code that will prove useful later.
|
||||
* Oct 05, 2012 1195 djohnson Don't persist slots for null values.
|
||||
* 4/9/2013 1802 bphillip Pulled constants out into existing constants package that was moved into common
|
||||
* Jun 03, 2013 2038 djohnson Allow setting the same encoder strategy.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -172,7 +173,7 @@ public final class RegistryUtil {
|
|||
* has been set
|
||||
*/
|
||||
public static void setEncoderStrategy(IRegistryEncoder encoder) {
|
||||
if (ENCODER_STRATEGY != null) {
|
||||
if (ENCODER_STRATEGY != null && !ENCODER_STRATEGY.equals(encoder)) {
|
||||
throw new IllegalStateException(
|
||||
"The encoder strategy is already set, you cannot change it on a running system!");
|
||||
}
|
||||
|
|
|
@ -25,6 +25,9 @@ import oasis.names.tc.ebxml.regrep.xsd.rim.v4.RegistryObjectType;
|
|||
import oasis.names.tc.ebxml.regrep.xsd.rim.v4.SlotType;
|
||||
import oasis.names.tc.ebxml.regrep.xsd.rim.v4.ValueType;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
|
||||
import com.raytheon.uf.common.serialization.SerializationException;
|
||||
|
||||
/**
|
||||
|
@ -39,7 +42,8 @@ import com.raytheon.uf.common.serialization.SerializationException;
|
|||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Sep 7, 2012 1102 djohnson Initial creation
|
||||
* Sep 07, 2012 1102 djohnson Initial creation
|
||||
* Jun 03, 2013 2038 djohnson Add equals/hashcode.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -54,7 +58,19 @@ abstract class ContentSlotBasedEncoder<SLOT_VALUE_TYPE extends ValueType, CONTEN
|
|||
* the object.
|
||||
*/
|
||||
private static final String CONTENT_SLOT = "content";
|
||||
|
||||
/**
|
||||
* The type of encoder it is.
|
||||
*/
|
||||
private final RegistryEncoders.Type type;
|
||||
|
||||
/**
|
||||
* Constructor. Intentionally package-private.
|
||||
*/
|
||||
ContentSlotBasedEncoder(RegistryEncoders.Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -93,6 +109,32 @@ abstract class ContentSlotBasedEncoder<SLOT_VALUE_TYPE extends ValueType, CONTEN
|
|||
return slot;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof ContentSlotBasedEncoder) {
|
||||
ContentSlotBasedEncoder<?, ?> other = (ContentSlotBasedEncoder<?, ?>) obj;
|
||||
|
||||
EqualsBuilder builder = new EqualsBuilder();
|
||||
builder.append(this.type, other.type);
|
||||
return builder.isEquals();
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
HashCodeBuilder builder = new HashCodeBuilder();
|
||||
builder.append(type);
|
||||
|
||||
return builder.toHashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the slot value type and place the encoded object
|
||||
* as the value.
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
**/
|
||||
package com.raytheon.uf.common.registry.ebxml.encoder;
|
||||
|
||||
import static com.raytheon.uf.common.registry.ebxml.encoder.RegistryEncoders.Type.DYNAMIC_SERIALIZE;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import com.raytheon.uf.common.serialization.SerializationException;
|
||||
|
@ -36,7 +38,8 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
|
|||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Sep 7, 2012 1102 djohnson Initial creation
|
||||
* Sep 07, 2012 1102 djohnson Initial creation
|
||||
* Jun 03, 2013 2038 djohnson Add equals/hashcode.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -45,13 +48,20 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
|
|||
*/
|
||||
class DynamicSerializeEncoder extends StringBasedEncoder {
|
||||
|
||||
/**
|
||||
* @param type
|
||||
*/
|
||||
DynamicSerializeEncoder() {
|
||||
super(DYNAMIC_SERIALIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Object decodeContent(String content) throws SerializationException {
|
||||
return SerializationUtil.transformFromThrift(Base64
|
||||
.decodeBase64(content));
|
||||
return SerializationUtil.transformFromThrift(Object.class,
|
||||
Base64.decodeBase64(content));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
**/
|
||||
package com.raytheon.uf.common.registry.ebxml.encoder;
|
||||
|
||||
import static com.raytheon.uf.common.registry.ebxml.encoder.RegistryEncoders.Type.JAXB;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import com.raytheon.uf.common.serialization.SerializationException;
|
||||
|
@ -34,7 +36,8 @@ import com.raytheon.uf.common.serialization.SerializationUtil;
|
|||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Sep 7, 2012 1102 djohnson Initial creation
|
||||
* Sep 07, 2012 1102 djohnson Initial creation
|
||||
* Jun 03, 2013 2038 djohnson Add equals/hashcode.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -44,13 +47,20 @@ import com.raytheon.uf.common.serialization.SerializationUtil;
|
|||
|
||||
class JaxbEncoder extends StringBasedEncoder {
|
||||
|
||||
/**
|
||||
* @param type
|
||||
*/
|
||||
JaxbEncoder() {
|
||||
super(JAXB);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Object decodeContent(String content) throws SerializationException {
|
||||
try {
|
||||
return SerializationUtil.unmarshalFromXml(content);
|
||||
return SerializationUtil.unmarshalFromXml(Object.class, content);
|
||||
} catch (JAXBException e) {
|
||||
throw new SerializationException("Unable to decode the object!", e);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ package com.raytheon.uf.common.registry.ebxml.encoder;
|
|||
|
||||
import oasis.names.tc.ebxml.regrep.xsd.rim.v4.StringValueType;
|
||||
|
||||
import com.raytheon.uf.common.registry.ebxml.encoder.RegistryEncoders.Type;
|
||||
|
||||
/**
|
||||
* A string-based encoding strategy. Package-private because we want the
|
||||
* encoding strategies to remain implementation details that are separate from
|
||||
|
@ -32,7 +34,8 @@ import oasis.names.tc.ebxml.regrep.xsd.rim.v4.StringValueType;
|
|||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Sep 7, 2012 1102 djohnson Initial creation
|
||||
* Sep 07, 2012 1102 djohnson Initial creation
|
||||
* Jun 03, 2013 2038 djohnson Add equals/hashcode.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -42,6 +45,16 @@ import oasis.names.tc.ebxml.regrep.xsd.rim.v4.StringValueType;
|
|||
abstract class StringBasedEncoder extends
|
||||
ContentSlotBasedEncoder<StringValueType, String> {
|
||||
|
||||
/**
|
||||
* Constructor. Intentionally package-private.
|
||||
*
|
||||
* @param type
|
||||
* the type
|
||||
*/
|
||||
StringBasedEncoder(Type type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
|
@ -19,11 +19,13 @@
|
|||
**/
|
||||
package com.raytheon.uf.common.registry.handler;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.raytheon.uf.common.registry.annotations.RegistryObject;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
import com.raytheon.uf.common.util.registry.GenericRegistry;
|
||||
import com.raytheon.uf.common.util.registry.RegistryException;
|
||||
|
||||
/**
|
||||
* Register or find {@link IRegistryObjectHandler} implementations.
|
||||
|
@ -36,6 +38,7 @@ import com.raytheon.uf.common.registry.annotations.RegistryObject;
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* Sep 17, 2012 1169 djohnson Initial creation
|
||||
* Oct 16, 2012 0726 djohnson Add the ability to use a pojo instance which delegates to static methods.
|
||||
* Jun 03, 2013 2038 djohnson Change to use a {@link GenericRegistry}.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -45,7 +48,11 @@ import com.raytheon.uf.common.registry.annotations.RegistryObject;
|
|||
|
||||
public final class RegistryObjectHandlers {
|
||||
|
||||
private static final ConcurrentMap<String, IRegistryObjectHandler<?>> handlers = new ConcurrentHashMap<String, IRegistryObjectHandler<?>>();
|
||||
private static IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(RegistryObjectHandlers.class);
|
||||
|
||||
private static final GenericRegistry<String, IRegistryObjectHandler<?>> handlers = new GenericRegistry<String, IRegistryObjectHandler<?>>() {
|
||||
};
|
||||
|
||||
// Used to simplify the Spring files
|
||||
private static final RegistryObjectHandlers INSTANCE = new RegistryObjectHandlers();
|
||||
|
@ -87,8 +94,10 @@ public final class RegistryObjectHandlers {
|
|||
* the registry object handler interface
|
||||
* @param handler
|
||||
* the handler
|
||||
* @throws IllegalArgumentException
|
||||
* if the handlerInterface parameter is not an interface
|
||||
* @throws IllegalStateException
|
||||
* if a second handler is registered for any interface
|
||||
* on an error registering the handler
|
||||
*/
|
||||
public static <T extends IRegistryObjectHandler<?>> void register(
|
||||
Class<T> handlerInterface, T handler) throws IllegalStateException {
|
||||
|
@ -98,14 +107,16 @@ public final class RegistryObjectHandlers {
|
|||
"Implementations must be registered under their interfaces!");
|
||||
}
|
||||
|
||||
IRegistryObjectHandler<?> previous = handlers.putIfAbsent(
|
||||
handlerInterface.getName(), handler);
|
||||
if (previous != null) {
|
||||
throw new IllegalStateException(
|
||||
String.format(
|
||||
"Attempt to associate handler [%s] with handler interface [%s] fails, because [%s] is already associated with it!",
|
||||
handler.getClass().getName(), handlerInterface
|
||||
.getName(), previous.getClass().getName()));
|
||||
if (statusHandler.isPriorityEnabled(Priority.DEBUG)) {
|
||||
statusHandler.handle(Priority.DEBUG, String.format(
|
||||
"Associating handler [%s] with handler interface [%s]",
|
||||
handler.getClass().getName(), handlerInterface.getName()));
|
||||
}
|
||||
|
||||
try {
|
||||
handlers.register(handlerInterface.getName(), handler);
|
||||
} catch (RegistryException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,7 +125,7 @@ public final class RegistryObjectHandlers {
|
|||
*/
|
||||
@VisibleForTesting
|
||||
static void clear() {
|
||||
handlers.clear();
|
||||
handlers.getRegisteredObjects().clear();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -123,9 +134,10 @@ public final class RegistryObjectHandlers {
|
|||
* the handler interface
|
||||
* @return
|
||||
* the implementation
|
||||
* @throws IllegalArgumentException if no handler is registered for the specific interface
|
||||
*/
|
||||
public static <T> T get(Class<T> handlerInterface) {
|
||||
Object obj = handlers.get(handlerInterface.getName());
|
||||
Object obj = handlers.getRegisteredObject(handlerInterface.getName());
|
||||
|
||||
if (obj == null) {
|
||||
throw new IllegalArgumentException(
|
||||
|
|
|
@ -45,13 +45,14 @@ import org.apache.commons.beanutils.PropertyUtils;
|
|||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.cfg.AnnotationConfiguration;
|
||||
import org.hibernate.jdbc.Work;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.raytheon.uf.common.localization.LocalizationFile;
|
||||
import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||
import com.raytheon.uf.common.registry.ebxml.RegistryUtil;
|
||||
|
@ -89,9 +90,10 @@ import com.raytheon.uf.edex.registry.ebxml.init.RegistryInitializedListener;
|
|||
*/
|
||||
@Transactional
|
||||
public class DbInit extends com.raytheon.uf.edex.database.init.DbInit implements
|
||||
ApplicationListener {
|
||||
ApplicationListener<ContextRefreshedEvent> {
|
||||
|
||||
private static volatile boolean INITIALIZED = false;
|
||||
@VisibleForTesting
|
||||
static volatile boolean INITIALIZED = false;
|
||||
|
||||
/** The logger */
|
||||
private static final IUFStatusHandler statusHandler = UFStatus
|
||||
|
@ -317,7 +319,7 @@ public class DbInit extends com.raytheon.uf.edex.database.init.DbInit implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||
if (!INITIALIZED) {
|
||||
txTemplate.execute(new TransactionCallbackWithoutResult() {
|
||||
@Override
|
||||
|
|
|
@ -5,6 +5,13 @@ testTypes=unit,integration
|
|||
#testTypes=unit,integration,deploy
|
||||
|
||||
TEST.INCLUSION.PATTERN=**/*Test.java
|
||||
unit.FORK.TESTS=off
|
||||
unit.FORK.MODE=perTest
|
||||
unit.FORK.CLONEVM=false
|
||||
# Fork the integration tests because they don't clean up as well as they should
|
||||
integration.FORK.TESTS=on
|
||||
integration.FORK.MODE=perTest
|
||||
integration.FORK.CLONEVM=false
|
||||
|
||||
# Important directories
|
||||
WORKING.DIR=${basedir}/tmp
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
</target>
|
||||
|
||||
<target name="env-setup" description="Sets up the environment" depends="env-check, env-developer, env-jenkins">
|
||||
<property environment="env" />
|
||||
<property file="${build.properties.file}" />
|
||||
<property file="build.properties" />
|
||||
<property file="${BUILD.EDEX.PROPERTIES}" />
|
||||
|
@ -85,9 +86,13 @@
|
|||
|
||||
<forEachTestType>
|
||||
<var name="testTypeSourceDir" value="${basedir}/@{testType}" />
|
||||
<!-- Test type forking settings -->
|
||||
<propertycopy name="forkTests" from="@{testType}.FORK.TESTS" override="true" />
|
||||
<propertycopy name="forkMode" from="@{testType}.FORK.MODE" override="true" />
|
||||
<propertycopy name="forkCloneVm" from="@{testType}.FORK.CLONEVM" override="true" />
|
||||
|
||||
<junit printsummary="yes" haltonfailure="no" failureproperty="tests.failed">
|
||||
<jvmarg value="-Duser.dir=${testTypeSourceDir}" />
|
||||
<junit printsummary="yes" forkmode="${forkMode}" clonevm="${forkCloneVm}" haltonfailure="no" failureproperty="tests.failed">
|
||||
<jvmarg line="-Duser.dir=${testTypeSourceDir} -XX:PermSize=${env.INITIAL_PERMGEN_SIZE} -XX:MaxPermSize=${env.MAX_PERMGEN_SIZE}" />
|
||||
<classpath>
|
||||
<!-- Any resources for tests -->
|
||||
<pathelement location="${testTypeSourceDir}" />
|
||||
|
@ -101,11 +106,8 @@
|
|||
|
||||
<formatter type="xml" />
|
||||
|
||||
<batchtest fork="no" todir="${TEST.REPORTS.DIR}">
|
||||
<fileset dir="${basedir}/@{testType}">
|
||||
<include name="${TEST.INCLUSION.PATTERN}" />
|
||||
<exclude name="${TEST.EXCLUSION.PATTERN}" />
|
||||
</fileset>
|
||||
<batchtest fork="${forkTests}" todir="${TEST.REPORTS.DIR}">
|
||||
<fileset dir="${basedir}/@{testType}" includes="${TEST.INCLUSION.PATTERN}" excludes="${TEST.EXCLUSION.PATTERN}" />
|
||||
</batchtest>
|
||||
</junit>
|
||||
</forEachTestType>
|
||||
|
|
|
@ -48,7 +48,6 @@ import com.raytheon.uf.common.time.util.TimeUtil;
|
|||
import com.raytheon.uf.common.time.util.TimeUtilTest;
|
||||
import com.raytheon.uf.common.util.PropertiesUtil;
|
||||
import com.raytheon.uf.common.util.SpringFiles;
|
||||
import com.raytheon.uf.edex.database.dao.DatabaseUtil;
|
||||
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.RetrievalPlan;
|
||||
|
@ -78,7 +77,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
|||
* @version 1.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { DatabaseUtil.UNIT_TEST_DB_BEANS_XML,
|
||||
@ContextConfiguration(locations = { SpringFiles.UNIT_TEST_DB_BEANS_XML,
|
||||
SpringFiles.EVENTBUS_COMMON_XML,
|
||||
SpringFiles.RETRIEVAL_DATADELIVERY_DAOS_XML,
|
||||
SpringFiles.BANDWIDTH_DATADELIVERY_DAOS_XML,
|
||||
|
|
|
@ -47,6 +47,8 @@ import oasis.names.tc.ebxml.regrep.xsd.rs.v4.RegistryExceptionType;
|
|||
import oasis.names.tc.ebxml.regrep.xsd.rs.v4.RegistryResponseStatus;
|
||||
import oasis.names.tc.ebxml.regrep.xsd.rs.v4.RegistryResponseType;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -58,7 +60,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import com.google.common.collect.Lists;
|
||||
import com.raytheon.uf.common.registry.ebxml.RegistryUtil;
|
||||
import com.raytheon.uf.common.util.SpringFiles;
|
||||
import com.raytheon.uf.edex.database.dao.DatabaseUtil;
|
||||
import com.raytheon.uf.edex.registry.ebxml.services.query.QueryConstants;
|
||||
import com.raytheon.uf.edex.registry.ebxml.services.query.QueryManagerImpl.RETURN_TYPE;
|
||||
import com.raytheon.uf.edex.registry.ebxml.util.EbxmlObjectUtil;
|
||||
|
@ -90,7 +91,7 @@ import com.raytheon.uf.edex.registry.ebxml.util.EbxmlObjectUtil;
|
|||
SpringFiles.EBXML_WEBSERVICES_XML, SpringFiles.EBXML_XACML_XML,
|
||||
SpringFiles.EBXML_VALIDATOR_PLUGINS_XML,
|
||||
SpringFiles.EBXML_SUBSCRIPTION_XML, SpringFiles.EVENTBUS_COMMON_XML,
|
||||
DatabaseUtil.UNIT_TEST_DB_BEANS_XML,
|
||||
SpringFiles.UNIT_TEST_DB_BEANS_XML,
|
||||
SpringFiles.UNIT_TEST_EBXML_BEANS_XML,
|
||||
SpringFiles.UNIT_TEST_LOCALIZATION_BEANS_XML })
|
||||
@TransactionConfiguration(transactionManager = "metadataTxManager", defaultRollback = true)
|
||||
|
@ -108,6 +109,12 @@ public class AbstractRegistryTest {
|
|||
@Autowired
|
||||
protected QueryManager queryManager;
|
||||
|
||||
@BeforeClass
|
||||
@AfterClass
|
||||
public static void resetDbInitialized() {
|
||||
DbInit.INITIALIZED = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits the registry object to the registry and verifies it was
|
||||
* successfully processed.
|
||||
|
|
1
tests/resources/schema.sql
Normal file
1
tests/resources/schema.sql
Normal file
|
@ -0,0 +1 @@
|
|||
create schema IF NOT EXISTS ebxml;
|
|
@ -1 +0,0 @@
|
|||
unit.test.jdbc.url=jdbc:h2:mem:unit-testing
|
|
@ -1,17 +1,46 @@
|
|||
<?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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean
|
||||
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="location">
|
||||
<value>classpath:/unit-test-db-beans.properties</value>
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/tx
|
||||
http://www.springframework.org/schema/tx/spring-tx.xsd
|
||||
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd">
|
||||
|
||||
<bean id="metadataSessionFactory"
|
||||
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="packagesToScan">
|
||||
<list>
|
||||
<value>com.raytheon.uf.edex.datadelivery.bandwidth.dao</value>
|
||||
<value>com.raytheon.uf.edex.datadelivery.retrieval.db</value>
|
||||
<value>oasis.names.tc.ebxml.regrep.xsd.rim.v4</value>
|
||||
</list>
|
||||
</property>
|
||||
<property name="configLocation">
|
||||
<value>classpath:unit-test-hibernate.cfg.xml</value>
|
||||
</property>
|
||||
<property name="ignoreUnresolvablePlaceholders" value="true" />
|
||||
</bean>
|
||||
|
||||
<import resource="classpath:/unit-test-db-session.xml" />
|
||||
<tx:annotation-driven transaction-manager="metadataTxManager"
|
||||
proxy-target-class="true" />
|
||||
|
||||
<bean id="metadataTxManager"
|
||||
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
|
||||
<property name="sessionFactory" ref="metadataSessionFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="metadataTxTemplate"
|
||||
class="org.springframework.transaction.support.TransactionTemplate">
|
||||
<property name="transactionManager" ref="metadataTxManager" />
|
||||
</bean>
|
||||
|
||||
<!-- Register the application context with EDEXUtil -->
|
||||
<bean class="com.raytheon.uf.edex.core.EDEXUtil" />
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="H2">
|
||||
<jdbc:script location="classpath:schema.sql"/>
|
||||
</jdbc:embedded-database>
|
||||
|
||||
</beans>
|
|
@ -1 +0,0 @@
|
|||
unit.test.jdbc.url=jdbc:h2:mem:unit-testing2
|
|
@ -1,20 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
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.xsd">
|
||||
|
||||
<!-- Used in the case where a second in-memory database needs to be started
|
||||
in the same unit test -->
|
||||
|
||||
<bean
|
||||
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="location">
|
||||
<value>classpath:/unit-test-db-beans2.properties</value>
|
||||
</property>
|
||||
<property name="ignoreUnresolvablePlaceholders" value="true" />
|
||||
</bean>
|
||||
|
||||
<import resource="classpath:/unit-test-db-session.xml" />
|
||||
|
||||
</beans>
|
|
@ -1,50 +0,0 @@
|
|||
<?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: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="metadataSessionFactory"
|
||||
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="packagesToScan">
|
||||
<list>
|
||||
<value>com.raytheon.uf.edex.datadelivery.bandwidth.dao</value>
|
||||
<value>com.raytheon.uf.edex.datadelivery.retrieval.db</value>
|
||||
<value>oasis.names.tc.ebxml.regrep.xsd.rim.v4</value>
|
||||
</list>
|
||||
</property>
|
||||
<property name="configLocation">
|
||||
<value>classpath:unit-test-hibernate.cfg.xml</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<tx:annotation-driven transaction-manager="metadataTxManager"
|
||||
proxy-target-class="true" />
|
||||
|
||||
<bean id="metadataTxManager"
|
||||
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
|
||||
<property name="sessionFactory" ref="metadataSessionFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="metadataTxTemplate"
|
||||
class="org.springframework.transaction.support.TransactionTemplate">
|
||||
<property name="transactionManager" ref="metadataTxManager" />
|
||||
</bean>
|
||||
|
||||
<!-- Register the application context with EDEXUtil -->
|
||||
<bean class="com.raytheon.uf.edex.core.EDEXUtil" />
|
||||
|
||||
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
|
||||
destroy-method="close">
|
||||
<property name="driverClassName" value="org.h2.Driver" />
|
||||
<property name="url"
|
||||
value="${unit.test.jdbc.url}:;INIT=create schema IF NOT EXISTS ebxml" />
|
||||
<property name="username" value="sa" />
|
||||
<property name="password" value="" />
|
||||
<property name="defaultAutoCommit" value="false" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -10,5 +10,5 @@ then
|
|||
export MAX_PERMGEN_SIZE="192m"
|
||||
fi
|
||||
|
||||
export ANT_OPTS="-XX:PermSize=${INITIAL_PERMGEN_SIZE} -XX:MaxPermSize=${MAX_PERMGEN_SIZE}"
|
||||
export ANT_OPTS="-XX:PermSize=${INITIAL_PERMGEN_SIZE} -XX:MaxPermSize=${MAX_PERMGEN_SIZE} $*"
|
||||
ant
|
||||
|
|
|
@ -67,8 +67,8 @@ public class RegistryObjectHandlersTest {
|
|||
RegistryObjectHandlers.get(IMockRegistryObjectHandler.class));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testAssociatingTwoHandlersWithSameInterfaceThrowsException() {
|
||||
@Test
|
||||
public void testAssociatingTwoHandlersWithSameInterfaceDoesNotThrowException() {
|
||||
RegistryObjectHandlers.register(IMockRegistryObjectHandler.class,
|
||||
new MockRegistryObjectHandler());
|
||||
RegistryObjectHandlers.register(IMockRegistryObjectHandler.class,
|
||||
|
|
|
@ -93,6 +93,8 @@ public class SpringFiles {
|
|||
|
||||
public static final String EVENTBUS_COMMON_XML = "/spring/eventbus-common.xml";
|
||||
|
||||
public static final String UNIT_TEST_DB_BEANS_XML = "/unit-test-db-beans.xml";
|
||||
|
||||
public static final String UNIT_TEST_LOCALIZATION_BEANS_XML = "/unit-test-localization-beans.xml";
|
||||
|
||||
public static final String UNIT_TEST_EBXML_BEANS_XML = "/ebxml/unit-test-ebxml-beans.xml";
|
||||
|
|
|
@ -1,98 +0,0 @@
|
|||
/**
|
||||
* 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.edex.database.dao;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.edex.core.EDEXUtil;
|
||||
|
||||
/**
|
||||
* Utility class for test classes to start and stop an in-memory database.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 10, 2012 0726 djohnson Initial creation
|
||||
* Feb 27, 2013 1644 djohnson Add constant for second in-memory database Spring file.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author djohnson
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public final class DatabaseUtil {
|
||||
|
||||
private static final IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(DatabaseUtil.class);
|
||||
|
||||
public static final String UNIT_TEST_DB_BEANS_XML = "/unit-test-db-beans.xml";
|
||||
|
||||
public static final String UNIT_TEST_DB_BEANS2_XML = "/unit-test-db-beans2.xml";
|
||||
|
||||
private static ApplicationContext originalApplicationContext;
|
||||
|
||||
private static ClassPathXmlApplicationContext applicationContext;
|
||||
|
||||
/**
|
||||
* No construction.
|
||||
*/
|
||||
private DatabaseUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the in-memory database for unit testing code that utilizes the
|
||||
* database. This should be called in the @Before section of a JUnit test,
|
||||
* and {@link #shutdown()} should be called in the @After section.
|
||||
*/
|
||||
public static void start() {
|
||||
statusHandler.debug("Starting the in-memory database.");
|
||||
|
||||
originalApplicationContext = EDEXUtil.getSpringContext();
|
||||
applicationContext = new ClassPathXmlApplicationContext(
|
||||
UNIT_TEST_DB_BEANS_XML, DatabaseUtil.class);
|
||||
new EDEXUtil().setApplicationContext(applicationContext);
|
||||
|
||||
statusHandler.debug("Started.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown the database. Should be called in the @After section of a JUnit
|
||||
* test.
|
||||
*/
|
||||
public static void shutdown() {
|
||||
statusHandler.debug("Stopping the in-memory database.");
|
||||
|
||||
if (applicationContext != null) {
|
||||
applicationContext.close();
|
||||
applicationContext = null;
|
||||
}
|
||||
new EDEXUtil().setApplicationContext(originalApplicationContext);
|
||||
originalApplicationContext = null;
|
||||
|
||||
statusHandler.debug("Stopped.");
|
||||
}
|
||||
}
|
|
@ -54,7 +54,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionRetrievalFixt
|
|||
* @version 1.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { DatabaseUtil.UNIT_TEST_DB_BEANS_XML,
|
||||
@ContextConfiguration(locations = { SpringFiles.UNIT_TEST_DB_BEANS_XML,
|
||||
SpringFiles.BANDWIDTH_DATADELIVERY_DAOS_XML,
|
||||
SpringFiles.RETRIEVAL_DATADELIVERY_DAOS_XML,
|
||||
"sessionManagedServiceTest.xml" })
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.springframework.test.context.ContextConfiguration;
|
|||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.raytheon.uf.common.util.SpringFiles;
|
||||
import com.raytheon.uf.edex.database.dao.DatabaseUtil;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.HibernateBandwidthDao;
|
||||
|
||||
|
@ -49,7 +48,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.HibernateBandwidthD
|
|||
* @version 1.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { DatabaseUtil.UNIT_TEST_DB_BEANS_XML,
|
||||
@ContextConfiguration(locations = { SpringFiles.UNIT_TEST_DB_BEANS_XML,
|
||||
SpringFiles.BANDWIDTH_DATADELIVERY_DAOS_XML,
|
||||
SpringFiles.RETRIEVAL_DATADELIVERY_DAOS_XML })
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
|
|
|
@ -50,7 +50,6 @@ 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.database.DataAccessLayerException;
|
||||
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.SubscriptionRetrieval;
|
||||
import com.raytheon.uf.edex.datadelivery.retrieval.db.IRetrievalDao;
|
||||
|
@ -74,7 +73,7 @@ import com.raytheon.uf.edex.datadelivery.retrieval.db.RetrievalRequestRecord.Sta
|
|||
* @version 1.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { DatabaseUtil.UNIT_TEST_DB_BEANS_XML,
|
||||
@ContextConfiguration(locations = { SpringFiles.UNIT_TEST_DB_BEANS_XML,
|
||||
SpringFiles.BANDWIDTH_DATADELIVERY_DAOS_XML,
|
||||
SpringFiles.RETRIEVAL_DATADELIVERY_DAOS_XML })
|
||||
public class SubscriptionRetrievalAgentTest {
|
||||
|
|
|
@ -62,7 +62,6 @@ import com.raytheon.uf.common.util.SpringFiles;
|
|||
import com.raytheon.uf.common.util.TestUtil;
|
||||
import com.raytheon.uf.common.util.file.FilenameFilters;
|
||||
import com.raytheon.uf.edex.database.DataAccessLayerException;
|
||||
import com.raytheon.uf.edex.database.dao.DatabaseUtil;
|
||||
import com.raytheon.uf.edex.datadelivery.retrieval.ServiceTypeFactory;
|
||||
import com.raytheon.uf.edex.datadelivery.retrieval.adapters.RetrievalAdapter;
|
||||
import com.raytheon.uf.edex.datadelivery.retrieval.db.IRetrievalDao;
|
||||
|
@ -93,7 +92,7 @@ import com.raytheon.uf.edex.datadelivery.retrieval.interfaces.IRetrievalResponse
|
|||
* @version 1.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { DatabaseUtil.UNIT_TEST_DB_BEANS_XML,
|
||||
@ContextConfiguration(locations = { SpringFiles.UNIT_TEST_DB_BEANS_XML,
|
||||
SpringFiles.RETRIEVAL_DATADELIVERY_DAOS_XML })
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class RetrievalTaskTest {
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
**/
|
||||
package com.raytheon.uf.edex.registry.ebxml.dao;
|
||||
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Extends {@link DbInit} to load the database for HSQL.
|
||||
|
@ -42,6 +44,7 @@ public class HsqlEbxmlDbInit extends DbInit {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public void initDb() throws Exception {
|
||||
populateDB();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue