KickJava   Java API By Example, From Geeks To Geeks.

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


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: DocumentMoveTaskTest.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 import org.apache.lenya.cms.rc.RevisionController;
35
36
37 /**
38  * Class for testing the task to copy a document.
39  * Extend the AntTask class.
40   */

41 public class DocumentMoveTaskTest extends AntTaskTest {
42
43     private long time = 0;
44
45     /**
46      * Creates a new DocumentMoveTaskTest object.
47      *
48      * @param test the test
49      */

50     public DocumentMoveTaskTest(String JavaDoc test) {
51         super(test);
52     }
53
54     /**
55      * Creates a test suite.
56      * @return Test
57      **/

58     public static Test getSuite() {
59         return new TestSuite(DocumentMoveTaskTest.class);
60     }
61
62     /**
63      * The main program for the DocumentMoveTaskTest class
64      *
65      * @param args The command line arguments
66      */

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

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     /**
90      * Returns the target test.
91      * @return target.
92      */

93     protected String JavaDoc getTarget() {
94         return "moveDocument";
95     }
96
97     /**
98      * prepare the test
99      *
100      * @throws Exception if an error occurs
101      */

102     protected void prepareTest() throws Exception JavaDoc {
103         File JavaDoc publicationDirectory = PublicationHelper.getPublication().getDirectory();
104         String JavaDoc publicationPath = publicationDirectory.getAbsolutePath()+ File.separator;
105         File JavaDoc authoringDirectory = new File JavaDoc(publicationPath, AUTHORING_PATH);
106
107         // TODO generate the resources
108

109         // generate the rcml and rcbak files
110
File JavaDoc rcmlDirectory = new File JavaDoc(publicationPath , RCML_DIR);
111         File JavaDoc rcbakDirectory = new File JavaDoc(publicationPath , RCBAK_DIR);
112         RevisionController rc = new RevisionController(rcmlDirectory.getAbsolutePath(), rcbakDirectory.getAbsolutePath(), publicationPath);
113         String JavaDoc 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     /**
119      * evaluate the test
120      *
121      * @throws Exception if an error occurs
122      */

123     protected void evaluateTest() throws Exception JavaDoc {
124         File JavaDoc publicationDirectory = PublicationHelper.getPublication().getDirectory();
125         String JavaDoc publicationPath = publicationDirectory.getAbsolutePath();
126         File JavaDoc authoringDirectory = new File JavaDoc(publicationPath, AUTHORING_PATH);
127         
128         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(FIRST_DOCUMENT_ID , "/", true);
129         int l = st.countTokens();
130         for (int i=1; i<l; i++) {
131           st.nextToken();
132         }
133         String JavaDoc secdocumentid = SEC_DOCUMENT_ID+"/"+st.nextToken();
134         String JavaDoc filepath = secdocumentid + File.separator + "index.xml";
135
136         File JavaDoc documentFile = new File JavaDoc(authoringDirectory, filepath);
137         assertTrue(documentFile.exists());
138         System.out.println("Document was copied: " + documentFile.getAbsolutePath());
139         String JavaDoc firstfilepath = FIRST_DOCUMENT_ID + File.separator + "index.xml";
140         File JavaDoc firstdocumentFile = new File JavaDoc(authoringDirectory, firstfilepath);
141         assertFalse(firstdocumentFile.exists());
142         System.out.println("Document was deleted: " + firstdocumentFile.getAbsolutePath());
143
144         File JavaDoc rcmlDirectory = new File JavaDoc(publicationPath , RCML_DIR);
145         String JavaDoc rcmlFilePath = filepath+".rcml";
146         File JavaDoc rcmlFile = new File JavaDoc(rcmlDirectory , AUTHORING_PATH + rcmlFilePath);
147         assertTrue(rcmlFile.exists());
148         System.out.println("rcml file was copied: " + rcmlFile.getAbsolutePath());
149
150         String JavaDoc firstRcmlFilePath = firstfilepath+".rcml";
151         File JavaDoc firstRcmlFile = new File JavaDoc(rcmlDirectory , AUTHORING_PATH + firstRcmlFilePath);
152         assertFalse(firstRcmlFile.exists());
153         System.out.println("rcml file was deleted: " + firstRcmlFile.getAbsolutePath());
154
155         File JavaDoc rcbakDirectory = new File JavaDoc(publicationPath , RCBAK_DIR);
156         String JavaDoc rcbakFilePath= filepath +".bak." +time ;
157         File JavaDoc rcbakFile = new File JavaDoc(rcbakDirectory, AUTHORING_PATH + rcbakFilePath);
158         assertTrue(rcbakFile.exists());
159         System.out.println("Backup was copied: " + rcbakFile.getAbsolutePath());
160
161         String JavaDoc firstRcbakFilePath= firstfilepath +".bak." +time ;
162         File JavaDoc firstRcbakFile = new File JavaDoc(rcbakDirectory, AUTHORING_PATH + firstRcbakFilePath);
163         assertFalse(firstRcbakFile.exists());
164         System.out.println("Backup was deleted: " + firstRcbakFile.getAbsolutePath());
165         
166         //TODO evaluation of meta, workflow
167

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