You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by bilobag <bi...@hotmail.com> on 2007/07/19 17:42:03 UTC

Junit testing with Jackrabbit using AbstractDependencyInjectionSpringContextTests

I'm am in the process of setting up Junit testing for my Jackrabbit based CMS
web application using JSF and Spring. I finally got my test to see the
config files I need, but now I get the following error message. It seems
like the JcrTemplate isn't opening up a new JCR session so that I can access
the repository. Everything works fine when the application is
deployed...just not for my Junit test. Since I don't get any errors about
being able to initialize any of my Dependency Injected beans...i would
assume everything is initialized properly. Does anyone know what i'm
missing? Do I need to set something in the
AbstractDependencyInjectionSpringContextTests class to initialize the
repository?

javax.jcr.RepositoryException: this session has been closed
at org.apache.jackrabbit.core.SessionImpl.sanityCheck (SessionImpl.java:353)
at org.apache.jackrabbit.core.ItemImpl.sanityCheck(It emImpl.java:153)
at org.apache.jackrabbit.core.NodeImpl.getUUID(NodeIm pl.java:2803)
at org.bmpcoe.cwe5.service.impl.NodeServiceImpl.getNo
deByPath(NodeServiceImpl.java:165)
at org.bmpcoe.cwe5.service.NodeServiceTests.testGetAl
lFiles(NodeServiceTests.java:41)
at org.springframework.test.ConditionalTestCase.runBa
re(ConditionalTestCase.java:69)
at org.eclipse.ant.internal.ui.antsupport.EclipseDefa
ultExecutor.executeTargets(EclipseDefaultExecutor. java:32)
at org.eclipse.ant.internal.ui.antsupport.InternalAnt
Runner.run(InternalAntRunner.java:423)
at org.eclipse.ant.internal.ui.antsupport.InternalAnt
Runner.main(InternalAntRunner.java:137)
-- 
View this message in context: http://www.nabble.com/Junit-testing-with-Jackrabbit-using-AbstractDependencyInjectionSpringContextTests-tf4111862.html#a11691587
Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.


Re: Junit testing with Jackrabbit using AbstractDependencyInjectionSpringContextTests

Posted by bilobag <bi...@hotmail.com>.
Thanks a lot for the help Christoph!  Your code worked.  This will really get
my unit tests going.  Thanks again.



