KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > task > DocumentCopyTaskTest


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: DocumentCopyTaskTest.java 160152 2005-04-05 09:59:45Z michi $ */
19
20 package org.apache.lenya.cms.task;
21
22 import java.io.File JavaDoc;
23 import java.util.StringTokenizer JavaDoc;
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 /**
37  * Class for testing the task to copy a document.
38  */

39 public class DocumentCopyTaskTest extends AntTaskTest {
40
41     /**
42      * Creates a new DocumentCopyTaskTest object.
43      * @param test the test
44      */

45     public DocumentCopyTaskTest(String JavaDoc test) {
46         super(test);
47     }
48
49     /**
50      * Creates a test suite.
51      * @return Test
52      **/

53     public static Test getSuite() {
54         return new TestSuite(DocumentCopyTaskTest.class);
55     }
56
57     /**
58      * The main program for the DocumentCopyTaskTest class
59      *
60      * @param args The command line arguments
61      */

62     public static void main(String JavaDoc[] args) {
63         AntTaskTest.initialize(args);
64         TestRunner.run(getSuite());
65     }
66
67     public static final String JavaDoc FIRST_DOCUMENT_ID = "/tutorial";
68     public static final String JavaDoc SEC_DOCUMENT_ID = "/features";
69     public static final String JavaDoc AUTHORING_PATH = "content/authoring".replace('/', File.separatorChar);
70     public static final String JavaDoc TREE_FILE = "sitetree.xml";
71     public static final String JavaDoc AUTHORING_RESOURCE = "resources/authoring";
72     public static final String JavaDoc RCML_DIR = "content/rcml";
73     public static final String JavaDoc RCBAK_DIR = "content/rcbak";
74     
75     /**
76      * @see org.apache.lenya.cms.task.AntTaskTest#getTaskParameters()
77      **/

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     /**
86      * Returns the target test.
87      * @return target.
88      */

89     protected String JavaDoc getTarget() {
90         return "copyDocument";
91     }
92
93     /**
94      * prepare the test
95      *
96      * @throws Exception if an error occurs
97      */

98     protected void prepareTest() throws Exception JavaDoc {
99         File JavaDoc publicationDirectory = PublicationHelper.getPublication().getDirectory();
100         String JavaDoc publicationPath = publicationDirectory.getAbsolutePath()+ File.separator;
101         File JavaDoc authoringDirectory = new File JavaDoc(publicationPath, AUTHORING_PATH);
102
103         // TODO generate the resources
104
}
105
106     /**
107      * evaluate the test
108      *
109      * @throws Exception if an error occurs
110      */

111     protected void evaluateTest() throws Exception JavaDoc {
112         File JavaDoc publicationDirectory = PublicationHelper.getPublication().getDirectory();
113         String JavaDoc publicationPath = publicationDirectory.getAbsolutePath();
114         File JavaDoc authoringDirectory = new File JavaDoc(publicationPath, AUTHORING_PATH);
115         
116         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(FIRST_DOCUMENT_ID , "/", true);
117         int l = st.countTokens();
118         for (int i=1; i<l; i++) {
119           st.nextToken();
120         }
121         String JavaDoc secdocumentid = SEC_DOCUMENT_ID+"/"+st.nextToken();
122
123         String JavaDoc filepath = secdocumentid + File.separator + "index.xml";
124
125         File JavaDoc documentFile = new File JavaDoc(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