jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r659644 - in /jackrabbit/trunk/jackrabbit-ocm/src: main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ test/java/org/apache/jackrabbit/ocm/ test/java/org/apache/jackrabbit/ocm/manager/version/ test/java/org/apache/jackrabbit/o...
Date Fri, 23 May 2008 19:54:10 GMT
Author: clombart
Date: Fri May 23 12:54:09 2008
New Revision: 659644

URL: http://svn.apache.org/viewvc?rev=659644&view=rev
Log:
Add fix and unit test for JCR-1448

Added:
    jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/version/
    jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/version/Author.java
    jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/version/PressRelease.java
Modified:
    jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java
    jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java
    jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/version/AnnotationBasicVersionningTest.java

Modified: jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java?rev=659644&r1=659643&r2=659644&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/main/java/org/apache/jackrabbit/ocm/manager/objectconverter/impl/ObjectConverterImpl.java
Fri May 23 12:54:09 2008
@@ -370,6 +370,7 @@
 
 			Node node = (Node) session.getItem(path);
 			if (!classDescriptor.isInterface()) {
+				node = getActualNode(session,node);
 				checkCompatiblePrimaryNodeTypes(session, node, classDescriptor, true);
 			}
 
@@ -870,4 +871,20 @@
 		return classDescriptor;
 	}
 
+	 private Node getActualNode(Session session, Node node) throws RepositoryException
+	 {
+		NodeType type = node.getPrimaryNodeType();
+		if (type.getName().equals("nt:versionedChild")) {
+
+			String uuid = node.getProperty("jcr:childVersionHistory").getValue().getString();
+			Node actualNode = session.getNodeByUUID(uuid);
+			String name = actualNode.getName();
+			actualNode = session.getNodeByUUID(name);
+
+			return actualNode;
+		}
+
+		return node;
+	}
+
 }

Modified: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java?rev=659644&r1=659643&r2=659644&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java
Fri May 23 12:54:09 2008
@@ -63,6 +63,8 @@
 import org.apache.jackrabbit.ocm.testmodel.interfaces.Document;
 import org.apache.jackrabbit.ocm.testmodel.interfaces.Folder;
 import org.apache.jackrabbit.ocm.testmodel.interfaces.Interface;
