JcrWorkspace implements org.modeshape.jcr.api.Workspace { @Override public void clone( String srcWorkspace, String srcAbsPath, String destAbsPath, boolean removeExisting ) throws NoSuchWorkspaceException, ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException { internalClone(srcWorkspace, srcAbsPath, destAbsPath, removeExisting, false); } JcrWorkspace( JcrSession session,
                  String workspaceName ); @Override final JcrSession getSession(); @Override final String getName(); @Override void copy( String srcAbsPath,
                      String destAbsPath ); @Override void copy( String srcWorkspace,
                      String srcAbsPath,
                      String destAbsPath ); @Override void clone( String srcWorkspace,
                       String srcAbsPath,
                       String destAbsPath,
                       boolean removeExisting ); @Override void move( String srcAbsPath,
                      String destAbsPath ); @Override @SuppressWarnings("deprecation") void restore( Version[] versions,
                         boolean removeExisting ); @Override JcrLockManager getLockManager(); @Override JcrQueryManager getQueryManager(); @Override javax.jcr.NamespaceRegistry getNamespaceRegistry(); @Override IndexManager getIndexManager(); @Override JcrNodeTypeManager getNodeTypeManager(); @Override ObservationManager getObservationManager(); @Override JcrVersionManager getVersionManager(); @Override JcrRepositoryManager getRepositoryManager(); @Override ContentHandler getImportContentHandler( String parentAbsPath,
                                                   int uuidBehavior ); @Override void importXML( String parentAbsPath,
                           InputStream in,
                           int uuidBehavior ); @Override String[] getAccessibleWorkspaceNames(); @Override void createWorkspace( String name ); @Override void createWorkspace( String name,
                                 String srcWorkspace ); @Override void deleteWorkspace( String name ); @Override void reindex(); @Override void reindex( String pathStr ); @Override void reindexSince( long timestamp ); @Override Future<Boolean> reindexSinceAsync( long timestamp ); @Override Future<Boolean> reindexAsync(); @Override Future<Boolean> reindexAsync( String pathStr ); @Override FederationManager getFederationManager();  }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowCloneWithNullWorkspaceName() throws Exception { workspace.clone(null, "/src", "/dest", false); }
@Test @FixFor( "MODE-1972" ) public void shouldCloneEntireWorkspaces() throws Exception { otherWorkspace.clone(workspaceName, "/", "/", true); assertEquals(session.getNode("/a").getIdentifier(), otherSession.getNode("/a").getIdentifier()); assertEquals(session.getNode("/a/b").getIdentifier(), otherSession.getNode("/a/b").getIdentifier()); assertEquals(session.getNode("/a/b/c").getIdentifier(), otherSession.getNode("/a/b/c").getIdentifier()); assertEquals(session.getNode("/b").getIdentifier(), otherSession.getNode("/b").getIdentifier()); }
@Test( expected = RepositoryException.class ) @FixFor( "MODE-1972" ) public void shouldNotClonePartialWorkspaceIntoWorkspaceRoot() throws Exception { otherWorkspace.clone(workspaceName, "/a/b", "/", false); }
@Test @FixFor( "MODE-2007" ) public void shouldCloneChildrenOfRoot() throws Exception { otherWorkspace.clone(workspaceName, "/a", "/a", false); otherWorkspace.clone(workspaceName, "/b", "/b", false); assertEquals(session.getNode("/a").getIdentifier(), otherSession.getNode("/a").getIdentifier()); assertEquals(session.getNode("/a/b").getIdentifier(), otherSession.getNode("/a/b").getIdentifier()); assertEquals(session.getNode("/a/b/c").getIdentifier(), otherSession.getNode("/a/b/c").getIdentifier()); assertEquals(session.getNode("/b").getIdentifier(), otherSession.getNode("/b").getIdentifier()); }
@Test @FixFor( "MODE-2012" ) public void clonedReferencesShouldPointToTargetWorkspace() throws Exception { tools.registerNodeTypes(session, "cnd/references.cnd"); Node nodeA = session.getRootNode().addNode("A", "test:node"); Node nodeB = session.getRootNode().addNode("B", "test:node"); Node nodeC = session.getRootNode().addNode("C", "test:node"); Node nodeD = session.getRootNode().addNode("D", "test:node"); nodeA.setProperty("test:strongReference", session.getValueFactory().createValue(nodeB)); nodeA.setProperty("test:weakReference", session.getValueFactory().createValue(nodeC, true)); nodeA.setProperty("test:simpleReference", session.getValueFactory().createSimpleReference(nodeD)); session.save(); otherWorkspace.clone("default", "/", "/", true); nodeD.remove(); nodeC.remove(); nodeB.remove(); nodeA.remove(); session.save(); AbstractJcrNode otherA = otherSession.getNode("/A"); AbstractJcrNode otherB = otherSession.getNode("/B"); AbstractJcrNode otherC = otherSession.getNode("/C"); AbstractJcrNode otherD = otherSession.getNode("/D"); assertEquals(otherB.getIdentifier(), otherA.getProperty("test:strongReference").getNode().getIdentifier()); assertEquals(otherC.getIdentifier(), otherA.getProperty("test:weakReference").getNode().getIdentifier()); assertEquals(otherD.getIdentifier(), otherA.getProperty("test:simpleReference").getNode().getIdentifier()); }
@Test @FixFor( "MODE-2012" ) public void clonedUUIDsShouldBeTheSame() throws Exception { tools.registerNodeTypes(session, "cnd/references.cnd"); Node nodeA = session.getRootNode().addNode("A", "test:node"); Node nodeB = session.getRootNode().addNode("B", "test:node"); session.save(); otherWorkspace.clone("default", "/", "/", true); assertEquals(nodeA.getIdentifier(), otherSession.getNode("/A").getIdentifier()); assertEquals(nodeB.getIdentifier(), otherSession.getNode("/B").getIdentifier()); }
@Test @FixFor( "MODE-2115" ) public void clonedNodesWithAutoCreatedChildrenShouldPreserveIdentifiers() throws Exception { tools.registerNodeTypes(session, "cnd/autocreated-child-nodes.cnd"); Node parent = session.getRootNode().addNode("parent", "test:autocreatedFolders"); session.save(); Node folder1 = parent.getNode("folder1"); long folder1CreatedTs = folder1.getProperty("jcr:created").getDate().getTimeInMillis(); Node folder2 = parent.getNode("folder2"); long folder2CreatedTs = folder2.getProperty("jcr:created").getDate().getTimeInMillis(); otherWorkspace.clone(workspaceName, "/parent", "/parent", true); AbstractJcrNode otherParent = otherSession.getNode("/parent"); assertEquals(2, otherParent.getNodes().getSize()); Node otherFolder1 = otherSession.getNode("/parent/folder1"); assertEquals(folder1CreatedTs, otherFolder1.getProperty("jcr:created").getDate().getTimeInMillis()); assertEquals(folder1.getIdentifier(), otherFolder1.getIdentifier()); Node otherFolder2 = otherSession.getNode("/parent/folder2"); assertEquals(folder2.getIdentifier(), otherFolder2.getIdentifier()); assertEquals(folder2CreatedTs, otherFolder2.getProperty("jcr:created").getDate().getTimeInMillis()); }