KickJava   Java API By Example, From Geeks To Geeks.

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


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: DefaultSiteTreeTest.java 57494 2004-11-12 02:47:02Z gregor $ */
19
20 package org.apache.lenya.cms.publication;
21
22 import java.io.IOException JavaDoc;
23
24 import javax.xml.parsers.ParserConfigurationException JavaDoc;
25 import javax.xml.transform.TransformerException JavaDoc;
26
27 import junit.framework.TestCase;
28
29 import org.xml.sax.SAXException JavaDoc;
30
31 public class DefaultSiteTreeTest extends TestCase {
32     
33     private DefaultSiteTree siteTree = null;
34
35     /**
36      * Constructor.
37      * @param test The test.
38      */

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

49     public static void main(String JavaDoc[] args) {
50         junit.textui.TestRunner.run(DefaultSiteTreeTest.class);
51     }
52
53     /**
54      * @see TestCase#setUp()
55      */

56     protected void setUp() throws Exception JavaDoc {
57         super.setUp();
58         siteTree = new DefaultSiteTree("testTree.xml");
59         Label label = new Label("Foo", "en");
60         Label[] fooLabels = { label };
61         siteTree.addNode("/foo", fooLabels, true, null, null, false);
62         label = new Label("Home", "en");
63         Label[] homeLabels = { label };
64         siteTree.addNode("/index", homeLabels, true, null, null, false);
65         label = new Label("Bar", "en");
66         Label label_de = new Label("Stab", "de");
67         Label[] barLabels = { label, label_de };
68         siteTree.addNode("/foo/bar", barLabels, true, "http://exact.biz", "suffix", true);
69         label = new Label("Lala", "en");
70         Label[] lalaLabels = { label };
71         siteTree.addNode("/foo/lala", lalaLabels, true, null, null, false);
72     }
73
74     /**
75      * @see TestCase#tearDown()
76      */

77     protected void tearDown() throws Exception JavaDoc {
78         super.tearDown();
79     }
80
81     /**
82      * Test for void DefaultSiteTree(String)
83      */

84     final public void testDefaultSiteTreeString() {
85         //TODO Implement DefaultSiteTree().
86
}
87
88     /**
89      * Test for void DefaultSiteTree(File)
90      */

91     final public void testDefaultSiteTreeFile() {
92         //TODO Implement DefaultSiteTree().
93
}
94
95     /**
96      * Test for void addNode(String, String, Label[])
97      *
98      * @throws SiteTreeException if an error occurs
99      */

100     final public void testAddNodeStringStringLabelArray() throws SiteTreeException {
101         Label label = new Label("Tutorial", null);
102         Label[] labels = { label };
103
104         siteTree.addNode("/foo", "tutorial", labels);
105         SiteTreeNode node = siteTree.getNode("/foo/tutorial");
106         assertNotNull(node);
107         assertEquals(node.getId(), "tutorial");
108     }
109
110     /**
111      * Test for void addNode(SiteTreeNode)
112      */

113     final public void testAddNodeSiteTreeNode() {
114         //TODO Implement addNode().
115
}
116
117     /**
118      * Test for void addNode(String, Label[], String, String, boolean)
119      *
120      * @throws SiteTreeException if an error occurs
121      */

122     final public void testAddNodeStringLabelArrayStringStringboolean() throws SiteTreeException {
123         Label label1 = new Label("Doh", "en");
124         Label label2 = new Label("Ding", "en");
125         Label[] labels = { label1, label2};
126
127         siteTree.addNode("/foo/ding", labels, true, null, null, false);
128         
129         assertNotNull(siteTree.getNode("/foo/ding"));
130         assertEquals(siteTree.getNode("/foo/ding").getId(), "ding");
131     }
132
133     /**
134      * Test for void addNode(String, String, Label[], String, String, boolean)
135      *
136      * @throws SiteTreeException if an error occurs
137      */

138     final public void testAddNodeStringStringLabelArrayStringStringboolean() throws SiteTreeException {
139         Label label1 = new Label("Doh", "en");
140         Label label2 = new Label("Ding", "en");
141         Label[] labels = { label1, label2};
142
143         siteTree.addNode("/foo", "baz", labels, true, null, null, false);
144         
145         assertNotNull(siteTree.getNode("/foo/baz"));
146         assertEquals(siteTree.getNode("/foo/baz").getId(), "baz");
147     }
148
149     /**
150      * Test addLabel
151      *
152      * @throws SiteTreeException if an error occurs
153      */

154     final public void testAddLabel() throws SiteTreeException {
155         Label label = new Label("Tutorial", null);
156         Label[] labels = null;
157
158         siteTree.addLabel("/foo/bar", label);
159         labels = siteTree.getNode("/foo/bar").getLabels();
160         assertEquals(labels.length, 3);
161         label = siteTree.getNode("/foo/bar").getLabel("");
162         assertNotNull(label);
163         assertEquals(label.getLabel(), "Tutorial");
164     }
165
166     /**
167      * Test removeLabel
168      *
169      */

170     final public void testRemoveLabel() {
171         assertEquals(siteTree.getNode("/foo/bar").getLabels().length, 2);
172         
173         Label label = new Label("Stab", "de");
174         siteTree.removeLabel("/foo/bar", label);
175         assertEquals(siteTree.getNode("/foo/bar").getLabels().length, 1);
176         
177         assertEquals(siteTree.getNode("/foo/bar").getLabels()[0], new Label("Bar", "en"));
178         
179         siteTree.addLabel("/foo/bar", label);
180         assertEquals(siteTree.getNode("/foo/bar").getLabels().length, 2);
181     }
182
183     /**
184      * Test removeNode
185      *
186      * @throws SiteTreeException if an error occurs
187      */

188     final public void testRemoveNode() throws SiteTreeException {
189         Label label1 = new Label("Hi", "en");
190         Label label2 = new Label("Ho", "en");
191         Label[] labels1 = { label1, label2};
192         
193         siteTree.addNode("/hi", labels1, true, null, null, false);
194
195         Label[] labels2 = { label1, label2};
196
197         siteTree.addNode("/hi/ho", labels2, true, null, null, false);
198         
199         assertNotNull(siteTree.getNode("/hi/ho"));
200         
201         siteTree.removeNode("/hi");
202         
203         assertNull(siteTree.getNode("/hi/ho"));
204         assertNull(siteTree.getNode("/hi"));
205     }
206
207     /**
208      * Test getNode
209      *
210      */

211     final public void testGetNode() {
212         assertNotNull(siteTree.getNode("/foo/bar"));
213         
214         assertNull(siteTree.getNode("/foo/baz"));
215     }
216
217     /**
218      * Test save
219      *
220      */

221     final public void testSave() {
222         //TODO Implement save().
223
}
224     
225     /**
226      * Test moving a node up
227      *
228      * @throws SiteTreeException if an error occurs
229      * @throws IOException if an error occurs
230      * @throws TransformerException if an error occurs
231      */

232     final public void testMoveUp() throws SiteTreeException, IOException JavaDoc, TransformerException JavaDoc {
233         siteTree.moveUp("/foo/lala");
234         siteTree.save();
235         assertNotNull(siteTree.getNode("/foo/lala"));
236     }
237     
238     /**
239      * Test moving a node down
240      *
241      * @throws SiteTreeException if an error occurs
242      * @throws IOException if an error occurs
243      * @throws TransformerException if an error occurs
244      */

245     final public void testMoveDown() throws SiteTreeException, IOException JavaDoc, TransformerException JavaDoc {
246         siteTree.moveDown("/foo");
247         siteTree.save();
248         assertNotNull(siteTree.getNode("/foo"));
249     }
250     
251     /**
252      * Test the import of a subtree
253      *
254      * @throws ParserConfigurationException if an error occurs.
255      * @throws SAXException if an error occurs.
256      * @throws SiteTreeException if an error occurs.
257      * @throws IOException if an error occurs.
258      * @throws TransformerException if an error occurs.
259      */

260     final public void testImportSubtree() throws ParserConfigurationException JavaDoc, SAXException JavaDoc, SiteTreeException, IOException JavaDoc, TransformerException JavaDoc {
261         DefaultSiteTree newSiteTree = new DefaultSiteTree("importedTree.xml");
262         Label label = new Label("root", "en");
263         Label[] rootLabels = { label };
264         newSiteTree.addNode("/root", rootLabels, true, null, null, false);
265         label = new Label("foo", "en");
266         Label[] fooLabels = { label };
267         newSiteTree.addNode("/root/foo", fooLabels, true, null, null, false);
268         label = new Label("subtree", "en");
269         Label[] subtreeLabels = { label };
270         newSiteTree.addNode("/root/subtree", subtreeLabels, true, "http://exact.biz", "suffix", true);
271         label = new Label("child", "en");
272         Label[] childLabels = { label };
273         newSiteTree.addNode("/root/subtree/child", childLabels, true, null, null, false);
274         SiteTreeNode node=newSiteTree.getNode("/root/subtree");
275         assertNotNull(node);
276         SiteTreeNode parentNode=siteTree.getNode("/foo/lala");
277         assertNotNull(parentNode);
278         siteTree.importSubtree(parentNode,node, "subtree", null);
279         siteTree.save();
280         assertNotNull(siteTree.getNode("/foo/lala/subtree"));
281         assertNotNull(siteTree.getNode("/foo/lala/subtree/child"));
282     }
283 }
284
Popular Tags