001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: /* $Id: DefaultSiteTreeTest.java 568271 2007-08-21 20:49:18Z andreas $ */
020:
021: package org.apache.lenya.cms.site.tree;
022:
023: import junit.framework.TestCase;
024:
025: import org.apache.avalon.framework.container.ContainerUtil;
026: import org.apache.lenya.ac.impl.AbstractAccessControlTest;
027: import org.apache.lenya.cms.publication.Publication;
028: import org.apache.lenya.cms.publication.PublicationException;
029: import org.apache.lenya.cms.repository.RepositoryException;
030: import org.apache.lenya.cms.site.Link;
031: import org.apache.lenya.cms.site.SiteException;
032: import org.apache.lenya.cms.site.SiteNode;
033: import org.apache.lenya.cms.site.tree.DefaultSiteTree;
034: import org.apache.lenya.cms.site.tree.SiteTreeNode;
035:
036: /**
037: * Test class for the default site tree
038: */
039: public class DefaultSiteTreeTest extends AbstractAccessControlTest {
040:
041: private DefaultSiteTree siteTree = null;
042:
043: /**
044: * @see TestCase#setUp()
045: */
046: public void setUp() throws Exception {
047: super .setUp();
048: Publication pub = getPublication("test");
049: this .siteTree = new DefaultSiteTree(getFactory(), pub, "test",
050: getManager(), getLogger());
051: ContainerUtil.enableLogging(this .siteTree, getLogger());
052:
053: this .siteTree.getRepositoryNode().lock();
054:
055: this .siteTree.addNode("/foo", "foo-uuid", true, null, null,
056: false);
057: this .siteTree.addNode("/index", "index-uuid", true, null, null,
058: false);
059: this .siteTree.addNode("/foo/bar", "foo-bar-uuid", true,
060: "http://exact.biz", "suffix", true);
061: this .siteTree.addNode("/foo/lala", "foo-lala-uuid", true, null,
062: null, false);
063: }
064:
065: /**
066: * @see TestCase#tearDown()
067: */
068: public void tearDown() throws Exception {
069: super .tearDown();
070: this .siteTree.getRepositoryNode().unlock();
071: }
072:
073: /**
074: * Test for void DefaultSiteTree(String)
075: */
076: final public void testDefaultSiteTreeString() {
077: // TODO Implement DefaultSiteTree().
078: }
079:
080: /**
081: * Test for void DefaultSiteTree(File)
082: */
083: final public void testDefaultSiteTreeFile() {
084: // TODO Implement DefaultSiteTree().
085: }
086:
087: /**
088: * Test for void addNode(String, String, Label[])
089: *
090: * @throws SiteException if an error occurs
091: */
092: final public void testAddNodeStringStringLabelArray()
093: throws SiteException {
094: String uuid = "12345";
095: this .siteTree.addNode("/foo", "tutorial", uuid, true);
096: this .siteTree.addLabel("/foo", "en", "Tutorial");
097: SiteNode node = this .siteTree.getNode("/foo/tutorial");
098: assertNotNull(node);
099: assertEquals(node.getName(), "tutorial");
100: assertEquals(node.getUuid(), uuid);
101: }
102:
103: /**
104: * Test for void addNode(SiteTreeNode)
105: */
106: final public void testAddNodeSiteTreeNode() {
107: // TODO Implement addNode().
108: }
109:
110: /**
111: * Test for void addNode(String, Label[], String, String, boolean)
112: *
113: * @throws SiteException if an error occurs
114: */
115: final public void testAddNodeStringLabelArrayStringStringboolean()
116: throws SiteException {
117: this .siteTree.addNode("/foo/ding", "foo-ding-uuid", true, null,
118: null, false);
119: this .siteTree.addLabel("/foo/ding", "en", "Doh");
120: this .siteTree.addLabel("/foo/ding", "de", "Ding");
121:
122: assertNotNull(this .siteTree.getNode("/foo/ding"));
123: assertEquals(this .siteTree.getNode("/foo/ding").getName(),
124: "ding");
125: }
126:
127: /**
128: * Test for void addNode(String, String, Label[], String, String, boolean)
129: * @throws SiteException if an error occurs
130: */
131: final public void testAddNodeStringStringLabelArrayStringStringboolean()
132: throws SiteException {
133:
134: String uuid = "123";
135:
136: this .siteTree.addNode("/foo", "baz", uuid, true, null, null,
137: false);
138:
139: assertNotNull(this .siteTree.getNode("/foo/baz"));
140: assertEquals(this .siteTree.getNode("/foo/baz").getName(), "baz");
141: }
142:
143: /**
144: * Test addLabel
145: * @throws SiteException
146: */
147: final public void testAddLabel() throws SiteException {
148: this .siteTree.addLabel("/foo/bar", "en", "Tutorial");
149: String[] labels = ((SiteTreeNode) this .siteTree
150: .getNode("/foo/bar")).getLanguages();
151: assertEquals(labels.length, 1);
152: Link label = ((SiteTreeNode) this .siteTree.getNode("/foo/bar"))
153: .getLink("en");
154: assertNotNull(label);
155: assertEquals(label.getLabel(), "Tutorial");
156: }
157:
158: /**
159: * Test removeLabel
160: * @throws SiteException
161: */
162: final public void testRemoveLabel() throws SiteException {
163: this .siteTree.addLabel("/foo/bar", "de", "Hello");
164: if (!this .siteTree.getNode("/foo/bar").hasLink("en")) {
165: this .siteTree.addLabel("/foo/bar", "en", "World");
166: }
167: assertEquals(((SiteTreeNode) this .siteTree.getNode("/foo/bar"))
168: .getLanguages().length, 2);
169:
170: this .siteTree.removeLabel("/foo/bar", "de");
171: assertEquals(((SiteTreeNode) this .siteTree.getNode("/foo/bar"))
172: .getLanguages().length, 1);
173:
174: assertEquals(((SiteTreeNode) this .siteTree.getNode("/foo/bar"))
175: .getLanguages()[0], "en");
176:
177: this .siteTree.addLabel("/foo/bar", "de", "Foo");
178: assertEquals(((SiteTreeNode) this .siteTree.getNode("/foo/bar"))
179: .getLanguages().length, 2);
180: }
181:
182: /**
183: * Test removeNode
184: *
185: * @throws SiteException if an error occurs
186: */
187: final public void testRemoveNode() throws SiteException {
188:
189: this .siteTree
190: .addNode("/hi", "hi-uuid", true, null, null, false);
191:
192: this .siteTree.addNode("/hi/ho", "hi-ho-uuid", true, null, null,
193: false);
194:
195: assertNotNull(this .siteTree.getNode("/hi/ho"));
196:
197: this .siteTree.removeNode("/hi");
198:
199: assertFalse(this .siteTree.contains("/hi/ho"));
200: assertFalse(this .siteTree.contains("/hi"));
201: }
202:
203: /**
204: * Test getNode
205: * @throws SiteException
206: *
207: */
208: final public void testGetNode() throws SiteException {
209: assertNotNull(this .siteTree.getNode("/foo/bar"));
210: assertFalse(this .siteTree.contains("/foo/bar/baz"));
211: }
212:
213: /**
214: * Test save
215: *
216: */
217: final public void testSave() {
218: // TODO Implement save().
219: }
220:
221: /**
222: * Test moving a node up
223: * @throws RepositoryException
224: */
225: final public void testMoveUp() throws RepositoryException {
226: this .siteTree.moveUp("/foo/lala");
227: this .siteTree.save();
228: assertNotNull(this .siteTree.getNode("/foo/lala"));
229: }
230:
231: /**
232: * Test moving a node down
233: * @throws RepositoryException
234: */
235: final public void testMoveDown() throws RepositoryException {
236: this .siteTree.moveDown("/foo");
237: this .siteTree.save();
238: assertNotNull(this .siteTree.getNode("/foo"));
239: }
240:
241: /**
242: * Test the import of a subtree
243: * @throws PublicationException
244: * @throws RepositoryException
245: */
246: final public void testImportSubtree() throws PublicationException,
247: RepositoryException {
248: Publication pub = getPublication("test");
249: DefaultSiteTree newSiteTree = new DefaultSiteTree(getFactory(),
250: pub, "test1", getManager(), getLogger());
251: ContainerUtil.enableLogging(newSiteTree, getLogger());
252:
253: newSiteTree.getRepositoryNode().lock();
254:
255: newSiteTree.addNode("/root", "root-uuid", true, null, null,
256: false);
257: newSiteTree.addLabel("/root", "en", "root");
258: newSiteTree.addNode("/root/foo", "root-foo-uuid", true, null,
259: null, false);
260: newSiteTree.addLabel("/root/foo", "en", "foo");
261: newSiteTree.addNode("/root/subtree", "root-subtree-uuid", true,
262: "http://exact.biz", "suffix", true);
263: newSiteTree.addLabel("/root/subtree", "en", "subtree");
264: newSiteTree.addNode("/root/subtree/child",
265: "root-subtree-child-uuid", true, null, null, false);
266: newSiteTree.addLabel("/root/subtree/child", "en", "child");
267: SiteTreeNode node = (SiteTreeNode) newSiteTree
268: .getNode("/root/subtree");
269: assertNotNull(node);
270: SiteTreeNode parentNode = (SiteTreeNode) this .siteTree
271: .getNode("/foo/lala");
272: assertNotNull(parentNode);
273:
274: newSiteTree.getRepositoryNode().unlock();
275: }
276: }
|