Christoph Kiehl-3 wrote:
> 
> bilobag wrote:
> 
>> Ok, i think my issue is that I have the
>> org.springmodules.jcr.support.OpenSessionInViewFilter configured in my
>> web.xml which is supposed to keep my repository session open.  My dao
>> mainly
>> just uses the jcrTemplate methods to access the repository.  I believe
>> the
>> template opens and closes the session.  Does anyone know of a way to keep
>> it
>> open during my entire test case?   
> 
> I just copied some code from OpenSessionInViewFilter to put together a
> quick and 
> dirty solution. I'm using transactions and therefore have a threadbound
> session 
> available anyway. There might be a cleaner solution but this one should
> work for 
> now.
> 
> Cheers,
> Christoph
> 
> ps: Just post such questions to the user list next time. Most developers
> read 
> both lists anyway.
> 
> =======
> 
> package com.subshell.sophora.server.persistence.jcr;
> 
> import javax.jcr.Node;
> import javax.jcr.RepositoryException;
> import javax.jcr.Session;
> 
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> import org.apache.jackrabbit.JcrConstants;
> import
> org.springframework.test.AbstractDependencyInjectionSpringContextTests;
> import
> org.springframework.transaction.support.TransactionSynchronizationManager;
> import org.springmodules.jcr.JcrTemplate;
> import org.springmodules.jcr.SessionFactory;
> import org.springmodules.jcr.SessionFactoryUtils;
> 
> public class NodeServiceTests extends
> 		AbstractDependencyInjectionSpringContextTests {
> 
> 	protected static final Log log =
> LogFactory.getLog(NodeServiceTests.class);
> 
> 	protected JcrTemplate jcrTemplate;
> 
> 	private SessionFactory sf;
> 
> 	private Session session;
> 
> 	public JcrTemplate getJcrTemplate() {
> 		return jcrTemplate;
> 	}
> 
> 	public void setJcrTemplate(JcrTemplate jcrTemplate) {
> 		this.jcrTemplate = jcrTemplate;
> 	}
> 
> 	public NodeServiceTests() {
> 		super();
> 		setAutowireMode(AUTOWIRE_BY_NAME);
> 	}
> 
> 	@Override
> 	protected String[] getConfigLocations() {
> 		return new String[] { "classpath:WEB-INF/applicationContext.xml" };
> 	}
> 
> 	@Override
> 	protected void onSetUp() throws Exception {
> 		super.onSetUp();
> 		sf = jcrTemplate.getSessionFactory();
> 		session = SessionFactoryUtils.getSession(sf, true);
> 		TransactionSynchronizationManager.bindResource(sf,
> 				sf.getSessionHolder(session));
> 	}
> 
> 	@Override
> 	protected void onTearDown() throws Exception {
> 		TransactionSynchronizationManager.unbindResource(sf);
> 		SessionFactoryUtils.releaseSession(session, sf);
> 		super.onTearDown();
> 	}
> 
> 	public void testGetAllFiles() throws RepositoryException {
> 		Node addNode = jcrTemplate.getRootNode().addNode("test");
> 		addNode.addMixin(JcrConstants.MIX_REFERENCEABLE);
> 		String uuid = addNode.getUUID();
> 
> 		Node nodeByUUID = jcrTemplate.getNodeByUUID(uuid);
> 		assertEquals(JcrConstants.MIX_REFERENCEABLE,
> 				nodeByUUID.getMixinNodeTypes()[0].getName());
> 	}
> }
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Junit-testing-with-Jackrabbit-using-AbstractDependencyInjectionSpringContextTests-tf4111862.html#a11708893
Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.


Re: Junit testing with Jackrabbit using AbstractDependencyInjectionSpringContextTests

Posted by Christoph Kiehl <ch...@sulu3000.de>.
bilobag wrote:

> Ok, i think my issue is that I have the
> org.springmodules.jcr.support.OpenSessionInViewFilter configured in my
> web.xml which is supposed to keep my repository session open.  My dao mainly
> just uses the jcrTemplate methods to access the repository.  I believe the
> template opens and closes the session.  Does anyone know of a way to keep it
> open during my entire test case?   

I just copied some code from OpenSessionInViewFilter to put together a quick and 
dirty solution. I'm using transactions and therefore have a threadbound session 
available anyway. There might be a cleaner solution but this one should work for 
now.

Cheers,
Christoph

ps: Just post such questions to the user list next time. Most developers read 
both lists anyway.

=======

package com.subshell.sophora.server.persistence.jcr;

import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jackrabbit.JcrConstants;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springmodules.jcr.JcrTemplate;
import org.springmodules.jcr.SessionFactory;
import org.springmodules.jcr.SessionFactoryUtils;

public class NodeServiceTests extends
		AbstractDependencyInjectionSpringContextTests {

	protected static final Log log = LogFactory.getLog(NodeServiceTests.class);

	protected JcrTemplate jcrTemplate;

	private SessionFactory sf;

	private Session session;

	public JcrTemplate getJcrTemplate() {
		return jcrTemplate;
	}

	public void setJcrTemplate(JcrTemplate jcrTemplate) {
		this.jcrTemplate = jcrTemplate;
	}

	public NodeServiceTests() {
		super();
		setAutowireMode(AUTOWIRE_BY_NAME);
	}

	@Override
	protected String[] getConfigLocations() {
		return new String[] { "classpath:WEB-INF/applicationContext.xml" };
	}

	@Override
	protected void onSetUp() throws Exception {
		super.onSetUp();
		sf = jcrTemplate.getSessionFactory();
		session = SessionFactoryUtils.getSession(sf, true);
		TransactionSynchronizationManager.bindResource(sf,
				sf.getSessionHolder(session));
	}

	@Override
	protected void onTearDown() throws Exception {
		TransactionSynchronizationManager.unbindResource(sf);
		SessionFactoryUtils.releaseSession(session, sf);
		super.onTearDown();
	}

	public void testGetAllFiles() throws RepositoryException {
		Node addNode = jcrTemplate.getRootNode().addNode("test");
		addNode.addMixin(JcrConstants.MIX_REFERENCEABLE);
		String uuid = addNode.getUUID();

		Node nodeByUUID = jcrTemplate.getNodeByUUID(uuid);
		assertEquals(JcrConstants.MIX_REFERENCEABLE,
				nodeByUUID.getMixinNodeTypes()[0].getName());
	}
}



