1 17 18 19 20 package org.apache.lenya.cms.task; 21 22 import java.io.File ; 23 import java.util.StringTokenizer ; 24 25 import junit.framework.Test; 26 import junit.framework.TestSuite; 27 import junit.textui.TestRunner; 28 29 import org.apache.avalon.framework.parameters.Parameters; 30 import org.apache.lenya.cms.PublicationHelper; 31 import org.apache.lenya.cms.publication.Publication; 32 import org.apache.lenya.cms.publication.SiteTree; 33 import org.apache.lenya.cms.publication.SiteTreeNode; 34 import org.apache.lenya.cms.rc.RevisionController; 35 36 37 41 public class DocumentMoveTaskTest extends AntTaskTest { 42 43 private long time = 0; 44 45 50 public DocumentMoveTaskTest(String test) { 51 super(test); 52 } 53 54 58 public static Test getSuite() { 59 return new TestSuite(DocumentMoveTaskTest.class); 60 } 61 62 67 public static void main(String [] args) { 68 AntTaskTest.initialize(args); 69 TestRunner.run(getSuite()); 70 } 71 72 public static final String FIRST_DOCUMENT_ID = "/concepts"; 73 public static final String SEC_DOCUMENT_ID = "/features"; 74 public static final String AUTHORING_PATH = "content/authoring".replace('/', File.separatorChar); 75 public static final String AUTHORING_RESOURCE = "resources/authoring"; 76 public static final String RCML_DIR = "content/rcml"; 77 public static final String RCBAK_DIR = "content/rcbak"; 78 79 82 protected Parameters getTaskParameters() { 83 Parameters parameters = super.getTaskParameters(); 84 parameters.setParameter("properties.node.firstdocumentid", FIRST_DOCUMENT_ID); 85 parameters.setParameter("properties.node.secdocumentid", SEC_DOCUMENT_ID); 86 return parameters; 87 } 88 89 93 protected String getTarget() { 94 return "moveDocument"; 95 } 96 97 102 protected void prepareTest() throws Exception { 103 File publicationDirectory = PublicationHelper.getPublication().getDirectory(); 104 String publicationPath = publicationDirectory.getAbsolutePath()+ File.separator; 105 File authoringDirectory = new File (publicationPath, AUTHORING_PATH); 106 107 109 File rcmlDirectory = new File (publicationPath , RCML_DIR); 111 File rcbakDirectory = new File (publicationPath , RCBAK_DIR); 112 RevisionController rc = new RevisionController(rcmlDirectory.getAbsolutePath(), rcbakDirectory.getAbsolutePath(), publicationPath); 113 String filename = AUTHORING_PATH +FIRST_DOCUMENT_ID + File.separator + "index.xml"; 114 rc.reservedCheckOut(filename, "lenya"); 115 time = rc.reservedCheckIn(filename, "lenya", true); 116 } 117 118 123 protected void evaluateTest() throws Exception { 124 File publicationDirectory = PublicationHelper.getPublication().getDirectory(); 125 String publicationPath = publicationDirectory.getAbsolutePath(); 126 File authoringDirectory = new File (publicationPath, AUTHORING_PATH); 127 128 StringTokenizer st = new StringTokenizer (FIRST_DOCUMENT_ID , "/", true); 129 int l = st.countTokens(); 130 for (int i=1; i<l; i++) { 131 st.nextToken(); 132 } 133 String secdocumentid = SEC_DOCUMENT_ID+"/"+st.nextToken(); 134 String filepath = secdocumentid + File.separator + "index.xml"; 135 136 File documentFile = new File (authoringDirectory, filepath); 137 assertTrue(documentFile.exists()); 138 System.out.println("Document was copied: " + documentFile.getAbsolutePath()); 139 String firstfilepath = FIRST_DOCUMENT_ID + File.separator + "index.xml"; 140 File firstdocumentFile = new File (authoringDirectory, firstfilepath); 141 assertFalse(firstdocumentFile.exists()); 142 System.out.println("Document was deleted: " + firstdocumentFile.getAbsolutePath()); 143 144 File rcmlDirectory = new File (publicationPath , RCML_DIR); 145 String rcmlFilePath = filepath+".rcml"; 146 File rcmlFile = new File (rcmlDirectory , AUTHORING_PATH + rcmlFilePath); 147 assertTrue(rcmlFile.exists()); 148 System.out.println("rcml file was copied: " + rcmlFile.getAbsolutePath()); 149 150 String firstRcmlFilePath = firstfilepath+".rcml"; 151 File firstRcmlFile = new File (rcmlDirectory , AUTHORING_PATH + firstRcmlFilePath); 152 assertFalse(firstRcmlFile.exists()); 153 System.out.println("rcml file was deleted: " + firstRcmlFile.getAbsolutePath()); 154 155 File rcbakDirectory = new File (publicationPath , RCBAK_DIR); 156 String rcbakFilePath= filepath +".bak." +time ; 157 File rcbakFile = new File (rcbakDirectory, AUTHORING_PATH + rcbakFilePath); 158 assertTrue(rcbakFile.exists()); 159 System.out.println("Backup was copied: " + rcbakFile.getAbsolutePath()); 160 161 String firstRcbakFilePath= firstfilepath +".bak." +time ; 162 File firstRcbakFile = new File (rcbakDirectory, AUTHORING_PATH + firstRcbakFilePath); 163 assertFalse(firstRcbakFile.exists()); 164 System.out.println("Backup was deleted: " + firstRcbakFile.getAbsolutePath()); 165 166 168 SiteTree sitetree = PublicationHelper.getPublication().getTree(Publication.AUTHORING_AREA); 169 SiteTreeNode node = sitetree.getNode(secdocumentid); 170 assertNotNull(node); 171 System.out.println("Sitetree node with id "+node.getId()+" was created as child of node with id: " + node.getAbsoluteParentId()); 172 SiteTreeNode firstnode = sitetree.getNode(FIRST_DOCUMENT_ID); 173 assertNull(firstnode); 174 System.out.println("Sitetree node for document id "+FIRST_DOCUMENT_ID+" was deleted"); 175 } 176 } 177 | Popular Tags |