You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by cl...@apache.org on 2008/05/19 21:52:40 UTC
svn commit: r657946 - in /jackrabbit/sandbox/jackrabbit-jcr-mapping/spring:
./ src/test/java/org/apache/jackrabbit/ocm/spring/
src/test/java/org/apache/jackrabbit/ocm/spring/test/model/
src/test/resources/ src/test/resources/nodetypes/
Author: clombart
Date: Mon May 19 12:52:40 2008
New Revision: 657946
URL: http://svn.apache.org/viewvc?rev=657946&view=rev
Log:
- Use OCM annotations for the unit test
- Migrate to junit 4
- Simplify the Spring config file
- Update to the latest Spring module version for the JCR support
- Remove the nodetypes which are not necessary from OCM 1.5 snapshot
Removed:
jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/resources/jackrabbit-ocm.dtd
jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/resources/jcrmapping.xml
jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/resources/nodetypes/
Modified:
jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/pom.xml
jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/SimpleTest.java
jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/model/Article.java
jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/model/News.java
jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/resources/applicationContext-repository.xml
Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/pom.xml?rev=657946&r1=657945&r2=657946&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/pom.xml (original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/pom.xml Mon May 19 12:52:40 2008
@@ -131,7 +131,7 @@
</exclusion>
</exclusions>
</dependency>
- <dependency>
+ <!-- dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-api</artifactId>
<version>1.5-SNAPSHOT</version>
@@ -160,7 +160,7 @@
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-jca</artifactId>
<version>1.5-SNAPSHOT</version>
- </dependency>
+ </dependency -->
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-ocm</artifactId>
@@ -176,13 +176,23 @@
<artifactId>spring</artifactId>
<version>2.5.4</version>
</dependency>
-
+ <dependency>
+ <groupId>aspectj</groupId>
+ <artifactId>aspectjtools</artifactId>
+ <version>1.5.3</version>
+ </dependency>
<!-- Test -->
<dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>2.5.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.1</version>
+ <version>4.4</version>
<scope>test</scope>
</dependency>
Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/SimpleTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/SimpleTest.java?rev=657946&r1=657945&r2=657946&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/SimpleTest.java (original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/SimpleTest.java Mon May 19 12:52:40 2008
@@ -16,71 +16,52 @@
*/
package org.apache.jackrabbit.ocm.spring;
+import static org.junit.Assert.*;
+
import java.io.IOException;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
import org.apache.jackrabbit.ocm.spring.test.components.ArticleService;
import org.apache.jackrabbit.ocm.spring.test.components.NewsService;
import org.apache.jackrabbit.ocm.spring.test.model.Article;
import org.apache.jackrabbit.ocm.spring.test.model.News;
+import org.junit.Test;
+
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
-
-/**
- * Test Mapper
- *
- * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
- */
-public class SimpleTest extends TestCase
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.transaction.annotation.Transactional;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations={"/applicationContext-repository.xml"})
+public class SimpleTest
{
+ private ArticleService articleService;
+ private NewsService newsService;
- /**
- * <p>Defines the test case name for junit.</p>
- * @param testName The test case name.
- */
- public SimpleTest(String testName)
- {
- super(testName);
- }
-
- /**
- * @see junit.framework.TestCase#setUp()
- */
- protected void setUp() throws Exception
- {
- super.setUp();
- }
-
- /**
- * @see junit.framework.TestCase#tearDown()
- */
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
+ @Autowired
+ public void setArticleService(ArticleService articleService) {
+ this.articleService = articleService;
+ }
- public static Test suite()
- {
- // All methods starting with "test" will be executed in the test suite.
- return new TestSuite(SimpleTest.class);
- }
+ @Autowired
+ public void setNewsService(NewsService newsService) {
+ this.newsService = newsService;
+ }
- public void testCommit()
+ @Test
+ public void testCommit()
{
try {
System.out.println("Init Spring");
- AbstractApplicationContext context = getApplicationContext();
- //ResourceLoader loader = new DefaultResourceLoader();
System.out.println("Add article");
- ArticleService articleService = (ArticleService) context .getBean("org.apache.jackrabbit.ocm.spring.test.components.ArticleService");
Article article = new Article();
article.setPath("/article");
article.setAuthor("Christophe");
@@ -93,7 +74,6 @@
// Check if a news has been created
System.out.println("Check News");
- NewsService newsService = (NewsService) context .getBean("org.apache.jackrabbit.ocm.spring.test.components.NewsService");
Collection news = newsService.getNews();
assertEquals("Invalid number of news", news.size(), 1);
@@ -112,8 +92,6 @@
news = newsService.getNews();
assertEquals("Invalid number of news", news.size(), 0);
-
- context.close();
} catch (Exception e) {
e.printStackTrace();
@@ -121,16 +99,16 @@
}
+ @Test
public void testRollback()
{
try {
System.out.println("Init Spring");
- AbstractApplicationContext context = getApplicationContext();
+
//ResourceLoader loader = new DefaultResourceLoader();
System.out.println("Add article");
- ArticleService service = (ArticleService) context .getBean("org.apache.jackrabbit.ocm.spring.test.components.ArticleService");
Article article = new Article();
article.setPath("/article-rollback");
article.setAuthor("Christophe");
@@ -140,32 +118,21 @@
article.setTitle("Article Title");
try
{
- service.createArticlesRollback(article);
+ articleService.createArticlesRollback(article);
+ fail("PersistenceException is not throw");
}
catch (Exception e)
{
- article = service.getArticle("/article-rollback");
+ article = articleService.getArticle("/article-rollback");
assertNull("article is not null", article);
- context.close();
- return;
}
- fail("PersistenceException is not throw");
+
} catch (Exception e) {
e.printStackTrace();
}
-
-
}
-
- private AbstractApplicationContext getApplicationContext() throws IOException
- {
- //new FileSystemXmlApplicationContext("/" + new ClassPathResource("applicationContext-repository.xml").getFile().getPath());
- AbstractApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-repository.xml");
- return context;
- }
-
}
\ No newline at end of file
Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/model/Article.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/model/Article.java?rev=657946&r1=657945&r2=657946&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/model/Article.java (original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/model/Article.java Mon May 19 12:52:40 2008
@@ -21,25 +21,28 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field;
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
/**
* Simple Article class
*
* @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
- *
+ *
*/
-public class Article
+@Node
+public class Article
{
protected final static Log log = LogFactory.getLog(Article.class);
-
- protected String path;
- protected String title;
- protected String description;
- protected String author;
- protected Date creationDate;
- protected String content;
-
-
+
+ @Field(path=true) protected String path;
+ @Field protected String title;
+ @Field protected String description;
+ @Field protected String author;
+ @Field protected Date creationDate;
+ @Field protected String content;
+
+
public String getPath()
{
return path;
Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/model/News.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/model/News.java?rev=657946&r1=657945&r2=657946&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/model/News.java (original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/model/News.java Mon May 19 12:52:40 2008
@@ -17,27 +17,30 @@
package org.apache.jackrabbit.ocm.spring.test.model;
-import java.util.*;
+import java.util.Date;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field;
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
/**
* Simple New class
*
* @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
- *
+ *
*/
-public class News
+@Node
+public class News
{
protected final static Log log = LogFactory.getLog(News.class);
-
- protected String path;
- protected Date creationDate;
- protected String content;
-
-
-
+
+ @Field(path=true) protected String path;
+ @Field protected Date creationDate;
+ @Field protected String content;
+
+
+
public String getPath()
{
return path;
Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/resources/applicationContext-repository.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/resources/applicationContext-repository.xml?rev=657946&r1=657945&r2=657946&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/resources/applicationContext-repository.xml (original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/resources/applicationContext-repository.xml Mon May 19 12:52:40 2008
@@ -1,101 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
- "http://www.springframework.org/dtd/spring-beans.dtd">
-<!--
- JSR-170 configuration support. Note that the transaction managers are defined
- in separate files.
-
- $Id: applicationContext-repository.xml,v 1.2 2005/10/10 09:20:42 costin Exp $
- -->
-<beans default-lazy-init="true">
- <!-- import resource="applicationContext-jr-jca.xml"/ -->
- <import resource="applicationContext-jr-local.xml"/>
+<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"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
+
+ <!--
+ JSR-170 configuration support. Note that the transaction managers are defined
+ in separate files.
+
+ $Id: applicationContext-repository.xml,v 1.2 2005/10/10 09:20:42 costin Exp $
+ -->
+
+ <bean id="transactionManager"
+ class="org.springmodules.jcr.jackrabbit.LocalTransactionManager">
+ <property name="sessionFactory" ref="jcrSessionFactory" />
+ </bean>
+
+ <bean id="repository"
+ class="org.springmodules.jcr.jackrabbit.RepositoryFactoryBean">
+ <!-- normal factory beans params -->
+ <property name="configuration"
+ value="file:./src/test/resources/repository.xml" />
+ <property name="homeDir" value="file:./target/repository" />
+ </bean>
- <bean id="jcrSessionFactory" class="org.apache.jackrabbit.ocm.spring.JackrabbitSessionFactory">
- <property name="repository" ref="repository"/>
+ <bean id="jcrSessionFactory"
+ class="org.apache.jackrabbit.ocm.spring.JackrabbitSessionFactory">
+ <property name="repository" ref="repository" />
<property name="credentials">
<bean class="javax.jcr.SimpleCredentials">
- <constructor-arg index="0" value="superuser"/>
+ <constructor-arg index="0" value="superuser" />
<!-- create the credentials using a bean factory -->
<constructor-arg index="1">
<bean factory-bean="password"
- factory-method="toCharArray"/>
+ factory-method="toCharArray" />
</constructor-arg>
- </bean>
+ </bean>
- </property>
- <property name="nodeTypes2Import" value="file:./src/test/resources/nodetypes/custom_nodetypes.xml"/>
+ </property>
+ <!-- property name="nodeTypes2Import" value="file:./src/test/resources/nodetypes/custom_nodetypes.xml"/-->
</bean>
<!-- create the password to return it as a char[] -->
<bean id="password" class="java.lang.String">
- <constructor-arg index="0" value="superuser"/>
- </bean>
-
-
- <bean id="jcrMappingDescriptor" class="org.apache.jackrabbit.ocm.mapper.impl.digester.DigesterMapperImpl">
- <constructor-arg index="0" value="./src/test/resources/jcrmapping.xml"/>
+ <constructor-arg index="0" value="superuser" />
</bean>
- <bean id="jcrMappingTemplate" class="org.apache.jackrabbit.ocm.spring.JcrMappingTemplate">
- <constructor-arg index="0" ref="jcrSessionFactory"/>
- <constructor-arg index="1" ref="jcrMappingDescriptor"/>
- </bean>
- <bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
- abstract="true">
- <property name="transactionManager">
- <ref bean="jcrTransactionManager"/>
- </property>
- <property name="transactionAttributes">
- <props>
- <prop key="*">PROPAGATION_REQUIRED</prop>
- </props>
- </property>
+ <bean id="jcrMappingDescriptor"
+ class="org.apache.jackrabbit.ocm.mapper.impl.annotation.AnnotationMapperImpl">
+ <constructor-arg index="0">
+ <list>
+ <value>
+ org.apache.jackrabbit.ocm.spring.test.model.Article
+ </value>
+ <value>
+ org.apache.jackrabbit.ocm.spring.test.model.News
+ </value>
+ </list>
+ </constructor-arg>
</bean>
-
- <bean id="org.apache.jackrabbit.ocm.spring.test.components.impl.NewsServiceImpl"
- class="org.apache.jackrabbit.ocm.spring.test.components.impl.NewsServiceImpl" >
- <property name="jcrMappingTemplate" ref="jcrMappingTemplate"/>
+ <bean id="jcrMappingTemplate"
+ class="org.apache.jackrabbit.ocm.spring.JcrMappingTemplate">
+ <constructor-arg index="0" ref="jcrSessionFactory" />
+ <constructor-arg index="1" ref="jcrMappingDescriptor" />
</bean>
- <bean id="org.apache.jackrabbit.ocm.spring.test.components.NewsService" parent="baseTransactionProxy">
- <property name="proxyInterfaces">
- <value>org.apache.jackrabbit.ocm.spring.test.components.NewsService</value>
- </property>
- <property name="target">
- <ref bean="org.apache.jackrabbit.ocm.spring.test.components.impl.NewsServiceImpl"/>
- </property>
- <property name="transactionAttributes">
- <props>
+ <tx:annotation-driven />
- <prop key="*">PROPAGATION_REQUIRED</prop>
- </props>
- </property>
- </bean>
- <bean id="org.apache.jackrabbit.ocm.spring.test.components.impl.ArticleServiceImpl"
- class="org.apache.jackrabbit.ocm.spring.test.components.impl.ArticleServiceImpl" >
- <property name="jcrMappingTemplate" ref="jcrMappingTemplate"/>
- <property name="newsService" ref="org.apache.jackrabbit.ocm.spring.test.components.NewsService"/>
+ <bean
+ id="org.apache.jackrabbit.ocm.spring.test.components.NewsService"
+ class="org.apache.jackrabbit.ocm.spring.test.components.impl.NewsServiceImpl">
+ <property name="jcrMappingTemplate" ref="jcrMappingTemplate" />
</bean>
- <bean id="org.apache.jackrabbit.ocm.spring.test.components.ArticleService" parent="baseTransactionProxy">
- <property name="proxyInterfaces">
- <value>org.apache.jackrabbit.ocm.spring.test.components.ArticleService</value>
- </property>
- <property name="target">
- <ref bean="org.apache.jackrabbit.ocm.spring.test.components.impl.ArticleServiceImpl"/>
- </property>
- <property name="transactionAttributes">
- <props>
- <prop key="*">PROPAGATION_REQUIRED</prop>
- </props>
- </property>
+ <bean
+ id="org.apache.jackrabbit.ocm.spring.test.components.ArticleService"
+ class="org.apache.jackrabbit.ocm.spring.test.components.impl.ArticleServiceImpl">
+ <property name="jcrMappingTemplate" ref="jcrMappingTemplate" />
+ <property name="newsService"
+ ref="org.apache.jackrabbit.ocm.spring.test.components.NewsService" />
</bean>
+ <tx:advice id="txAdvice"
+ transaction-manager="transactionManager">
+ <!-- the transactional semantics... -->
+ <tx:attributes>
+ <!-- all methods starting with 'get' are read-only -->
+ <tx:method name="get*" read-only="true" />
+ <!-- other methods use the default transaction settings (see below) -->
+ <tx:method name="*" />
+ </tx:attributes>
+ </tx:advice>
+ <aop:config>
+ <aop:pointcut id="serviceOperations"
+ expression="execution(* org.apache.jackrabbit.ocm.spring.test.components.impl.*.*(..))" />
+ <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperations" />
+ </aop:config>
</beans>
\ No newline at end of file