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 35 36 39 public class DocumentCopyTaskTest extends AntTaskTest { 40 41 45 public DocumentCopyTaskTest(String test) { 46 super(test); 47 } 48 49 53 public static Test getSuite() { 54 return new TestSuite(DocumentCopyTaskTest.class); 55 } 56 57 62 public static void main(String [] args) { 63 AntTaskTest.initialize(args); 64 TestRunner.run(getSuite()); 65 } 66 67 public static final String FIRST_DOCUMENT_ID = "/tutorial"; 68 public static final String SEC_DOCUMENT_ID = "/features"; 69 public static final String AUTHORING_PATH = "content/authoring".replace('/', File.separatorChar); 70 public static final String TREE_FILE = "sitetree.xml"; 71 public static final String AUTHORING_RESOURCE = "resources/authoring"; 72 public static final String RCML_DIR = "content/rcml"; 73 public static final String RCBAK_DIR = "content/rcbak"; 74 75 78 protected Parameters getTaskParameters() { 79 Parameters parameters = super.getTaskParameters(); 80 parameters.setParameter("properties.node.firstdocumentid", FIRST_DOCUMENT_ID); 81 parameters.setParameter("properties.node.secdocumentid", SEC_DOCUMENT_ID); 82 return parameters; 83 } 84 85 89 protected String getTarget() { 90 return "copyDocument"; 91 } 92 93 98 protected void prepareTest() throws Exception { 99 File publicationDirectory = PublicationHelper.getPublication().getDirectory(); 100 String publicationPath = publicationDirectory.getAbsolutePath()+ File.separator; 101 File authoringDirectory = new File (publicationPath, AUTHORING_PATH); 102 103 } 105 106 111 protected void evaluateTest() throws Exception { 112 File publicationDirectory = PublicationHelper.getPublication().getDirectory(); 113 String publicationPath = publicationDirectory.getAbsolutePath(); 114 File authoringDirectory = new File (publicationPath, AUTHORING_PATH); 115 116 StringTokenizer st = new StringTokenizer (FIRST_DOCUMENT_ID , "/", true); 117 int l = st.countTokens(); 118 for (int i=1; i<l; i++) { 119 st.nextToken(); 120 } 121 String secdocumentid = SEC_DOCUMENT_ID+"/"+st.nextToken(); 122 123 String filepath = secdocumentid + File.separator + "index.xml"; 124 125 File documentFile = new File (authoringDirectory, filepath); 126 assertTrue(documentFile.exists()); 127 System.out.println("Document was copied: " + documentFile.getAbsolutePath()); 128 129 SiteTree sitetree = PublicationHelper.getPublication().getTree(Publication.AUTHORING_AREA); 130 SiteTreeNode node = sitetree.getNode(secdocumentid); 131 assertNotNull(node); 132 System.out.println("Sitetree node with id " + node.getId() + 133 " was created as child of node with id: " + node.getAbsoluteParentId()); 134 } 135 } 136 | Popular Tags |