jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bilobag <bilo...@hotmail.com>
Subject Re: Junit testing with Jackrabbit using AbstractDependencyInjectionSpringContextTests
Date Thu, 19 Jul 2007 19:42:28 GMT

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.


Mime
View raw message