public void testBasicRenameContentAndMove() throws Exception { startNewTransaction(); TransferManifestNormalNode node = null; try { String transferId = ftTransferReceiver.start("1234", true, ftTransferReceiver.getVersion()); try { // get back the node in the list node = (TransferManifestNormalNode) staticNodes.get(0); // modify the node name node.getProperties().put(ContentModel.PROP_NAME, "New_Name.txt"); // create a folder TransferManifestNormalNode folderNode = this.createFolderNode(companytHome, "FOLDER_1"); staticNodes.add(folderNode); // modify the parent modifyParentNode(folderNode.getNodeRef(), node); // set the root // NodeRef parentRef = node.getPrimaryParentAssoc().getParentRef(); String snapshot = createSnapshot(staticNodes, false); ftTransferReceiver.setFileTransferRootNodeFileFileSystem(this.companytHome.toString()); ftTransferReceiver.saveSnapshot( transferId, new ByteArrayInputStream(snapshot.getBytes("UTF-8"))); ftTransferReceiver.commit(transferId); } catch (Exception ex) { ftTransferReceiver.end(transferId); throw ex; } } finally { endTransaction(); } // check that the temporary folder where orphan are put in do not exist anymore File tempFolder = new File(ftTransferReceiver.getDefaultReceivingroot() + "/" + "T_V_R_1234432123478"); assertFalse(tempFolder.exists()); // check that content exist // get the name of the node String nodeName = (String) node.getProperties().get(ContentModel.PROP_NAME); File transferedNode = new File(ftTransferReceiver.getDefaultReceivingroot() + "/" + "FOLDER_1" + "/" + nodeName); assertTrue(transferedNode.exists()); // check content itself byte byteArray[] = readBytesFromFile(transferedNode); // transform to string ByteArrayOutputStream bs = new ByteArrayOutputStream(); bs.write(byteArray, 0, byteArray.length); String content = bs.toString(); assertEquals(content, dummyContent); }
/** @return */ private void modifyParentNode(NodeRef parentFolder, TransferManifestNormalNode nodeToMove) throws Exception { String nodeName = (String) nodeToMove.getProperties().get(ContentModel.PROP_NAME); List<ChildAssociationRef> parents = new ArrayList<ChildAssociationRef>(); ChildAssociationRef primaryAssoc = new ChildAssociationRef( ContentModel.ASSOC_CONTAINS, parentFolder, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeName), nodeToMove.getNodeRef(), true, -1); parents.add(primaryAssoc); nodeToMove.setParentAssocs(parents); nodeToMove.setParentPath(null); nodeToMove.setPrimaryParentAssoc(primaryAssoc); }