mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Fixed BaseSpringTest to handle custom application contexts from derived tests
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5730 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -27,6 +27,7 @@ package org.alfresco.util;
|
|||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
import org.springframework.orm.hibernate3.SessionFactoryUtils;
|
import org.springframework.orm.hibernate3.SessionFactoryUtils;
|
||||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||||
|
|
||||||
@@ -44,12 +45,14 @@ public abstract class BaseSpringTest extends AbstractTransactionalDataSourceSpri
|
|||||||
{
|
{
|
||||||
/** protected so that it gets populated if autowiring is done by variable name **/
|
/** protected so that it gets populated if autowiring is done by variable name **/
|
||||||
protected SessionFactory sessionFactory;
|
protected SessionFactory sessionFactory;
|
||||||
|
private boolean defaultContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public BaseSpringTest()
|
public BaseSpringTest()
|
||||||
{
|
{
|
||||||
|
defaultContext = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,6 +93,8 @@ public abstract class BaseSpringTest extends AbstractTransactionalDataSourceSpri
|
|||||||
@Override
|
@Override
|
||||||
protected String[] getConfigLocations()
|
protected String[] getConfigLocations()
|
||||||
{
|
{
|
||||||
|
// The derived class is using the default context
|
||||||
|
defaultContext = true;
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logger.debug("Getting config locations");
|
logger.debug("Getting config locations");
|
||||||
@@ -103,6 +108,14 @@ public abstract class BaseSpringTest extends AbstractTransactionalDataSourceSpri
|
|||||||
@Override
|
@Override
|
||||||
protected ConfigurableApplicationContext loadContext(Object key) throws Exception
|
protected ConfigurableApplicationContext loadContext(Object key) throws Exception
|
||||||
{
|
{
|
||||||
return (ConfigurableApplicationContext) ApplicationContextHelper.getApplicationContext();
|
if (defaultContext)
|
||||||
|
{
|
||||||
|
return (ConfigurableApplicationContext) ApplicationContextHelper.getApplicationContext();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
String[] configLocations = (String[]) key;
|
||||||
|
return new ClassPathXmlApplicationContext(configLocations);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user