KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > authoring > DocumentCreatorTest


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: DocumentCreatorTest.java 160152 2005-04-05 09:59:45Z michi $ */
19
20 package org.apache.lenya.cms.authoring;
21
22 import java.io.File JavaDoc;
23
24 import junit.framework.Test;
25 import junit.framework.TestCase;
26 import junit.framework.TestSuite;
27 import junit.textui.TestRunner;
28
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.SiteTreeException;
33 import org.apache.lenya.cms.publication.SiteTreeNode;
34
35
36 /**
37  *
38  * To change the template for this generated type comment go to
39  * Window>Preferences>Java>Code Generation>Code and Comments
40  */

41 public class DocumentCreatorTest extends TestCase {
42     /**
43      * Constructor.
44      * @param test The test to invoke.
45      */

46     public DocumentCreatorTest(String JavaDoc test) {
47         super(test);
48     }
49
50     /**
51      * The main program.
52      * The parameters are set from the command line arguments.
53      *
54      * @param args The command line arguments.
55      */

56     public static void main(String JavaDoc[] args) {
57         args = PublicationHelper.extractPublicationArguments(args);
58         TestRunner.run(getSuite());
59     }
60
61     /**
62      * Returns the test suite.
63      * @return A Test object.
64      */

65     public static Test getSuite() {
66         return new TestSuite(DocumentCreatorTest.class);
67     }
68
69     /**
70      * Tests whatever you want.
71      * @throws CreatorException when something went wrong.
72      * @throws SiteTreeException when something went wrong.
73      */

74     public void testCreator()
75         throws CreatorException, SiteTreeException {
76         Publication publication = PublicationHelper.getPublication();
77         DocumentCreator creator = new DocumentCreator();
78         File JavaDoc authoringDirectory = new File JavaDoc(publication.getDirectory(), AUTHORING_DIR);
79
80         creator.create(publication, authoringDirectory, AREA, PARENT_ID, CHILD_ID, CHILD_NAME,
81             CHILD_TYPE, DOCUMENT_TYPE, DOCUMENT_LANGUAGE, VISIBLEINNAV);
82
83         File JavaDoc documentFile = new File JavaDoc(authoringDirectory, CREATED_FILE);
84         assertTrue(documentFile.exists());
85         System.out.println("File was created: " + documentFile.getAbsolutePath());
86
87         SiteTree sitetree = publication.getTree(AREA);
88         SiteTreeNode node = sitetree.getNode(PARENT_ID + "/" + CHILD_ID);
89         assertNotNull(node);
90         System.out.println("Sitetree node was created: " + node.getId() + " (label: " +
91             node.getLabel(DOCUMENT_LANGUAGE) + ")");
92     }
93
94     protected static final String JavaDoc AUTHORING_DIR = "content" + File.separator + "authoring";
95     protected static final String JavaDoc PARENT_ID = "/tutorial";
96     protected static final String JavaDoc CHILD_ID = "test-document";
97     protected static final String JavaDoc CHILD_NAME = "Test Document";
98     protected static final String JavaDoc CHILD_TYPE = "leaf";
99     protected static final String JavaDoc DOCUMENT_TYPE = "xhtml";
100     protected static final String JavaDoc CREATED_FILE = "tutorial/test-document/index_en.xml";
101     protected static final String JavaDoc DOCUMENT_LANGUAGE = "en";
102     protected static final String JavaDoc AREA = "authoring";
103     protected static final boolean VISIBLEINNAV =true;
104
105     /** @see junit.framework.TestCase#setUp() */
106     protected void setUp() throws Exception JavaDoc {
107         if (PublicationHelper.getPublication() == null) {
108             String JavaDoc[] args = { "/home/egli/build/jakarta-tomcat-4.1.21-LE-jdk14/webapps/lenya", "test" };
109             PublicationHelper.extractPublicationArguments(args);
110         }
111     }
112 }
113
Popular Tags