KickJava   Java API By Example, From Geeks To Geeks.

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


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: DocumentRenameTaskTest.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 rename a document.
39  */

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

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

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

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

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

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

103     protected void prepareTest() throws Exception JavaDoc {
104         File JavaDoc publicationDirectory = PublicationHelper.getPublication().getDirectory();
105         String JavaDoc publicationPath = publicationDirectory.getAbsolutePath()+ File.separator;
106         String JavaDoc filename = AUTHORING_PATH +FIRST_DOCUMENT_ID + File.separator + "index_de.xml";
107         
108         // generate the rcml and rcbak files
109
File JavaDoc rcmlDirectory = new File JavaDoc(publicationPath , RCML_DIR);
110         File JavaDoc rcbakDirectory = new File JavaDoc(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         // TODO generate the workflow, meta
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 , "/");
129         int l = st.countTokens();
130         String JavaDoc 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 JavaDoc filepath = secdocumentid + File.separator + "index_de.xml";
138         String JavaDoc en_filepath = secdocumentid + File.separator + "index_en.xml";
139         String JavaDoc firstfilepath = FIRST_DOCUMENT_ID + File.separator + "index_de.xml";
140         String JavaDoc firsten_filepath = FIRST_DOCUMENT_ID + File.separator + "index_en.xml";
141
142         //evaluate the file
143
File JavaDoc documentFile = new File JavaDoc(authoringDirectory, filepath);
144         assertTrue(documentFile.exists());
145         System.out.println("Document was copied: " + documentFile.getAbsolutePath());
146         File JavaDoc en_documentFile = new File JavaDoc(authoringDirectory, en_filepath);
147         assertTrue(en_documentFile.exists());
148         System.out.println("Document was copied: " + en_documentFile.getAbsolutePath());
149         File JavaDoc firstdocumentFile = new File JavaDoc(authoringDirectory, firstfilepath);
150         assertFalse(firstdocumentFile.exists());
151         System.out.println("Document was deleted: " + firstdocumentFile.getAbsolutePath());
152         File JavaDoc firsten_documentFile = new File JavaDoc(authoringDirectory, firsten_filepath);
153         assertFalse(firsten_documentFile.exists());
154         System.out.println("Document was deleted: " + firsten_documentFile.getAbsolutePath());
155
156         //evaluate the rcml
157
File JavaDoc rcmlDirectory = new File JavaDoc(publicationPath , RCML_DIR);
158         String JavaDoc rcmlFilePath = filepath+".rcml";
159         File JavaDoc rcmlFile = new File JavaDoc(rcmlDirectory , AUTHORING_PATH + rcmlFilePath);
160         assertTrue(rcmlFile.exists());
161         System.out.println("rcml file was copied: " + rcmlFile.getAbsolutePath());
162
163         String JavaDoc firstRcmlFilePath = firstfilepath+".rcml";
164         File JavaDoc firstRcmlFile = new File JavaDoc(rcmlDirectory , AUTHORING_PATH + firstRcmlFilePath);
165         assertFalse(firstRcmlFile.exists());
166         System.out.println("rcml file was deleted: " + firstRcmlFile.getAbsolutePath());
167
168         //evaluate the backup
169
File JavaDoc rcbakDirectory = new File JavaDoc(publicationPath , RCBAK_DIR);
170         String JavaDoc rcbakFilePath= filepath +".bak." +time ;
171         File JavaDoc rcbakFile = new File JavaDoc(rcbakDirectory, AUTHORING_PATH + rcbakFilePath);
172         assertTrue(rcbakFile.exists());
173         System.out.println("Backup was copied: " + rcbakFile.getAbsolutePath());
174
175         String JavaDoc firstRcbakFilePath= firstfilepath +".bak." +time ;
176         File JavaDoc firstRcbakFile = new File JavaDoc(rcbakDirectory, AUTHORING_PATH + firstRcbakFilePath);
177         assertFalse(firstRcbakFile.exists());
178         System.out.println("Backup was deleted: " + firstRcbakFile.getAbsolutePath());
179
180         //TODO evaluation of meta, workflow
181

182         //evaluate the node
183
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