Author: skabashnyuk
Date: 2009-10-15 10:56:47 -0400 (Thu, 15 Oct 2009)
New Revision: 284
Modified:
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/util/VersionHistoryImporter.java
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/api/importing/TestImport.java
Log:
EXOJCR-189 : Versioning is not working well with nt:file. Test and fix
Modified:
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/util/VersionHistoryImporter.java
===================================================================
---
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/util/VersionHistoryImporter.java 2009-10-15
14:31:25 UTC (rev 283)
+++
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/util/VersionHistoryImporter.java 2009-10-15
14:56:47 UTC (rev 284)
@@ -173,7 +173,7 @@
// remove version history
dataKeeper.save(changesLog);
// import new version history
- userSession.importXML(path, versionHistoryStream, 0);
+ userSession.getWorkspace().importXML(path, versionHistoryStream, 0);
userSession.save();
}
Modified:
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/api/importing/TestImport.java
===================================================================
---
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/api/importing/TestImport.java 2009-10-15
14:31:25 UTC (rev 283)
+++
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/api/importing/TestImport.java 2009-10-15
14:56:47 UTC (rev 284)
@@ -511,6 +511,69 @@
}
/**
+ * Test for
http://jira.exoplatform.org/browse/JCR-1247
+ *
+ * @throws Exception
+ */
+ public void testJCR1247() throws Exception
+ {
+
+ Node testRoot = root.addNode("testRoot");
+ Node fileNode = testRoot.addNode("TestJCR1247", "nt:file");
+ Node contentNode = fileNode.addNode("jcr:content",
"nt:resource");
+ contentNode.setProperty("jcr:data", new
ByteArrayInputStream("".getBytes()));
+ contentNode.setProperty("jcr:mimeType", "image/jpg");
+ contentNode.setProperty("jcr:lastModified", Calendar.getInstance());
+ session.save();
+ Node contentNodeBeforeAddVersion = fileNode.getNode("jcr:content");
+
assertNotNull(contentNodeBeforeAddVersion.getProperty("jcr:lastModified"));
+ if (fileNode.canAddMixin("mix:versionable"))
+ {
+ fileNode.addMixin("mix:versionable");
+ }
+ fileNode.save();
+ fileNode.checkin();
+ fileNode.checkout();
+ session.save();
+
+ String nodeDump = dumpVersionable(fileNode);
+ // Export VersionHistory
+
+ assertTrue(fileNode.isNodeType("mix:versionable"));
+
+ VersionableNodeInfo nodeInfo = new VersionableNodeInfo(fileNode);
+
+ // node content
+ byte[] versionableNode = serialize(fileNode, false, true);
+ // version history
+ byte[] versionHistory = serialize(fileNode.getVersionHistory(), false, true);
+ System.out.println(new String(versionHistory));
+ fileNode.remove();
+ session.save();
+ assertFalse(testRoot.hasNode("TestJCR1247"));
+
+ // restore node content
+ deserialize(testRoot, XmlSaveType.SESSION, true,
ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW,
+ new ByteArrayInputStream(versionableNode));
+ session.save();
+
+ assertTrue(testRoot.hasNode("TestJCR1247"));
+
+ Node fileImport = testRoot.getNode("TestJCR1247");
+ assertTrue(fileImport.isNodeType("mix:versionable"));
+
+ VersionHistoryImporter versionHistoryImporter =
+ new VersionHistoryImporter((NodeImpl)fileImport, new
ByteArrayInputStream(versionHistory), nodeInfo
+ .getBaseVersion(), nodeInfo.getPredecessorsHistory(),
nodeInfo.getVersionHistory());
+ versionHistoryImporter.doImport();
+ fileImport.checkin();
+ fileImport.checkout();
+ session.save();
+ // assertEquals(nodeDump, dumpVersionable(fileImport));
+
+ }
+
+ /**
* Test for
http://jira.exoplatform.org/browse/JCR-1047
*
* @throws Exception