+import org.apache.jackrabbit.ocm.testmodel.version.Author;
+import org.apache.jackrabbit.ocm.testmodel.version.PressRelease;
 
 /**
  * Base class for testcases. Provides priviledged access to the jcr test
@@ -92,10 +94,10 @@
 
 	protected void initObjectContentManager() throws UnsupportedRepositoryOperationException,
javax.jcr.RepositoryException
 	{
-		Repository repository = RepositoryUtil.getRepository("repositoryTest");	
+		Repository repository = RepositoryUtil.getRepository("repositoryTest");
 		session = RepositoryUtil.login(repository, "superuser", "superuser");
 		List<Class> classes = new ArrayList<Class>();
-		
+
 		// Register content classes used by the unit tests
 		classes.add(Atomic.class);
 		classes.add(Default.class);
@@ -110,12 +112,12 @@
 		classes.add(Main.class);
 		classes.add(Element.class);
 		classes.add(MultiValue.class);
-		
+
 
 		classes.add(Residual.class);
 		classes.add(ResidualProperties.class);
 		classes.add(ResidualNodes.class);
-		
+
 		classes.add(CmsObject.class);
 		classes.add(Content.class);
 		classes.add(Document.class);
@@ -126,28 +128,28 @@
 		classes.add(DocumentExtImpl.class);
 		classes.add(DocumentStream.class);
 		classes.add(FolderImpl.class);
-		
+
 		classes.add(Ancestor.class);
 		classes.add(Descendant.class);
 		classes.add(AnotherDescendant.class);
 		classes.add(SubDescendant.class);
 		classes.add(Interface.class);
 		classes.add(AnotherInterface.class);
-		
+
 		classes.add(HierarchyNode.class);
 		classes.add(File.class);
 		classes.add(org.apache.jackrabbit.ocm.testmodel.Folder.class);
 		classes.add(Resource.class);
 		classes.add(PropertyTest.class);
-		
+
 		classes.add(Lockable.class);
-		
+
 		classes.add(org.apache.jackrabbit.ocm.testmodel.proxy.Main.class);
 		classes.add(org.apache.jackrabbit.ocm.testmodel.proxy.Detail.class);
-		
+
 		classes.add(org.apache.jackrabbit.ocm.testmodel.proxy.NTMain.class);
 		classes.add(org.apache.jackrabbit.ocm.testmodel.proxy.NTDetail.class);
-		
+
 		classes.add(org.apache.jackrabbit.ocm.testmodel.uuid.A.class);
 		classes.add(org.apache.jackrabbit.ocm.testmodel.uuid.B.class);
 		classes.add(org.apache.jackrabbit.ocm.testmodel.uuid.B2.class);
@@ -155,9 +157,12 @@
 		classes.add(org.apache.jackrabbit.ocm.testmodel.uuid.Descendant.class);
 		classes.add(org.apache.jackrabbit.ocm.testmodel.unstructured.UnstructuredParagraph.class);
 		classes.add(org.apache.jackrabbit.ocm.testmodel.unstructured.UnstructuredPage.class);
+
+		classes.add(PressRelease.class);
+		classes.add(Author.class);
 		Mapper mapper = new AnnotationMapperImpl(classes);
 		ocm = new ObjectContentManagerImpl(session, mapper);
-		
+
 	}
 
 

Modified: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/version/AnnotationBasicVersionningTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/version/AnnotationBasicVersionningTest.java?rev=659644&r1=659643&r2=659644&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/version/AnnotationBasicVersionningTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/manager/version/AnnotationBasicVersionningTest.java
Fri May 23 12:54:09 2008
@@ -31,6 +31,8 @@
 import org.apache.jackrabbit.ocm.testmodel.Paragraph;
 import org.apache.jackrabbit.ocm.testmodel.unstructured.UnstructuredPage;
 import org.apache.jackrabbit.ocm.testmodel.unstructured.UnstructuredParagraph;
+import org.apache.jackrabbit.ocm.testmodel.version.Author;
+import org.apache.jackrabbit.ocm.testmodel.version.PressRelease;
 import org.apache.jackrabbit.ocm.version.Version;
 import org.apache.jackrabbit.ocm.version.VersionIterator;
 
@@ -42,7 +44,7 @@
 public class AnnotationBasicVersionningTest extends AnnotationTestBase
 {
 	private final static Log log = LogFactory.getLog(AnnotationBasicVersionningTest.class);
-		
+
 	/**
 	 * <p>Defines the test case name for junit.</p>
 	 * @param testName The test case name.
@@ -50,7 +52,7 @@
 	public AnnotationBasicVersionningTest(String testName) throws Exception
 	{
 		super(testName);
-		
+
 	}
 
 	public static Test suite()
@@ -59,113 +61,113 @@
 		return new RepositoryLifecycleTestSetup(
                 new TestSuite(AnnotationBasicVersionningTest.class));
 	}
-	
+
 
 	public void testSimpleVersionWithNodeType()
 	{
 		     ObjectContentManager ocm = getObjectContentManager();
              try
              {
-            	
+
             	 Page page = new Page();
             	 page.setPath("/page");
-            	 page.setTitle("Page Title");            	
+            	 page.setTitle("Page Title");
             	 page.addParagraph(new Paragraph("para1"));
             	 page.addParagraph(new Paragraph("para2"));
             	 ocm.insert(page);
             	 ocm.save();
-            	
+
             	 page.addParagraph(new Paragraph("para3"));
             	 page.setTitle("Page Title 2");
             	 ocm.checkout("/page");
             	 ocm.update(page);
             	 ocm.save();
             	 ocm.checkin("/page");
-            	
+
             	 page.addParagraph(new Paragraph("para4"));
             	 page.setTitle("Page Title 3");
             	 ocm.checkout("/page");
             	 ocm.update(page);
             	 ocm.save();
-            	 ocm.checkin("/page");            	
+            	 ocm.checkin("/page");
 
             	 VersionIterator versionIterator = ocm.getAllVersions("/page");
             	 assertNotNull("VersionIterator is null", versionIterator);
             	 assertTrue("Invalid number of versions found", versionIterator.getSize() ==
3);
-            	
+
             	 while (versionIterator.hasNext())
             	 {
             		 Version version = (Version) versionIterator.next();
-            		 log.info("version found : "+ version.getName() + " - " + version.getPath()
+ " - " +  version.getCreated().getTime());            		 
+            		 log.info("version found : "+ version.getName() + " - " + version.getPath()
+ " - " +  version.getCreated().getTime());
             		 if (version.getName().equals("jcr:rootVersion"))
             		 {
-            			 continue; 
+            			 continue;
             		 }
-            		 
+
             		 page = (Page) ocm.getObject("/page", version.getName());
             		 assertNotNull("Page is null for version " + version.getName(), page);
-            		 
+
             		 if (version.getName().equals("1.0"))
             		 {
             			assertEquals("Invalid title for version " + version.getName(),page.getTitle(),
"Page Title 2");
             		 }
-            		 
+
             		 if (version.getName().equals("1.1"))
             		 {
-            			assertEquals("Invalid title for version " + version.getName(),page.getTitle(),
"Page Title 3"); 
-            		 } 
-            		 
+            			assertEquals("Invalid title for version " + version.getName(),page.getTitle(),
"Page Title 3");
+            		 }
+
             	 }
-            	
+
             	 Version baseVersion = ocm.getBaseVersion("/page");
             	 System.out.println("Base version : " + baseVersion.getName());
 
             	 Version rootVersion = ocm.getRootVersion("/page");
             	 System.out.println("Root version : " + rootVersion.getName());
             	 //this.exportDocument("/home/christophe/export.xml", "/jcr:system/jcr:versionStorage",
true, false);
-            	             	
+
                  //Get the latest version
             	 page = (Page) ocm.getObject( "/page");
             	 assertNotNull("Last version is nulll", page);
             	 assertTrue("Invalid number of paragraph found in the last  version", page.getParagraphs().size()
== 4);
 
-            	
+
              }
              catch(Exception e)
              {
             	 e.printStackTrace();
             	 fail(e.getMessage());
-            	
+
              }
 	}
 
-	
+
 	public void testVersionLabels()
 	{
 		     ObjectContentManager ocm = getObjectContentManager();
              try
              {
-            	
+
             	 Page page = new Page();
             	 page.setPath("/page");
-            	 page.setTitle("Page Title");            	
+            	 page.setTitle("Page Title");
             	 page.addParagraph(new Paragraph("para1"));
             	 page.addParagraph(new Paragraph("para2"));
             	 ocm.insert(page);
             	 ocm.save();
-            	
+
 
             	 page.addParagraph(new Paragraph("para3"));
             	 ocm.checkout("/page");
             	 ocm.update(page);
             	 ocm.save();
             	 ocm.checkin("/page", new String[] {"A", "B"});
-            	
+
             	 page.addParagraph(new Paragraph("para4"));
             	 ocm.checkout("/page");
             	 ocm.update(page);
             	 ocm.save();
-            	 ocm.checkin("/page", new String[] {"C", "D"});         	
+            	 ocm.checkin("/page", new String[] {"C", "D"});
 
             	 String[] allLabels = ocm.getAllVersionLabels("/page");
             	 assertTrue("Incorrect number of labels", allLabels.length == 4);
@@ -174,7 +176,7 @@
             	 assertTrue("Incorrect number of labels", versionLabels.length == 2);
             	 assertTrue("Incorrect label", versionLabels[0].equals("C") || versionLabels[0].equals("D"));
             	 assertTrue("Incorrect label", versionLabels[1].equals("C") || versionLabels[0].equals("D"));
-            	
+
 
              }
              catch(Exception e)
@@ -189,15 +191,15 @@
 		     ObjectContentManager ocm = getObjectContentManager();
              try
              {
-            	
+
             	 UnstructuredPage page = new UnstructuredPage();
             	 page.setPath("/page");
-            	 page.setTitle("Page Title");            	
+            	 page.setTitle("Page Title");
             	 page.addParagraph(new UnstructuredParagraph("para1"));
             	 page.addParagraph(new UnstructuredParagraph("para2"));
             	 ocm.insert(page);
             	 ocm.save();
-            	
+
 
             	 page.addParagraph(new UnstructuredParagraph("para3"));
             	 page.setTitle("Page Title 2");
@@ -205,63 +207,133 @@
             	 ocm.update(page);
             	 ocm.save();
             	 ocm.checkin("/page");
-            	
+
             	 page.addParagraph(new UnstructuredParagraph("para4"));
             	 page.setTitle("Page Title 3");
             	 ocm.checkout("/page");
             	 ocm.update(page);
             	 ocm.save();
-            	 ocm.checkin("/page");            	
+            	 ocm.checkin("/page");
 
             	 VersionIterator versionIterator = ocm.getAllVersions("/page");
             	 assertNotNull("VersionIterator is null", versionIterator);
             	 assertTrue("Invalid number of versions found", versionIterator.getSize() ==
3);
-            	
+
             	 while (versionIterator.hasNext())
             	 {
             		 Version version = (Version) versionIterator.next();
             		 log.info("version found : "+ version.getName() + " - " + version.getPath()
+ " - " +  version.getCreated().getTime());
             		 if (version.getName().equals("jcr:rootVersion"))
             		 {
-            			 continue; 
+            			 continue;
             		 }
-            		 
+
             		 page = (UnstructuredPage) ocm.getObject("/page", version.getName());
-            		 
+
             		 assertNotNull("Page is null for version " + version.getName(), page);
-            		 
+
             		 if (version.getName().equals("1.0"))
             		 {
             			assertEquals("Invalid title for version " + version.getName(),page.getTitle(),
"Page Title 2");
             		 }
-            		 
+
             		 if (version.getName().equals("1.1"))
             		 {
-            			assertEquals("Invalid title for version " + version.getName(),page.getTitle(),
"Page Title 3"); 
-            		 } 
+            			assertEquals("Invalid title for version " + version.getName(),page.getTitle(),
"Page Title 3");
+            		 }
 
             	 }
-            	
+
             	 Version baseVersion = ocm.getBaseVersion("/page");
             	 System.out.println("Base version : " + baseVersion.getName());
 
             	 Version rootVersion = ocm.getRootVersion("/page");
             	 System.out.println("Root version : " + rootVersion.getName());
             	 //this.exportDocument("/home/christophe/export.xml", "/jcr:system/jcr:versionStorage",
true, false);
-            	             	
+
                  //Get the latest version
             	 page = (UnstructuredPage) ocm.getObject( "/page");
             	 assertNotNull("Last version is nulll", page);
             	 assertTrue("Invalid number of paragraph found in the last  version", page.getParagraphs().size()
== 4);
 
-            	
+
              }
              catch(Exception e)
              {
             	 e.printStackTrace();
             	 fail(e.getMessage());
-            	
+
              }
 	}
-	
+
+	public void testVersionedChild() {
+		ObjectContentManager ocm = getObjectContentManager();
+		try {
+
+			PressRelease pressRelease = new PressRelease();
+			pressRelease.setContent("content v1");
+			pressRelease.setPath("/pressrelease1");
+			pressRelease.setPubDate(new Date());
+			pressRelease.setTitle("Title");
+
+			Author author = new Author();
+			author.setName("John");
+			pressRelease.setAuthor(author);
+			ocm.insert(pressRelease);
+			ocm.save();
+
+			pressRelease.setContent("content v2");
+			ocm.checkout("/pressrelease1");
+			ocm.update(pressRelease);
+			ocm.save();
+			ocm.checkin("/pressrelease1");
+
+			pressRelease.setContent("content v3");
+			ocm.checkout("/pressrelease1");
+			ocm.update(pressRelease);
+			ocm.save();
+			ocm.checkin("/pressrelease1");
+
+			VersionIterator versionIterator = ocm
+					.getAllVersions("/pressrelease1");
+			assertNotNull("VersionIterator is null", versionIterator);
+			assertTrue("Invalid number of versions found", versionIterator
+					.getSize() == 3);
+
+			while (versionIterator.hasNext()) {
+				Version version = (Version) versionIterator.next();
+				log.info("version found : " + version.getName() + " - "
+						+ version.getPath() + " - "
+						+ version.getCreated().getTime());
+				if (version.getName().equals("jcr:rootVersion")) {
+					continue;
+				}
+
+				pressRelease = (PressRelease) ocm.getObject("/pressrelease1",
+						version.getName());
+
+				assertNotNull("pressRelease is null for version "
+						+ version.getName(), pressRelease);
+
+				if (version.getName().equals("1.0")) {
+					assertEquals("Invalid content for version "
+							+ version.getName(), pressRelease.getContent(),
+							"content v2");
+				}
+
+				if (version.getName().equals("1.1")) {
+					assertEquals("Invalid title for version "
+							+ version.getName(), pressRelease.getContent(),
+							"content v3");
+				}
+
+			}
+
+		} catch (Exception e) {
+			e.printStackTrace();
+			fail(e.getMessage());
+
+		}
+	}
+
 }
\ No newline at end of file

Added: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/version/Author.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/version/Author.java?rev=659644&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/version/Author.java
(added)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/version/Author.java
Fri May 23 12:54:09 2008
@@ -0,0 +1,28 @@
+package org.apache.jackrabbit.ocm.testmodel.version;
+
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field;
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
+
+@Node(jcrMixinTypes = "mix:versionable")
+public class Author {
+
+	//@Field(path = true) String path;
+	@Field String name;
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+//	public String getPath() {
+//		return path;
+//	}
+//
+//	public void setPath(String path) {
+//		this.path = path;
+//	}
+
+}
\ No newline at end of file

Added: jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/version/PressRelease.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/version/PressRelease.java?rev=659644&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/version/PressRelease.java
(added)
+++ jackrabbit/trunk/jackrabbit-ocm/src/test/java/org/apache/jackrabbit/ocm/testmodel/version/PressRelease.java
Fri May 23 12:54:09 2008
@@ -0,0 +1,62 @@
+package org.apache.jackrabbit.ocm.testmodel.version;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Bean;
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Collection;
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field;
+import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
+import org.w3c.dom.Comment;
+
+@Node(jcrMixinTypes = "mix:versionable")
+public class PressRelease {
+	@Field(path = true) String path;
+	@Field String title;
+	@Field Date pubDate;
+	@Field String content;
+	@Bean Author author;
+
+
+	public String getPath() {
+		return path;
+	}
+
+	public void setPath(String path) {
+		this.path = path;
+	}
+
+	public String getContent() {
+		return content;
+	}
+
+	public void setContent(String content) {
+		this.content = content;
+	}
+
+	public Date getPubDate() {
+		return pubDate;
+	}
+
+	public void setPubDate(Date pubDate) {
+		this.pubDate = pubDate;
+	}
+
+	public String getTitle() {
+		return title;
+	}
+
+	public void setTitle(String title) {
+		this.title = title;
+	}
+
+	public Author getAuthor() {
+		return author;
+	}
+
+	public void setAuthor(Author author) {
+		this.author = author;
+	}
+
+}



Mime
View raw message