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 40 public class DocumentRenameTaskTest extends AntTaskTest { 41 private long time = 0; 42 43 47 public DocumentRenameTaskTest(String test) { 48 super(test); 49 } 50 51 55 public static Test getSuite() { 56 return new TestSuite(DocumentRenameTaskTest.class); 57 } 58 59 64 public static void main(String [] args) { 65 AntTaskTest.initialize(args); 66 TestRunner.run(getSuite()); 67 } 68 69 public static final String FIRST_DOCUMENT_ID = "/doctypes/simple-document"; 70 public static final String SEC_DOCUMENT_ID = "newname"; 71 public static final String FIRST_AREA = "authoring"; 72 public static final String SEC_AREA = "authoring"; 73 public static final String AUTHORING_PATH = "content/authoring".replace('/', File.separatorChar); 74 public static final String AUTHORING_RESOURCE = "resources/authoring"; 75 public static final String RCML_DIR = "content/rcml"; 76 public static final String RCBAK_DIR = "content/rcbak"; 77 78 81 protected Parameters getTaskParameters() { 82 Parameters parameters = super.getTaskParameters(); 83 parameters.setParameter("properties.node.firstdocumentid", FIRST_DOCUMENT_ID); 84 parameters.setParameter("properties.node.secdocumentid", SEC_DOCUMENT_ID); 85 parameters.setParameter("properties.firstarea", FIRST_AREA); 86 parameters.setParameter("properties.secarea", SEC_AREA); 87 return parameters; 88 } 89 90 94 protected String getTarget() { 95 return "renameDocument"; 96 } 97 98 103 protected void prepareTest() throws Exception { 104 File publicationDirectory = PublicationHelper.getPublication().getDirectory(); 105 String publicationPath = publicationDirectory.getAbsolutePath()+ File.separator; 106 String filename = AUTHORING_PATH +FIRST_DOCUMENT_ID + File.separator + "index_de.xml"; 107 108 File rcmlDirectory = new File (publicationPath , RCML_DIR); 110 File rcbakDirectory = new File (publicationPath , RCBAK_DIR); 111 RevisionController rc = new RevisionController(rcmlDirectory.getAbsolutePath(), rcbakDirectory.getAbsolutePath(), publicationPath); 112 rc.reservedCheckOut(filename, "lenya"); 113 time = rc.reservedCheckIn(filename, "lenya", true); 114 115 } 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 , "/"); 129 int l = st.countTokens(); 130 String secdocumentid = ""; 131 for (int i=1; i<l; i++) { 132 secdocumentid= secdocumentid + "/" + st.nextToken(); 133 } 134 secdocumentid = secdocumentid + "/" + SEC_DOCUMENT_ID; 135 System.out.println("the second document id" + secdocumentid); 136 137 String filepath = secdocumentid + File.separator + "index_de.xml"; 138 String en_filepath = secdocumentid + File.separator + "index_en.xml"; 139 String firstfilepath = FIRST_DOCUMENT_ID + File.separator + "index_de.xml"; 140 String firsten_filepath = FIRST_DOCUMENT_ID + File.separator + "index_en.xml"; 141 142 File documentFile = new File (authoringDirectory, filepath); 144 assertTrue(documentFile.exists()); 145 System.out.println("Document was copied: " + documentFile.getAbsolutePath()); 146 File en_documentFile = new File (authoringDirectory, en_filepath); 147 assertTrue(en_documentFile.exists()); 148 System.out.println("Document was copied: " + en_documentFile.getAbsolutePath()); 149 File firstdocumentFile = new File (authoringDirectory, firstfilepath); 150 assertFalse(firstdocumentFile.exists()); 151 System.out.println("Document was deleted: " + firstdocumentFile.getAbsolutePath()); 152 File firsten_documentFile = new File (authoringDirectory, firsten_filepath); 153 assertFalse(firsten_documentFile.exists()); 154 System.out.println("Document was deleted: " + firsten_documentFile.getAbsolutePath()); 155 156 File rcmlDirectory = new File (publicationPath , RCML_DIR); 158 String rcmlFilePath = filepath+".rcml"; 159 File rcmlFile = new File (rcmlDirectory , AUTHORING_PATH + rcmlFilePath); 160 assertTrue(rcmlFile.exists()); 161 System.out.println("rcml file was copied: " + rcmlFile.getAbsolutePath()); 162 163 String firstRcmlFilePath = firstfilepath+".rcml"; 164 File firstRcmlFile = new File (rcmlDirectory , AUTHORING_PATH + firstRcmlFilePath); 165 assertFalse(firstRcmlFile.exists()); 166 System.out.println("rcml file was deleted: " + firstRcmlFile.getAbsolutePath()); 167 168 File rcbakDirectory = new File (publicationPath , RCBAK_DIR); 170 String rcbakFilePath= filepath +".bak." +time ; 171 File rcbakFile = new File (rcbakDirectory, AUTHORING_PATH + rcbakFilePath); 172 assertTrue(rcbakFile.exists()); 173 System.out.println("Backup was copied: " + rcbakFile.getAbsolutePath()); 174 175 String firstRcbakFilePath= firstfilepath +".bak." +time ; 176 File firstRcbakFile = new File (rcbakDirectory, AUTHORING_PATH + firstRcbakFilePath); 177 assertFalse(firstRcbakFile.exists()); 178 System.out.println("Backup was deleted: " + firstRcbakFile.getAbsolutePath()); 179 180 182 SiteTree sitetree = PublicationHelper.getPublication().getTree(Publication.AUTHORING_AREA); 184 SiteTreeNode node = sitetree.getNode(secdocumentid); 185 assertNotNull(node); 186 System.out.println( 187 "Sitetree node with id " 188 + node.getId() 189 + " was created as child of node with id: " 190 + node.getAbsoluteParentId()); 191 SiteTreeNode firstnode = sitetree.getNode(FIRST_DOCUMENT_ID); 192 assertNull(firstnode); 193 System.out.println("Sitetree node for document id "+FIRST_DOCUMENT_ID+" was deleted"); 194 195 } 196 } 197 | Popular Tags |