KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > publication > DefaultDocumentTest


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: DefaultDocumentTest.java 42625 2004-03-04 15:45:03Z egli $ */
19
20 package org.apache.lenya.cms.publication;
21
22 import junit.framework.Test;
23 import junit.framework.TestCase;
24 import junit.framework.TestSuite;
25 import junit.textui.TestRunner;
26
27 import org.apache.lenya.cms.PublicationHelper;
28
29
30 /**
31  *
32  * To change the template for this generated type comment go to
33  * Window>Preferences>Java>Code Generation>Code and Comments
34  */

35 public class DefaultDocumentTest extends TestCase {
36     /**
37      * Constructor.
38      * @param test The test.
39      */

40     public DefaultDocumentTest(String JavaDoc test) {
41         super(test);
42     }
43
44     /**
45      * The main program.
46      * The parameters are set from the command line arguments.
47      *
48      * @param args The command line arguments.
49      */

50     public static void main(String JavaDoc[] args) {
51         PublicationHelper.extractPublicationArguments(args);
52         TestRunner.run(getSuite());
53     }
54
55     /**
56      * Returns the test suite.
57      * @return A test suite.
58      */

59     public static Test getSuite() {
60         return new TestSuite(DefaultDocumentTest.class);
61     }
62
63     protected static final DocumentTestSet[] testSets = {
64         new DocumentTestSet("/index.html", "/index", Publication.AUTHORING_AREA, "en", "html"),
65         new DocumentTestSet("/index_en.htm", "/index", Publication.AUTHORING_AREA, "en", "htm"),
66         new DocumentTestSet("/index_de.html", "/index", Publication.AUTHORING_AREA, "de", "html")
67     };
68
69     /**
70      * Tests a document test set.
71      * @param testSet The test set.
72      * @throws DocumentBuildException when something went wrong.
73      */

74     protected void doDocumentTest(DocumentTestSet testSet)
75         throws DocumentBuildException {
76         Document document = getDocument(testSet);
77         System.out.println("ID: " + document.getId());
78         System.out.println("Area: " + document.getArea());
79         System.out.println("Language: " + document.getLanguage());
80         System.out.println("Document URL: " + document.getDocumentURL());
81         System.out.println("Complete URL: " + document.getCompleteURL());
82         System.out.println("Extension: " + document.getExtension());
83
84         Publication publication = PublicationHelper.getPublication();
85         assertEquals(document.getPublication(), publication);
86         assertEquals(document.getId(), testSet.getId());
87         assertEquals(document.getArea(), testSet.getArea());
88         assertEquals(document.getLanguage(), testSet.getLanguage());
89         assertEquals(document.getDocumentURL(), testSet.getUrl());
90         assertEquals(document.getCompleteURL(),
91             "/" + publication.getId() + "/" + document.getArea() + testSet.getUrl());
92         assertEquals(document.getExtension(), testSet.getExtension());
93
94         System.out.println("-----------------------------------------------");
95     }
96
97     /**
98      * Tests the default document.
99      * @throws DocumentBuildException when something went wrong.
100      */

101     public void testDefaultDocument() throws DocumentBuildException {
102         for (int i = 0; i < testSets.length; i++) {
103             doDocumentTest(testSets[i]);
104         }
105     }
106
107     /**
108      * Returns the test document for a given test set.
109      * @param testSet A document test set.
110      * @return A document.
111      * @throws DocumentBuildException when something went wrong.
112      */

113     protected Document getDocument(DocumentTestSet testSet)
114         throws DocumentBuildException {
115         DefaultDocument document = new DefaultDocument(PublicationHelper.getPublication(),
116                 testSet.getId(), testSet.getArea());
117         document.setDocumentURL(testSet.getUrl());
118         document.setLanguage(testSet.getLanguage());
119         document.setExtension(testSet.getExtension());
120
121         return document;
122     }
123
124     /**
125      * Utility class to store test data for a document.
126      */

127     protected static class DocumentTestSet {
128         private String JavaDoc url;
129         private String JavaDoc id;
130         private String JavaDoc extension;
131         private String JavaDoc area;
132         private String JavaDoc language;
133
134         /**
135          * Ctor.
136          * @param url The url.
137          * @param id The ID.
138          * @param area The area.
139          * @param language The language.
140          * @param extension The extension.
141          */

142         public DocumentTestSet(String JavaDoc url, String JavaDoc id, String JavaDoc area, String JavaDoc language, String JavaDoc extension) {
143             this.url = url;
144             this.id = id;
145             this.area = area;
146             this.language = language;
147             this.extension = extension;
148         }
149
150         /**
151          * @return The area.
152          */

153         public String JavaDoc getArea() {
154             return area;
155         }
156
157         /**
158          * @return The extension.
159          */

160         public String JavaDoc getExtension() {
161             return extension;
162         }
163
164         /**
165          * @return The ID.
166          */

167         public String JavaDoc getId() {
168             return id;
169         }
170
171         /**
172          * @return The language.
173          */

174         public String JavaDoc getLanguage() {
175             return language;
176         }
177
178         /**
179          * @return The URL.
180          */

181         public String JavaDoc getUrl() {
182             return url;
183         }
184     }
185
186     /**
187      * @see junit.framework.TestCase#setUp()
188      */

189     protected void setUp() throws Exception JavaDoc {
190         if (PublicationHelper.getPublication() == null) {
191             String JavaDoc[] args = { "D:\\Development\\build\\tomcat-4.1.24\\webapps\\lenya", "test" };
192             PublicationHelper.extractPublicationArguments(args);
193         }
194     }
195 }
196
Popular Tags