JcrWorkspace implements org.modeshape.jcr.api.Workspace { @Override public void copy( String srcAbsPath, String destAbsPath ) throws ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException { CheckArg.isNotEmpty(srcAbsPath, "srcAbsPath"); CheckArg.isNotEmpty(destAbsPath, "destAbsPath"); session.checkLive(); this.copy(this.workspaceName, srcAbsPath, destAbsPath); } 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 shouldNotAllowCopyFromNullPathToNullPath() throws Exception { workspace.copy(null, null); }
@Test public void shouldCopyFromPathToAnotherPathInSameWorkspace() throws Exception { workspace.copy("/a/b", "/b/b-copy"); }
@Test @FixFor( "MODE-1972" ) public void shouldCopyEntireWorkspaces() throws Exception { otherWorkspace.copy(workspaceName, "/", "/"); assertNotNull(otherSession.getNode("/a")); assertNotNull(otherSession.getNode("/a/b")); assertNotNull(otherSession.getNode("/a/b/c")); assertNotNull(otherSession.getNode("/b")); }
@Test( expected = RepositoryException.class ) @FixFor( "MODE-1972" ) public void shouldNotCopyPartialWorkspaceIntoWorkspaceRoot() throws Exception { otherWorkspace.copy(workspaceName, "/a/b", "/"); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowCopyFromOtherWorkspaceWithNullWorkspace() throws Exception { workspace.copy(null, null, null); }
@Test @FixFor( "MODE-2012" ) public void copiedReferencesShouldPointToTargetWorkspace() 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.copy("default", "/", "/"); 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 copiedUUIDsShouldNotBeTheSame() 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.copy("default", "/", "/"); assertNotEquals(nodeA.getIdentifier(), otherSession.getNode("/A").getIdentifier()); assertNotEquals(nodeB.getIdentifier(), otherSession.getNode("/B").getIdentifier()); }
@Test @FixFor( "MODE-2114" ) public void copiedReferencesShouldHaveUpdatedUUIDs() throws Exception { tools.registerNodeTypes(session, "cnd/references.cnd"); Node parent = session.getRootNode().addNode("parent"); Node nodeA = parent.addNode("A", "test:node"); Node nodeB = parent.addNode("B", "test:node"); Node nodeC = parent.addNode("C", "test:node"); Node nodeD = parent.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(); workspace.copy("/parent", "/new_parent"); AbstractJcrNode otherA = session.getNode("/new_parent/A"); AbstractJcrNode otherB = session.getNode("/new_parent/B"); AbstractJcrNode otherC = session.getNode("/new_parent/C"); AbstractJcrNode otherD = session.getNode("/new_parent/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-2115" ) public void copiedNodesShouldReplaceAutoCreatedChildren() throws Exception { tools.registerNodeTypes(session, "cnd/autocreated-child-nodes.cnd"); Node parent = session.getRootNode().addNode("parent", "test:autocreatedFolders"); session.save(); long folder1CreatedTs = parent.getNode("folder1").getProperty("jcr:created").getDate().getTimeInMillis(); long folder2CreatedTs = parent.getNode("folder2").getProperty("jcr:created").getDate().getTimeInMillis(); workspace.copy("/parent", "/new_parent"); AbstractJcrNode newParent = session.getNode("/new_parent"); assertEquals(2, newParent.getNodes().getSize()); Node folder1Copy = assertNode("/new_parent/folder1", "nt:folder"); assertEquals(folder1CreatedTs, folder1Copy.getProperty("jcr:created").getDate().getTimeInMillis()); Node folder2Copy = assertNode("/new_parent/folder2", "nt:folder"); assertEquals(folder2CreatedTs, folder2Copy.getProperty("jcr:created").getDate().getTimeInMillis()); }
@Test @FixFor( "MODE-2115" ) public void copiedNodesShouldReplaceReferenceableAutoCreatedChildren() throws Exception { tools.registerNodeTypes(session, "cnd/autocreated-child-nodes.cnd"); session.getRootNode().addNode("parent", "test:autocreatedReferenceableChildren"); session.save(); session.getNode("/parent/child1").addNode("child1_1"); session.save(); workspace.copy("/parent", "/new_parent"); AbstractJcrNode newParent = session.getNode("/new_parent"); assertEquals(2, newParent.getNodes().getSize()); Node child1 = assertNode("/new_parent/child1", "test:subnodeReferenceable"); assertEquals(child1.getIdentifier(), child1.getProperty("jcr:uuid").getString()); Node child2 = assertNode("/new_parent/child2", "test:subnodeReferenceable"); assertEquals(child2.getIdentifier(), child2.getProperty("jcr:uuid").getString()); assertNode("/new_parent/child1/child1_1"); }
@Test @FixFor("MODE-2637") public void copyNodeWithEmptyMultiValueProperty() throws Exception { startRepositoryWithConfigurationFrom("config/repo-config-local-provider-and-nodetype-index.json"); session.getRootNode().addNode("a"); Node node = session.getNode("/a"); node.addMixin("mix:referenceable"); session.save(); node.removeMixin("mix:referenceable"); session.save(); assertTrue(node.hasProperty("jcr:mixinTypes")); assertThat(node.getProperty("jcr:mixinTypes").getValues().length, is(0)); session.getWorkspace().copy(session.getNode("/a").getPath(), "/a2"); session.save(); }