Re: Junit testing with Jackrabbit using AbstractDependencyInjectionSpringContextTests

Posted by bilobag <bi...@hotmail.com>.
Ok, i think my issue is that I have the
org.springmodules.jcr.support.OpenSessionInViewFilter configured in my
web.xml which is supposed to keep my repository session open.  My dao mainly
just uses the jcrTemplate methods to access the repository.  I believe the
template opens and closes the session.  Does anyone know of a way to keep it
open during my entire test case?   



bilobag wrote:
> 
> Yes, here is the source for my test class and the applicationContext.xml. 
> Please let me know what you think.  I would expect the jcrTemplate to open
> a repository session like it does when I run the web app, but it seems
> like its not.  Please let me know if there is something extra that I need
> to do to get my test case to work with a Jackrabbit repository.  Thanks.
> 
> 
> source:
> 
> 
> 
> public class NodeServiceTests extends
> AbstractDependencyInjectionSpringContextTests {
> 	protected static final Log log =
> LogFactory.getLog(NodeServiceTests.class);
> 
> 	private NodeService nodeService;
> 	
> 	public void setNodeService(NodeService nodeService) {
> 		this.nodeService = nodeService;
> 	}
> 	
> 	private NodeService getNodeService() {
> 		return this.nodeService;
> 	}
> 
> 	public NodeServiceTests() {
> 		super();
> 		setAutowireMode(AUTOWIRE_BY_NAME);
> 	}
> 	
> 	protected String[] getConfigLocations() {
> 		return new String[] { "classpath:WEB-INF/applicationContext.xml"};
> 	}
> 
> 	public void testGetAllFiles() throws IllegalAccessException,
> RepositoryException, InvocationTargetException {
> 		log.debug("****in testGetAllFiles()***");
> 		NodeDto fileNode = getNodeService().getNodeByPath("/app
> root/workspace3/folder0");
> 	
> 		Collection allFiles = getNodeService().getAllFiles(fileNode.getUuid());
> 		Iterator fileIter = allFiles.iterator();
> 		int x=0;
> 		while(fileIter.hasNext()) {
> 			log.debug("****fileNodeType" + x++ + " = " + fileIter.next());
> 		}
> 		log.debug("****end testGetAllFiles()" );
> 		assertNotNull(allFiles);
> 		
> 	}
> }
> 
> 
> applicationContext.xml:
> 
> <?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:aop="http://www.springframework.org/schema/aop"
> 	xmlns:tx="http://www.springframework.org/schema/tx"
> 	xsi:schemaLocation="http://www.springframework.org/schema/beans
> 			http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
>             http://www.springframework.org/schema/aop
> 			http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
>             http://www.springframework.org/schema/tx
> 			http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
> 
> 
> 	<bean id="repository"
> 		class="org.springmodules.jcr.jackrabbit.RepositoryFactoryBean">
> 		<!-- normal factory beans params -->
> 		<property name="configuration"
> 			value="/WEB-INF/app-repository.xml" />
> 	</bean>
> 
> 	<!-- JNDI configuration  -->
> 	<!-- bean id="repository"
> class="org.springframework.jndi.JndiObjectFactoryBean">
> 		<property name="jndiName" value="java:comp/env/jcr/myRepository"/>
> 		</bean -->
> 
> 	<!-- SessionFactory -->
> 	<bean id="jcrSessionFactory"
> 		class="org.app.webapp.util.AppJackrabbitSessionFactory">
> 		<property name="repository" ref="repository" />
> 		<property name="credentials">
> 			<bean class="javax.jcr.SimpleCredentials">
> 				<constructor-arg index="0" value="bogus" />
> 				<!-- create the credentials using a bean factory -->
> 				<constructor-arg index="1">
> 					<bean factory-bean="password"
> 						factory-method="toCharArray" />
> 				</constructor-arg>
> 			</bean>
> 		</property>
> 		<!-- 
> 			<property name="forceNamespacesRegistration" value="true"/>
> 			<property name="keepNewNamespaces" value="false"/>
> 		-->
> 		<property name="skipExistingNamespaces" value="true" />
> 		<property name="contentType" value="text/x-jcr-cnd" />
> 		<property name="nodeDefinitions">
> 
> 			<list>
> 				<value>/WEB-INF/appNodeTypes.cnd</value>
> 			</list>
> 		</property>
> 	</bean>
> 
> 	<!-- create the password to return it as a char[] -->
> 	<bean id="password" class="java.lang.String">
> 		<constructor-arg index="0" value="" />
> 	</bean>
> 
> 	<bean id="jcrTemplate" class="org.springmodules.jcr.JcrTemplate">
> 		<property name="sessionFactory" ref="jcrSessionFactory" />
> 		<property name="allowCreate" value="true" />
> 	</bean>
> 
> 	<bean id="jcrTransactionManager"
> 		class="org.springmodules.jcr.jackrabbit.LocalTransactionManager">
> 		<property name="sessionFactory" ref="jcrSessionFactory" />
> 	</bean>
> 
> 
> 	<bean id="txProxyTemplate" abstract="true"
> 	
> class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
> 		<property name="proxyTargetClass">
> 			<value>true</value>
> 		</property>
> 		<property name="transactionManager" ref="jcrTransactionManager" />
> 		<property name="transactionAttributes">
> 			<props>
> 				<prop key="save*">PROPAGATION_REQUIRED</prop>
> 				<prop key="*">PROPAGATION_REQUIRED, readOnly</prop>
> 			</props>
> 		</property>
> 	</bean>
> 
> 	<!-- 	
> 		<bean id="jcrService" parent="txProxyTemplate">
> 		<property name="target">
> 		<bean class="org.springmodules.examples.jcr.JcrService">
> 		<property name="template" ref="jcrTemplate"/>
> 		</bean>
> 		</property>
> 		</bean>
> 	-->
> 	<bean id="transactionRepository"
> 		class="org.springmodules.jcr.TransactionAwareRepository">
> 		<property name="allowNonTxRepository" value="true" />
> 		<property name="targetFactory" ref="jcrSessionFactory" />
> 	</bean>
> 
> 
> 	<!-- **************************************************
> 		***************** Hibernate Config ***************
> 		************************************************** -->
> 
> 	<bean id="sessionFactory"
> 		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
> 		<property name="dataSource" ref="dataSource" />
> 		<!-- 
> 			<property name="mappingDirectoryLocations">
> 			
> 			
> 			
> 			</property>
> 		-->
> 
> 		<property name="hibernateProperties">
> 			<props>
> 				<prop key="hibernate.dialect">
> 					org.hibernate.dialect.Oracle9Dialect
> 				</prop>
> 				<prop key="hibernate.show_sql">false</prop>
> 				<prop key="hibernate.jdbc.use_get_generated_keys">
> 					true
> 				</prop>
> 				<prop key="hibernate.max_fetch_depth">3</prop>
> 				<prop key="hibernate.jdbc.fetch_size">5</prop>
> 				<prop key="hibernate.jdbc.batch_size">20</prop>
> 				<prop key="hibernate.use_outer_join">true</prop>
> 				<prop key="cache.provider_class">
> 					org.hibernate.cache.NoCacheProvider
> 				</prop>
> 				<prop key="cache.use_query_cache">false</prop>
> 				<prop key="cache.use_minimal_puts">false</prop>
> 			</props>
> 		</property>
> 	</bean>
> 
> 	<!-- Transaction manager for a single Hibernate SessionFactory
> (alternative to JTA) -->
> 	<bean id="transactionManager"
> 		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
> 		<property name="sessionFactory" ref="sessionFactory" />
> 	</bean>
> 
> 	<tx:annotation-driven transaction-manager="transactionManager" />
> 
> 	<!--***********************************************
> 		******* Helper class that simplifies Hibernate 
> 		data access code, and converts checked HibernateExceptions 
> 		into unchecked DataAccessExceptions,  ************
> 		***********************************************-->
> 	<bean id="hibernateTemplate"
> 		class="org.springframework.orm.hibernate3.HibernateTemplate">
> 		<property name="sessionFactory">
> 			<ref bean="sessionFactory" />
> 		</property>
> 	</bean>
> 
> 	<!-- This bean defines the database information -->
> 	<bean class="com.mchange.v2.c3p0.ComboPooledDataSource"
> 		id="dataSource" destroy-method="close">
> 		<property name="driverClass">
> 			<value>@driverClassName@</value>
> 		</property>
> 		<property name="jdbcUrl">
> 			<value>@driverUrl@</value>
> 		</property>
> 		<property name="properties">
> 			<props>
> 				<prop key="c3p0.acquire_increment">5</prop>
> 				<prop key="c3p0.idle_test_period">100</prop>
> 				<prop key="c3p0.max_statements">0</prop>
> 				<prop key="c3p0.min_size">3</prop>
> 				<prop key="maxPoolSize">5</prop>
> 				<prop key="user">@username@</prop>
> 				<prop key="password">@password@</prop>
> 			</props>
> 		</property>
> 	</bean>
> 
> 
> 	<!--***********************************************
> 		***************   Services  *******************
> 		***********************************************-->
> 
> 	<bean id="nodeService"
> 		class="org.app.service.impl.NodeServiceImpl">
> 		<property name="jcrDAO" ref="jcrDao" />
> 	</bean>
> 	
> 	<bean id="fileNodeService"
> 		class="org.app.service.impl.FileNodeServiceImpl">
> 		<property name="jcrDAO" ref="jcrDao" />
> 	</bean>
> 	
> 
> 
> 	<!-- **************************************************
> 		*****************   DAO's  ***********************
> 		************************************************** -->
> 
> 	<bean
> 		class="org.springframework.orm.hibernate3.support.HibernateDaoSupport"
> 		id="hibernateSupport" abstract="true">
> 		<property name="sessionFactory">
> 			<ref bean="sessionFactory" />
> 		</property>
> 	</bean>
> 
> 	<bean id="userDao" class="org.app.dao.impl.UserDaoImpl"
> 		parent="hibernateSupport" />
> 
> 	<bean id="jcrDao" class="org.app.dao.impl.JcrBaseDAO">
> 		<property name="template" ref="jcrTemplate" />
> 	</bean>
> 
> </beans>
> 
> 
> 
> 
> Christoph Kiehl-3 wrote:
>> 
>> bilobag wrote:
>> 
>>> javax.jcr.RepositoryException: this session has been closed
>> 
>> Could you please provide the source code of a very simple TestCase that
>> fails 
>> for you? It seems like the session is closed to early (well obviously ;)
>> but 
>> without the source it's very difficult to tell what's going wrong.
>> 
>> Cheers,
>> Christoph
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Junit-testing-with-Jackrabbit-using-AbstractDependencyInjectionSpringContextTests-tf4111862.html#a11696412
Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.


Re: Junit testing with Jackrabbit using AbstractDependencyInjectionSpringContextTests

Posted by bilobag <bi...@hotmail.com>.
Yes, here is the source for my test class and the applicationContext.xml. 
Please let me know what you think.  I would expect the jcrTemplate to open a
repository session like it does when I run the web app, but it seems like
its not.  Please let me know if there is something extra that I need to do
to get my test case to work with a Jackrabbit repository.  Thanks.


source:



public class NodeServiceTests extends
AbstractDependencyInjectionSpringContextTests {
	protected static final Log log = LogFactory.getLog(NodeServiceTests.class);

	private NodeService nodeService;
	
	public void setNodeService(NodeService nodeService) {
		this.nodeService = nodeService;
	}
	
	private NodeService getNodeService() {
		return this.nodeService;
	}

	public NodeServiceTests() {
		super();
		setAutowireMode(AUTOWIRE_BY_NAME);
	}
	
	protected String[] getConfigLocations() {
		return new String[] { "classpath:WEB-INF/applicationContext.xml"};
	}

	public void testGetAllFiles() throws IllegalAccessException,
RepositoryException, InvocationTargetException {
		log.debug("****in testGetAllFiles()***");
		NodeDto fileNode = getNodeService().getNodeByPath("/app
root/workspace3/folder0");
	
		Collection allFiles = getNodeService().getAllFiles(fileNode.getUuid());
		Iterator fileIter = allFiles.iterator();
		int x=0;
		while(fileIter.hasNext()) {
			log.debug("****fileNodeType" + x++ + " = " + fileIter.next());
		}
		log.debug("****end testGetAllFiles()" );
		assertNotNull(allFiles);
		
	}
}


applicationContext.xml:

<?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:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
			http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
            http://www.springframework.org/schema/aop
			http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
            http://www.springframework.org/schema/tx
			http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">


	<bean id="repository"
		class="org.springmodules.jcr.jackrabbit.RepositoryFactoryBean">
		<!-- normal factory beans params -->
		<property name="configuration"
			value="/WEB-INF/app-repository.xml" />
	</bean>

	<!-- JNDI configuration  -->
	<!-- bean id="repository"
class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiName" value="java:comp/env/jcr/myRepository"/>
		</bean -->

	<!-- SessionFactory -->
	<bean id="jcrSessionFactory"
		class="org.app.webapp.util.AppJackrabbitSessionFactory">
		<property name="repository" ref="repository" />
		<property name="credentials">
			<bean class="javax.jcr.SimpleCredentials">
				<constructor-arg index="0" value="bogus" />
				<!-- create the credentials using a bean factory -->
				<constructor-arg index="1">
					<bean factory-bean="password"
						factory-method="toCharArray" />
				</constructor-arg>
			</bean>
		</property>
		<!-- 
			<property name="forceNamespacesRegistration" value="true"/>
			<property name="keepNewNamespaces" value="false"/>
		-->
		<property name="skipExistingNamespaces" value="true" />
		<property name="contentType" value="text/x-jcr-cnd" />
		<property name="nodeDefinitions">

			<list>
				<value>/WEB-INF/appNodeTypes.cnd</value>
			</list>
		</property>
	</bean>

	<!-- create the password to return it as a char[] -->
	<bean id="password" class="java.lang.String">
		<constructor-arg index="0" value="" />
	</bean>

	<bean id="jcrTemplate" class="org.springmodules.jcr.JcrTemplate">
		<property name="sessionFactory" ref="jcrSessionFactory" />
		<property name="allowCreate" value="true" />
	</bean>

	<bean id="jcrTransactionManager"
		class="org.springmodules.jcr.jackrabbit.LocalTransactionManager">
		<property name="sessionFactory" ref="jcrSessionFactory" />
	</bean>


	<bean id="txProxyTemplate" abstract="true"
	
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
		<property name="proxyTargetClass">
			<value>true</value>
		</property>
		<property name="transactionManager" ref="jcrTransactionManager" />
		<property name="transactionAttributes">
			<props>
				<prop key="save*">PROPAGATION_REQUIRED</prop>
				<prop key="*">PROPAGATION_REQUIRED, readOnly</prop>
			</props>
		</property>
	</bean>

	<!-- 	
		<bean id="jcrService" parent="txProxyTemplate">
		<property name="target">
		<bean class="org.springmodules.examples.jcr.JcrService">
		<property name="template" ref="jcrTemplate"/>
		</bean>
		</property>
		</bean>
	-->
	<bean id="transactionRepository"
		class="org.springmodules.jcr.TransactionAwareRepository">
		<property name="allowNonTxRepository" value="true" />
		<property name="targetFactory" ref="jcrSessionFactory" />
	</bean>


	<!-- **************************************************
		***************** Hibernate Config ***************
		************************************************** -->

	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<!-- 
			<property name="mappingDirectoryLocations">
			
			
			
			</property>
		-->

		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.Oracle9Dialect
				</prop>
				<prop key="hibernate.show_sql">false</prop>
				<prop key="hibernate.jdbc.use_get_generated_keys">
					true
				</prop>
				<prop key="hibernate.max_fetch_depth">3</prop>
				<prop key="hibernate.jdbc.fetch_size">5</prop>
				<prop key="hibernate.jdbc.batch_size">20</prop>
				<prop key="hibernate.use_outer_join">true</prop>
				<prop key="cache.provider_class">
					org.hibernate.cache.NoCacheProvider
				</prop>
				<prop key="cache.use_query_cache">false</prop>
				<prop key="cache.use_minimal_puts">false</prop>
			</props>
		</property>
	</bean>

	<!-- Transaction manager for a single Hibernate SessionFactory (alternative
to JTA) -->
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>

	<tx:annotation-driven transaction-manager="transactionManager" />

	<!--***********************************************
		******* Helper class that simplifies Hibernate 
		data access code, and converts checked HibernateExceptions 
		into unchecked DataAccessExceptions,  ************
		***********************************************-->
	<bean id="hibernateTemplate"
		class="org.springframework.orm.hibernate3.HibernateTemplate">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>

	<!-- This bean defines the database information -->
	<bean class="com.mchange.v2.c3p0.ComboPooledDataSource"
		id="dataSource" destroy-method="close">
		<property name="driverClass">
			<value>@driverClassName@</value>
		</property>
		<property name="jdbcUrl">
			<value>@driverUrl@</value>
		</property>
		<property name="properties">
			<props>
				<prop key="c3p0.acquire_increment">5</prop>
				<prop key="c3p0.idle_test_period">100</prop>
				<prop key="c3p0.max_statements">0</prop>
				<prop key="c3p0.min_size">3</prop>
				<prop key="maxPoolSize">5</prop>
				<prop key="user">@username@</prop>
				<prop key="password">@password@</prop>
			</props>
		</property>
	</bean>


	<!--***********************************************
		***************   Services  *******************
		***********************************************-->

	<bean id="nodeService"
		class="org.app.service.impl.NodeServiceImpl">
		<property name="jcrDAO" ref="jcrDao" />
	</bean>
	
	<bean id="fileNodeService"
		class="org.app.service.impl.FileNodeServiceImpl">
		<property name="jcrDAO" ref="jcrDao" />
	</bean>
	


	<!-- **************************************************
		*****************   DAO's  ***********************
		************************************************** -->

	<bean
		class="org.springframework.orm.hibernate3.support.HibernateDaoSupport"
		id="hibernateSupport" abstract="true">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>

	<bean id="userDao" class="org.app.dao.impl.UserDaoImpl"
		parent="hibernateSupport" />

	<bean id="jcrDao" class="org.app.dao.impl.JcrBaseDAO">
		<property name="template" ref="jcrTemplate" />
	</bean>

</beans>




Christoph Kiehl-3 wrote:
> 
> bilobag wrote:
> 
>> javax.jcr.RepositoryException: this session has been closed
> 
> Could you please provide the source code of a very simple TestCase that
> fails 
> for you? It seems like the session is closed to early (well obviously ;)
> but 
> without the source it's very difficult to tell what's going wrong.
> 
> Cheers,
> Christoph
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Junit-testing-with-Jackrabbit-using-AbstractDependencyInjectionSpringContextTests-tf4111862.html#a11694987
Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.


Re: Junit testing with Jackrabbit using AbstractDependencyInjectionSpringContextTests

Posted by Christoph Kiehl <ch...@sulu3000.de>.
bilobag wrote:

> javax.jcr.RepositoryException: this session has been closed

Could you please provide the source code of a very simple TestCase that fails 
for you? It seems like the session is closed to early (well obviously ;) but 
without the source it's very difficult to tell what's going wrong.

Cheers,
Christoph