Return-Path: Delivered-To: apmail-jackrabbit-dev-archive@www.apache.org Received: (qmail 96729 invoked from network); 20 Jul 2007 14:16:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 20 Jul 2007 14:16:13 -0000 Received: (qmail 40441 invoked by uid 500); 20 Jul 2007 14:15:36 -0000 Delivered-To: apmail-jackrabbit-dev-archive@jackrabbit.apache.org Received: (qmail 40396 invoked by uid 500); 20 Jul 2007 14:15:35 -0000 Mailing-List: contact dev-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list dev@jackrabbit.apache.org Received: (qmail 40357 invoked by uid 99); 20 Jul 2007 14:15:35 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Jul 2007 07:15:35 -0700 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=FORGED_HOTMAIL_RCVD2,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of lists@nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Jul 2007 07:15:30 -0700 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1IBtG9-0006Tm-P4 for dev@jackrabbit.apache.org; Fri, 20 Jul 2007 07:15:09 -0700 Message-ID: <11708893.post@talk.nabble.com> Date: Fri, 20 Jul 2007 07:15:09 -0700 (PDT) From: bilobag To: dev@jackrabbit.apache.org Subject: Re: Junit testing with Jackrabbit using AbstractDependencyInjectionSpringContextTests In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: bilobag@hotmail.com References: <11691587.post@talk.nabble.com> <11694987.post@talk.nabble.com> <11696412.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org 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.