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: SiteTreeNodeImplTest.java 494807 2007-01-10 13:12:27Z andreas $ */
020:
021: package org.apache.lenya.cms.site.tree;
022:
023: import org.apache.avalon.framework.container.ContainerUtil;
024: import org.apache.lenya.ac.impl.AbstractAccessControlTest;
025: import org.apache.lenya.cms.publication.Publication;
026: import org.apache.lenya.cms.site.Link;
027: import org.apache.lenya.cms.site.SiteException;
028: import org.apache.lenya.cms.site.tree.DefaultSiteTree;
029:
030: import junit.framework.TestCase;
031:
032: /**
033: * Tests the site tree
034: */
035: public class SiteTreeNodeImplTest extends AbstractAccessControlTest {
036:
037: private SiteTreeNodeImpl node = null;
038: private DefaultSiteTree siteTree = null;
039:
040: /**
041: * @see TestCase#setUp()
042: */
043: public void setUp() throws Exception {
044: super .setUp();
045: Publication pub = getPublication("test");
046: this .siteTree = new DefaultSiteTree(getFactory(), pub,
047: "testArea", getManager(), getLogger());
048: ContainerUtil.enableLogging(siteTree, getLogger());
049:
050: siteTree.getRepositoryNode().lock();
051:
052: if (siteTree.contains("/foo")) {
053: siteTree.removeNode("/foo");
054: }
055:
056: siteTree.addNode("/foo", "foo-uuid", true, null, null, false);
057: siteTree.addLabel("/foo", "en", "Foo");
058:
059: siteTree.addNode("/foo/bar", "foo-bar-uuid", true,
060: "http://exact.biz", "suffix", true);
061: siteTree.addLabel("/foo/bar", "en", "Bar");
062: siteTree.addLabel("/foo/bar", "de", "Stab");
063:
064: this .node = (SiteTreeNodeImpl) siteTree.getNode("/foo/bar");
065: }
066:
067: /**
068: * @see TestCase#tearDown()
069: */
070: public void tearDown() throws Exception {
071: super .tearDown();
072: this .siteTree.getRepositoryNode().unlock();
073: }
074:
075: /**
076: * Test getAbsoluteId
077: *
078: */
079: final public void testGetAbsoluteId() {
080: assertEquals(this .node.getPath(), "/foo/bar");
081: }
082:
083: /**
084: * Test getId
085: *
086: */
087: final public void testGetId() {
088: assertEquals(this .node.getName(), "bar");
089: }
090:
091: /**
092: * Test getLabels
093: * @throws SiteException
094: *
095: */
096: final public void testGetLabels() throws SiteException {
097: String[] languages = this .node.getLanguages();
098: assertEquals(languages.length, 2);
099: }
100:
101: /**
102: * Test getLabel
103: * @throws SiteException
104: *
105: */
106: final public void testGetLabel() throws SiteException {
107: Link label = this .node.getLink("en");
108: assertNotNull(label);
109: assertEquals(label.getLabel(), "Bar");
110: }
111:
112: /**
113: * Test addLabel
114: * @throws SiteException
115: *
116: */
117: final public void testAddLabel() throws SiteException {
118: this .node.addLabel("it", "Barolo");
119: Link label = this .node.getLink("it");
120: assertNotNull(label);
121: assertEquals(label.getLabel(), "Barolo");
122: assertFalse(this .node.hasLink("ch"));
123: }
124:
125: /**
126: * Test removeLabel
127: * @throws SiteException
128: *
129: */
130: final public void testRemoveLabel() throws SiteException {
131: assertNotNull(this .node.getLink("en"));
132: this .node.removeLabel("en");
133: assertFalse(this .node.hasLink("en"));
134: }
135:
136: /**
137: * Test getHref
138: *
139: */
140: final public void testGetHref() {
141: assertEquals(this .node.getHref(), "http://exact.biz");
142: }
143:
144: /**
145: * Test getSuffix
146: *
147: *
148: */
149: final public void testGetSuffix() {
150: assertEquals(this .node.getSuffix(), "suffix");
151: }
152:
153: /**
154: * Test hasLink
155: *
156: */
157: final public void testHasLink() {
158: assertTrue(this.node.hasLink());
159: }
160:
161: }
|