KickJava   Java API By Example, From Geeks To Geeks.

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


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: SiteTreeNodeImplTest.java 55566 2004-10-26 03:53:08Z gregor $ */
19
20 package org.apache.lenya.cms.publication;
21
22 import junit.framework.TestCase;
23
24 public class SiteTreeNodeImplTest extends TestCase {
25
26     private SiteTreeNode node = null;
27
28     /**
29      * Constructor.
30      * @param test The test.
31      */

32     public SiteTreeNodeImplTest(String JavaDoc test) {
33         super(test);
34     }
35
36     /**
37      * The main program.
38      * The parameters are set from the command line arguments.
39      *
40      * @param args The command line arguments.
41      */

42     public static void main(String JavaDoc[] args) {
43         junit.textui.TestRunner.run(SiteTreeNodeImplTest.class);
44     }
45
46     /**
47      * @see TestCase#setUp()
48      */

49     protected void setUp() throws Exception JavaDoc {
50         super.setUp();
51         DefaultSiteTree siteTree = new DefaultSiteTree("testTree");
52         Label label = new Label("Foo", "en");
53         Label[] fooLabels = { label };
54         siteTree.addNode("/foo", fooLabels, true, null, null, false);
55         label = new Label("Bar", "en");
56         Label label_de = new Label("Stab", "de");
57         Label[] barLabels = { label, label_de };
58         siteTree.addNode(
59             "/foo/bar",
60             barLabels,
61             true,
62             "http://exact.biz",
63             "suffix",
64             true);
65
66         node = siteTree.getNode("/foo/bar");
67     }
68
69     /**
70      * @see TestCase#tearDown()
71      */

72     protected void tearDown() throws Exception JavaDoc {
73         super.tearDown();
74     }
75
76     /**
77      * Test getParentId.
78      *
79      */

80     final public void testGetParentId() {
81         assertEquals(node.getParentId(), "foo");
82     }
83
84     /**
85      * Test getAbsoluteId
86      *
87      */

88     final public void testGetAbsoluteId() {
89         assertEquals(node.getAbsoluteId(), "/foo/bar");
90     }
91
92     /**
93      * Test getId
94      *
95      */

96     final public void testGetId() {
97         assertEquals(node.getId(), "bar");
98     }
99
100     /**
101      * Test getLabels
102      *
103      */

104     final public void testGetLabels() {
105         assertEquals(node.getLabels().length, 2);
106         for (int i = 0; i < node.getLabels().length; i++) {
107             Label label = node.getLabels()[i];
108             Label label1 = new Label("Bar", "en");
109             Label label2 = new Label("Stab", "de");
110             assertTrue(label.equals(label1) || label.equals(label2));
111         }
112     }
113
114     /**
115      * Test getLabel
116      *
117      */

118     final public void testGetLabel() {
119         Label label = node.getLabel("en");
120         assertNotNull(label);
121         assertEquals(label.getLabel(), "Bar");
122     }
123
124     /**
125      * Test addLabel
126      *
127      */

128     final public void testAddLabel() {
129         Label label = new Label("Barolo", "it");
130         node.addLabel(label);
131         label = node.getLabel("it");
132         assertNotNull(label);
133         assertEquals(label.getLabel(), "Barolo");
134         label = node.getLabel("ch");
135         assertNull(label);
136     }
137
138     /**
139      * Test removeLabel
140      *
141      */

142     final public void testRemoveLabel() {
143         Label label = new Label("Bar", "en");
144         assertNotNull(node.getLabel("en"));
145         node.removeLabel(label);
146         assertNull(node.getLabel("en"));
147     }
148
149     /**
150      * Test getHref
151      *
152      */

153     final public void testGetHref() {
154         assertEquals(node.getHref(), "http://exact.biz");
155     }
156
157     /**
158      * Test getSuffix
159      *
160      *
161      */

162     final public void testGetSuffix() {
163         assertEquals(node.getSuffix(), "suffix");
164     }
165
166     /**
167      * Test hasLink
168      *
169      */

170     final public void testHasLink() {
171         assertTrue(node.hasLink());
172     }
173
174 }
175
Popular Tags