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/05 21:59:14 UTC

svn commit: r653575 [2/2] - in /jackrabbit/sandbox/jackrabbit-jcr-mapping/spring: ./ src/java/ src/main/java/org/apache/jackrabbit/ocm/spring/ src/spring-config/ src/test-config/ src/test/ src/test/java/org/apache/jackrabbit/ocm/spring/ src/test/java/o...

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=653575&r1=653574&r2=653575&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  5 12:59:14 2008
@@ -1,108 +1,171 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jackrabbit.ocm.spring;
-
-import java.util.Date;
-import java.util.Iterator;
-
-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.springframework.context.support.AbstractApplicationContext;
-import org.springframework.context.support.FileSystemXmlApplicationContext;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Test Mapper
- *
- * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
- */
-public class SimpleTest extends TestCase
-{
-
-    
-    /**
-     * <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();
-    }
-
-    public static Test suite()
-    {
-        // All methods starting with "test" will be executed in the test suite.
-        return new TestSuite(SimpleTest.class);
-    }
-
-    public void testComponents()    
-    {
-		try {
-			System.out.println("Init Spring");
-			AbstractApplicationContext context = new FileSystemXmlApplicationContext("src/spring-config/applicationContext-repository.xml");
-			//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");
-			article.setAuthor("Christophe");
-			article.setContent("This is an interesting content");
-			article.setCreationDate(new Date());
-			article.setDescription("This is the article description");
-			article.setTitle("Article Title");
-
-			service.createArticle(article);
-
-			System.out.println("Check News");
-			NewsService newsService = (NewsService) context .getBean("org.apache.jackrabbit.ocm.spring.test.components.NewsService");
-			Iterator news = newsService.getNews().iterator();
-			while (news.hasNext())
-			{
-				News newsFound = (News) news.next();
-				System.out.println("News found : " + newsFound.getContent());
-			}
-			context.close();
-		} catch (Exception e) {
-			
-			e.printStackTrace();
-		}
-    	
-    }
-    
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.ocm.spring;
+
+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.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
+{
+
+
+    /**
+     * <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();
+    }
+
+    public static Test suite()
+    {
+        // All methods starting with "test" will be executed in the test suite.
+        return new TestSuite(SimpleTest.class);
+    }
+
+    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");
+			article.setContent("This is an interesting content");
+			article.setCreationDate(new Date());
+			article.setDescription("This is the article description");
+			article.setTitle("Article Title");
+
+			articleService.createArticle(article);
+
+			// 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);
+
+			Iterator newIterator = news.iterator();
+			while (newIterator.hasNext())
+			{
+				News newsFound = (News) newIterator.next();
+				System.out.println("News found : " + newsFound.getContent());
+			}
+
+			// Delete
+			articleService.deleteArticle("/article");
+			article = articleService.getArticle("/article");
+			assertNull("Article has not been delete", article);
+			newsService.deleteAllNews();
+			news = newsService.getNews();
+			assertEquals("Invalid number of news", news.size(), 0);
+
+
+			context.close();
+		} catch (Exception e) {
+
+			e.printStackTrace();
+		}
+
+    }
+
+    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");
+			article.setContent("This is an interesting content");
+			article.setCreationDate(new Date());
+			article.setDescription("This is the article description");
+			article.setTitle("Article Title");
+            try
+            {
+			   service.createArticlesRollback(article);
+            }
+            catch (Exception e)
+            {
+			   article = service.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

Added: jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/exception/PersistenceException.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/exception/PersistenceException.java?rev=653575&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/exception/PersistenceException.java (added)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/exception/PersistenceException.java Mon May  5 12:59:14 2008
@@ -0,0 +1,5 @@
+package org.apache.jackrabbit.ocm.spring.exception;
+
+public class PersistenceException extends RuntimeException {
+
+}

Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/ArticleService.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/ArticleService.java?rev=653575&r1=653574&r2=653575&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/ArticleService.java (original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/ArticleService.java Mon May  5 12:59:14 2008
@@ -1,34 +1,40 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jackrabbit.ocm.spring.test.components;
-
-import java.util.Collection;
-
-import org.apache.jackrabbit.ocm.spring.test.model.Article;
-/**
- *
- * VERY Simple article management
- * 
- * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
- *
- */
-public interface ArticleService
-{
-	public void createArticle(Article article);
-
-	public Collection getArticles();
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.ocm.spring.test.components;
+
+import java.util.Collection;
+
+import org.apache.jackrabbit.ocm.spring.test.model.Article;
+/**
+ *
+ * VERY Simple article management
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ *
+ */
+public interface ArticleService
+{
+	public void createArticle(Article article);
+
+	public void createArticlesRollback(Article article);
+
+	public Collection getArticles();
+
+	public Article getArticle(String path);
+
+	public void deleteArticle(String path);
+}

Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/NewsService.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/NewsService.java?rev=653575&r1=653574&r2=653575&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/NewsService.java (original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/NewsService.java Mon May  5 12:59:14 2008
@@ -1,34 +1,36 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jackrabbit.ocm.spring.test.components;
-
-import java.util.Collection;
-
-import org.apache.jackrabbit.ocm.spring.test.model.News;
-/**
- *
- * VERY Simple news management
- * 
- * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
- *
- */
-public interface NewsService
-{
-	public void createNews(News news);
-
-	public Collection getNews();
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.ocm.spring.test.components;
+
+import java.util.Collection;
+
+import org.apache.jackrabbit.ocm.spring.test.model.News;
+/**
+ *
+ * VERY Simple news management
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ *
+ */
+public interface NewsService
+{
+	public void createNews(News news);
+
+	public Collection getNews();
+
+	public void deleteAllNews();
+}

Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/impl/ArticleServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/impl/ArticleServiceImpl.java?rev=653575&r1=653574&r2=653575&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/impl/ArticleServiceImpl.java (original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/impl/ArticleServiceImpl.java Mon May  5 12:59:14 2008
@@ -1,97 +1,121 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jackrabbit.ocm.spring.test.components.impl;
-
-import java.util.Collection;
-import java.util.Date;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jackrabbit.ocm.query.Filter;
-import org.apache.jackrabbit.ocm.query.Query;
-import org.apache.jackrabbit.ocm.query.QueryManager;
-import org.apache.jackrabbit.ocm.spring.JcrMappingTemplate;
-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;
-
-/**
- * Default implementation for {@link org.apache.jackrabbit.ocm.spring.test.components.ArticleService}
- * 
- * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
- *
- */
-public class ArticleServiceImpl implements ArticleService {
-    private static final Log log = LogFactory.getLog(ArticleServiceImpl.class);
-
-    private JcrMappingTemplate jcrMappingtemplate;
-    private NewsService newsService;
-
-    
-    public void createArticle(Article article)
-	{
-    	
-        jcrMappingtemplate.insert(article);
-        jcrMappingtemplate.save();
-        
-        
-        News news = new News();
-        news.setContent("A new article has been created by " + article.getAuthor());
-        news.setCreationDate(new Date());
-        news.setPath("/news-" + System.currentTimeMillis());
-        newsService.createNews(news);
-	}
-    
-	public Collection getArticles()
-	{
-
-		QueryManager queryManager = jcrMappingtemplate.createQueryManager();
-	    Filter filter = queryManager.createFilter(Article.class);
-	    
-	    Query query = queryManager.createQuery(filter);
-		return jcrMappingtemplate.getObjects(query);
-	}
-
-
-	public NewsService getNewsService()
-	{
-		return newsService;
-	}
-
-	public void setNewsService(NewsService newsService)
-	{
-		this.newsService = newsService;
-	}
-
-	/**
-     * @return Returns the template.
-     */
-    public JcrMappingTemplate getJcrMappingTemplate() {
-        return jcrMappingtemplate;
-    }
-
-    /**
-     * @param template The template to set.
-     */
-    public void setJcrMappingTemplate(JcrMappingTemplate template) {
-        this.jcrMappingtemplate = template;
-    }
-    
-    
-    
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.ocm.spring.test.components.impl;
+
+import java.util.Collection;
+import java.util.Date;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.ocm.query.Filter;
+import org.apache.jackrabbit.ocm.query.Query;
+import org.apache.jackrabbit.ocm.query.QueryManager;
+import org.apache.jackrabbit.ocm.spring.JcrMappingTemplate;
+import org.apache.jackrabbit.ocm.spring.exception.PersistenceException;
+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;
+
+/**
+ * Default implementation for {@link org.springmodules.jcr.jackrabbit.ocm.test.components.ArticleService}
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ *
+ */
+public class ArticleServiceImpl implements ArticleService {
+    private static final Log log = LogFactory.getLog(ArticleServiceImpl.class);
+
+    private JcrMappingTemplate jcrMappingtemplate;
+    private NewsService newsService;
+
+
+    public void createArticle(Article article)
+	{
+        jcrMappingtemplate.insert(article);
+        jcrMappingtemplate.save();
+
+        News news = new News();
+        news.setContent("A new article has been created by " + article.getAuthor());
+        news.setCreationDate(new Date());
+        news.setPath("/news-" + System.currentTimeMillis());
+        newsService.createNews(news);
+	}
+
+    public void createArticlesRollback(Article article)
+	{
+        jcrMappingtemplate.insert(article);
+        jcrMappingtemplate.save();
+
+        News news = new News();
+        news.setContent("A new article has been created by " + article.getAuthor());
+        news.setCreationDate(new Date());
+        news.setPath("/news-" + System.currentTimeMillis());
+        newsService.createNews(news);
+
+        throw new PersistenceException();
+
+	}
+
+    public Article getArticle(String path)
+    {
+    	return (Article) jcrMappingtemplate.getObject(path);
+    }
+
+	public Collection getArticles()
+	{
+
+		QueryManager queryManager = jcrMappingtemplate.createQueryManager();
+	    Filter filter = queryManager.createFilter(Article.class);
+
+	    Query query = queryManager.createQuery(filter);
+		return jcrMappingtemplate.getObjects(query);
+	}
+
+	public void deleteArticle(String path)
+    {
+    	jcrMappingtemplate.remove(path);
+    	jcrMappingtemplate.save();
+    }
+
+	public NewsService getNewsService()
+	{
+		return newsService;
+	}
+
+	public void setNewsService(NewsService newsService)
+	{
+		this.newsService = newsService;
+	}
+
+	/**
+     * @return Returns the template.
+     */
+    public JcrMappingTemplate getJcrMappingTemplate() {
+        return jcrMappingtemplate;
+    }
+
+    /**
+     * @param template The template to set.
+     */
+    public void setJcrMappingTemplate(JcrMappingTemplate template) {
+        this.jcrMappingtemplate = template;
+    }
+
+
+
+}

Modified: jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/impl/NewsServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/impl/NewsServiceImpl.java?rev=653575&r1=653574&r2=653575&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/impl/NewsServiceImpl.java (original)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/java/org/apache/jackrabbit/ocm/spring/test/components/impl/NewsServiceImpl.java Mon May  5 12:59:14 2008
@@ -1,75 +1,98 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jackrabbit.ocm.spring.test.components.impl;
-
-import java.util.Collection;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jackrabbit.ocm.query.Filter;
-import org.apache.jackrabbit.ocm.query.Query;
-import org.apache.jackrabbit.ocm.query.QueryManager;
-import org.apache.jackrabbit.ocm.spring.JcrMappingTemplate;
-import org.apache.jackrabbit.ocm.spring.test.components.NewsService;
-import org.apache.jackrabbit.ocm.spring.test.model.News;
-
-/**
- * Default implementation for {@link org.apache.jackrabbit.ocm.spring.test.components.ArticleService}
- * 
- * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
- *
- */
-public class NewsServiceImpl implements NewsService {
-    private static final Log log = LogFactory.getLog(NewsServiceImpl.class);
-
-    private JcrMappingTemplate jcrMappingtemplate;
-
-    public void createNews(News news)
-	{
-        jcrMappingtemplate.insert(news);
-        jcrMappingtemplate.save();
-	
-	}
-    
-	public Collection getNews()
-	{
-
-		QueryManager queryManager = jcrMappingtemplate.createQueryManager();
-	    Filter filter = queryManager.createFilter(News.class);
-	    
-	    Query query = queryManager.createQuery(filter);
-		return jcrMappingtemplate.getObjects(query);
-	}
-
-
-	/**
-     * @return Returns the template.
-     */
-    public JcrMappingTemplate getJcrMappingTemplate() {
-        return jcrMappingtemplate;
-    }
-
-    /**
-     * @param template The template to set.
-     */
-    public void setJcrMappingTemplate(JcrMappingTemplate template) {
-        this.jcrMappingtemplate = template;
-    }
-    
-    
-    
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.ocm.spring.test.components.impl;
+
+import java.util.Collection;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.ocm.exception.JcrMappingException;
+import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
+import org.apache.jackrabbit.ocm.query.Filter;
+import org.apache.jackrabbit.ocm.query.Query;
+import org.apache.jackrabbit.ocm.query.QueryManager;
+import org.apache.jackrabbit.ocm.spring.JcrMappingCallback;
+import org.apache.jackrabbit.ocm.spring.JcrMappingTemplate;
+import org.apache.jackrabbit.ocm.spring.test.components.NewsService;
+import org.apache.jackrabbit.ocm.spring.test.model.News;
+
+/**
+ * Default implementation for {@link org.springmodules.jcr.jackrabbit.ocm.test.components.ArticleService}
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe </a>
+ *
+ */
+public class NewsServiceImpl implements NewsService {
+    private static final Log log = LogFactory.getLog(NewsServiceImpl.class);
+
+    private JcrMappingTemplate jcrMappingtemplate;
+
+    public void createNews(News news)
+	{
+        jcrMappingtemplate.insert(news);
+        jcrMappingtemplate.save();
+
+	}
+
+	public Collection getNews()
+	{
+
+		QueryManager queryManager = jcrMappingtemplate.createQueryManager();
+	    Filter filter = queryManager.createFilter(News.class);
+
+	    Query query = queryManager.createQuery(filter);
+		return jcrMappingtemplate.getObjects(query);
+	}
+
+    public void deleteAllNews()
+    {
+    	jcrMappingtemplate.execute(new JcrMappingCallback()
+    	{
+
+			public Object doInJcrMapping(ObjectContentManager manager)
+					throws JcrMappingException {
+
+				QueryManager queryManager = manager.getQueryManager();
+				Filter filter = queryManager.createFilter(News.class);
+				Query query = queryManager.createQuery(filter);
+
+				manager.remove(query);
+				return null;
+			}
+
+    	}
+    	 );
+    	jcrMappingtemplate.save();
+    }
+
+	/**
+     * @return Returns the template.
+     */
+    public JcrMappingTemplate getJcrMappingTemplate() {
+        return jcrMappingtemplate;
+    }
+
+    /**
+     * @param template The template to set.
+     */
+    public void setJcrMappingTemplate(JcrMappingTemplate template) {
+        this.jcrMappingtemplate = template;
+    }
+
+
+
+}

Added: jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/resources/nodetypes/custom_nodetypes.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/resources/nodetypes/custom_nodetypes.xml?rev=653575&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/resources/nodetypes/custom_nodetypes.xml (added)
+++ jackrabbit/sandbox/jackrabbit-jcr-mapping/spring/src/test/resources/nodetypes/custom_nodetypes.xml Mon May  5 12:59:14 2008
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+<nodeTypes xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+	xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal"
+	xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
+	xmlns:test="http://www.apache.org/jackrabbit/test"
+	xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
+	xmlns:ocm="http://jackrabbit.apache.org/ocm"> 
+
+   <nodeType name="ocm:discriminator" isMixin="true">
+    <supertypes>
+      <supertype>nt:base</supertype>
+    </supertypes>
+    <propertyDefinition name="ocm:classname" requiredType="String" autoCreated="false" mandatory="true" onParentVersion="COPY" protected="false" multiple="false" />    
+  </nodeType>
+
+</nodeTypes>