KickJava   Java API By Example, From Geeks To Geeks.

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


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: DocumentDeactivateTaskTest.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
24 import junit.framework.Test;
25 import junit.framework.TestSuite;
26 import junit.textui.TestRunner;
27
28 import org.apache.avalon.framework.parameters.Parameters;
29 import org.apache.lenya.cms.PublicationHelper;
30 import org.apache.lenya.cms.publication.Publication;
31 import org.apache.lenya.cms.publication.SiteTree;
32 import org.apache.lenya.cms.publication.SiteTreeNode;
33
34
35 /**
36  * Class for testing the task to deactivate a document.
37  * Extend the AntTask class.
38  */

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

47     public DocumentDeactivateTaskTest(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(DocumentDeactivateTaskTest.class);
57     }
58
59     /**
60      * The main program for the DocumentDeactivateTaskTest 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 DOCUMENT_ID = "/tutorial";
70     public static final String JavaDoc LANGUAGE = "en";
71     public static final String JavaDoc AUTHORING_PATH = "content/authoring".replace('/', File.separatorChar);
72     public static final String JavaDoc LIVE_PATH = "content/live".replace('/', File.separatorChar);
73     
74     /**
75      * @see org.apache.lenya.cms.task.AntTaskTest#getTaskParameters()
76      **/

77     protected Parameters getTaskParameters() {
78         Parameters parameters = super.getTaskParameters();
79         parameters.setParameter("properties.node.firstdocumentid", DOCUMENT_ID);
80         parameters.setParameter("properties.node.language", LANGUAGE);
81         return parameters;
82     }
83     
84     /**
85      * Returns the target test.
86      * @return target.
87      */

88     protected String JavaDoc getTarget() {
89         return "deactivateDocument";
90     }
91
92     /** (non-Javadoc)
93      * @see org.apache.lenya.cms.task.AntTaskTest#prepareTest()
94      */

95     protected void prepareTest() throws Exception JavaDoc {
96         File JavaDoc publicationDirectory = PublicationHelper.getPublication().getDirectory();
97         String JavaDoc publicationPath = publicationDirectory.getAbsolutePath()+ File.separator;
98
99
100         // TODO generate the resources
101
}
102
103     /** (non-Javadoc)
104      * @see org.apache.lenya.cms.task.AntTaskTest#evaluateTest()
105      */

106     protected void evaluateTest() throws Exception JavaDoc {
107         File JavaDoc publicationDirectory = PublicationHelper.getPublication().getDirectory();
108         String JavaDoc publicationPath = publicationDirectory.getAbsolutePath();
109         File JavaDoc authoringDirectory = new File JavaDoc(publicationPath, AUTHORING_PATH);
110         File JavaDoc liveDirectory = new File JavaDoc(publicationPath, LIVE_PATH);
111         
112         String JavaDoc filepath = DOCUMENT_ID.substring(1) + File.separator + "index_en.xml";
113
114         File JavaDoc authoringDocumentFile = new File JavaDoc(authoringDirectory, filepath);
115         System.out.println("Authoring document: " + authoringDocumentFile.getAbsolutePath());
116         assertTrue(authoringDocumentFile.exists());
117         File JavaDoc liveDocumentFile = new File JavaDoc(liveDirectory, filepath);
118         System.out.println("Live document: " + liveDocumentFile.getAbsolutePath());
119         assertFalse(liveDocumentFile.exists());
120
121         //TODO evaluation of resources, meta, workflow
122

123         SiteTree authoringSitetree = PublicationHelper.getPublication().getTree(Publication.AUTHORING_AREA);
124         SiteTreeNode node = authoringSitetree.getNode(DOCUMENT_ID);
125         assertNotNull(node);
126         System.out.println("Sitetree node with id ["+node.getId()+"] is always in authoring");
127         SiteTree liveSitetree = PublicationHelper.getPublication().getTree(Publication.LIVE_AREA);
128         SiteTreeNode livenode = liveSitetree.getNode(DOCUMENT_ID);
129         assertNull(livenode);
130         System.out.println("Sitetree node for document id ["+DOCUMENT_ID+"] was deleted from the live tree");
131     }
132 }
133
Popular Tags