You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by ed...@apache.org on 2003/09/23 15:50:40 UTC

cvs commit: cocoon-lenya/src/test/org/apache/lenya/cms/publication DefaultSiteTreeTest.java

edith       2003/09/23 06:50:40

  Modified:    src/java/org/apache/lenya/cms/ant InsertCopyNode.java
                        MoveNode.java
               src/java/org/apache/lenya/cms/publication SiteTree.java
                        DefaultSiteTree.java
               src/test/org/apache/lenya/cms/publication
                        DefaultSiteTreeTest.java
  Log:
  add a refDocumentId to the method importSubtree
  
  Revision  Changes    Path
  1.8       +2 -2      cocoon-lenya/src/java/org/apache/lenya/cms/ant/InsertCopyNode.java
  
  Index: InsertCopyNode.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ant/InsertCopyNode.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- InsertCopyNode.java	19 Aug 2003 13:11:26 -0000	1.7
  +++ InsertCopyNode.java	23 Sep 2003 13:50:40 -0000	1.8
  @@ -109,7 +109,7 @@
   		if (node != null) {
   			SiteTreeNode parentNode = sectree.getNode(parentid);
   			if (parentNode != null) {
  -				sectree.importSubtree(parentNode, node, newid);
  +				sectree.importSubtree(parentNode, node, newid, null);
   			} else {
   				throw new SiteTreeException(
   					"The parent node "
  
  
  
  1.7       +148 -131  cocoon-lenya/src/java/org/apache/lenya/cms/ant/MoveNode.java
  
  Index: MoveNode.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ant/MoveNode.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MoveNode.java	19 Aug 2003 13:11:26 -0000	1.6
  +++ MoveNode.java	23 Sep 2003 13:50:40 -0000	1.7
  @@ -1,131 +1,148 @@
  -/*
  -$Id$
  -<License>
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Apache Lenya" and  "Apache Software Foundation"  must  not  be
  -    used to  endorse or promote  products derived from  this software without
  -    prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation and was  originally created by
  - Michael Wechner <mi...@apache.org>. For more information on the Apache Soft-
  - ware Foundation, please see <http://www.apache.org/>.
  -
  - Lenya includes software developed by the Apache Software Foundation, W3C,
  - DOM4J Project, BitfluxEditor, Xopus, and WebSHPINX.
  -</License>
  -*/
  -package org.apache.lenya.cms.ant;
  -
  -import java.util.StringTokenizer;
  -
  -
  -import org.apache.lenya.cms.publication.Publication;
  -import org.apache.lenya.cms.publication.SiteTree;
  -import org.apache.lenya.cms.publication.SiteTreeException;
  -import org.apache.lenya.cms.publication.SiteTreeNode;
  -
  -/**
  - * @author edith
  - *
  - * Ant task that moves a node in a tree.
  - */
  -public class MoveNode extends TwoNodesTask {
  -	/**
  -	 *
  -	 */
  -	public MoveNode() {
  -		super();
  -	}
  -
  -	/**
  -	 * Move a node.
  -	 * 
  -	 * @param firstdocumentid The document-id of the document corresponding to the source node.
  -	 * @param secdocumentid  The document-id of the document corresponding to the destination node.
  -	 * @param firstarea The area of the document corresponding to the source node.
  -	 * @param secarea The area of the document corresponding to the destination node.
  -	 * @throws SiteTreeException if there are problems with creating or saving the site tree.  
  -	 */
  -	public void manipulateTree(
  -		String firstdocumentid,
  -		String secdocumentid,
  -		String firstarea,
  -		String secarea)
  -		throws SiteTreeException {
  -
  -		Publication publication = getPublication();
  -		SiteTree firsttree = publication.getSiteTree(firstarea);
  -		SiteTree sectree = publication.getSiteTree(secarea);
  -
  -		String parentid = "";
  -		StringTokenizer st = new StringTokenizer(secdocumentid, "/");
  -		int length = st.countTokens();
  -
  -		for (int i = 0; i < (length - 1); i++) {
  -			parentid = parentid + "/" + st.nextToken();
  -		}
  -		String newid = st.nextToken();
  -
  -		SiteTreeNode node = firsttree.removeNode(firstdocumentid);
  -		if (node != null) {
  -			SiteTreeNode parentNode = sectree.getNode(parentid);
  -			if (parentNode != null) {
  -				sectree.importSubtree(parentNode, node, newid);
  -			} else {
  -				throw new SiteTreeException(
  -					"The parent node "
  -						+ parentNode
  -						+ " where the removed node shall be inserted not found");
  -			}
  -		} else {
  -			throw new SiteTreeException(
  -				"Node " + node + " couldn't be removed");
  -		}
  -
  -		if (firstarea.equals(secarea)) {
  -			firsttree.save();
  -		} else {
  -			firsttree.save();
  -			sectree.save();
  -		}
  -	}
  -}
  +/*
  +$Id$
  +<License>
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Apache Lenya" and  "Apache Software Foundation"  must  not  be
  +    used to  endorse or promote  products derived from  this software without
  +    prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation and was  originally created by
  + Michael Wechner <mi...@apache.org>. For more information on the Apache Soft-
  + ware Foundation, please see <http://www.apache.org/>.
  +
  + Lenya includes software developed by the Apache Software Foundation, W3C,
  + DOM4J Project, BitfluxEditor, Xopus, and WebSHPINX.
  +</License>
  +*/
  +package org.apache.lenya.cms.ant;
  +
  +import java.util.StringTokenizer;
  +
  +
  +import org.apache.lenya.cms.publication.Publication;
  +import org.apache.lenya.cms.publication.SiteTree;
  +import org.apache.lenya.cms.publication.SiteTreeException;
  +import org.apache.lenya.cms.publication.SiteTreeNode;
  +
  +/**
  + * @author edith
  + *
  + * Ant task that moves a node in a tree.
  + */
  +public class MoveNode extends TwoNodesTask {
  +	private String refdocumentid;
  +	/**
  +	 *
  +	 */
  +	public MoveNode() {
  +		super();
  +	}
  +
  +	/**
  +	 * Move a node.
  +	 * 
  +	 * @param firstdocumentid The document-id of the document corresponding to the source node.
  +	 * @param secdocumentid  The document-id of the document corresponding to the destination node.
  +	 * @param firstarea The area of the document corresponding to the source node.
  +	 * @param secarea The area of the document corresponding to the destination node.
  +	 * @throws SiteTreeException if there are problems with creating or saving the site tree.  
  +	 */
  +	public void manipulateTree(
  +		String firstdocumentid,
  +		String secdocumentid,
  +		String firstarea,
  +		String secarea)
  +		throws SiteTreeException {
  +
  +		Publication publication = getPublication();
  +		SiteTree firsttree = publication.getSiteTree(firstarea);
  +		SiteTree sectree = publication.getSiteTree(secarea);
  +
  +		String parentid = "";
  +		StringTokenizer st = new StringTokenizer(secdocumentid, "/");
  +		int length = st.countTokens();
  +
  +		for (int i = 0; i < (length - 1); i++) {
  +			parentid = parentid + "/" + st.nextToken();
  +		}
  +		String newid = st.nextToken();
  +
  +		SiteTreeNode node = firsttree.removeNode(firstdocumentid);
  +		if (node != null) {
  +			SiteTreeNode parentNode = sectree.getNode(parentid);
  +			if (parentNode != null) {
  +				sectree.importSubtree(parentNode, node, newid, this.getRefdocumentid());
  +			} else {
  +				throw new SiteTreeException(
  +					"The parent node "
  +						+ parentNode
  +						+ " where the removed node shall be inserted not found");
  +			}
  +		} else {
  +			throw new SiteTreeException(
  +				"Node " + node + " couldn't be removed");
  +		}
  +
  +		if (firstarea.equals(secarea)) {
  +			firsttree.save();
  +		} else {
  +			firsttree.save();
  +			sectree.save();
  +		}
  +	}
  +	/**
  +	 * @return string The document-id corresponding to the reference node, before which 
  +	 * the moved node shoul be inserted. If null, the node is inserted at the end. 
  +	 */
  +	public String getRefdocumentid() {
  +		return refdocumentid;
  +	}
  +
  +	/**
  +	 * @param string The document-id corresponding to the reference node, before which 
  +	 * the moved node shoul be inserted. If null, the node is inserted at the end.
  +	 */
  +	public void setRefdocumentid(String string) {
  +		refdocumentid = string;
  +	}
  +
  +}
  
  
  
  1.19      +6 -4      cocoon-lenya/src/java/org/apache/lenya/cms/publication/SiteTree.java
  
  Index: SiteTree.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/publication/SiteTree.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- SiteTree.java	18 Sep 2003 11:50:42 -0000	1.18
  +++ SiteTree.java	23 Sep 2003 13:50:40 -0000	1.19
  @@ -231,10 +231,12 @@
   	 * @param subtreeRoot The root of the subtree to import.
   	 * @param newParent The node where the subtree shall be inserted.
   	 * @param newid The new id of the inserted subtreeRoot node (to not overwrite
  +	 * @param refDocumentId The document-id corresponding to the reference node, before which 
  +	 * the subtree should be inserted. If null, the subtree is inserted at the end. 
   	 * in case there is already a node with the same id in the tree).
   	 * @throws SiteTreeException when an error occurs.
   	 */
  -	void importSubtree(SiteTreeNode subtreeRoot, SiteTreeNode newParent, String newid) throws SiteTreeException;
  +	void importSubtree(SiteTreeNode subtreeRoot, SiteTreeNode newParent, String newid, String refDocumentId) throws SiteTreeException;
   
   	/**
   	 * Save the SiteTree.
  
  
  
  1.36      +13 -7     cocoon-lenya/src/java/org/apache/lenya/cms/publication/DefaultSiteTree.java
  
  Index: DefaultSiteTree.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/publication/DefaultSiteTree.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- DefaultSiteTree.java	19 Sep 2003 10:56:55 -0000	1.35
  +++ DefaultSiteTree.java	23 Sep 2003 13:50:40 -0000	1.36
  @@ -367,9 +367,13 @@
   			}
   
               // Add Node 
  -            if (refDocumentId != null){
  +            if (refDocumentId != null && !refDocumentId.equals("")){
   	 			Node nextSibling = getNodeInternal(refDocumentId);
  -				parentNode.insertBefore(child, nextSibling);
  +				if (nextSibling != null) {
  +					parentNode.insertBefore(child, nextSibling);
  +				} else {
  +					parentNode.appendChild(child);
  +				}	
               } else {
   				parentNode.appendChild(child);
               }
  @@ -547,7 +551,8 @@
       public void importSubtree(
           SiteTreeNode newParent,
           SiteTreeNode subtreeRoot,
  -        String newid)
  +        String newid,
  +	    String refDocumentId)
           throws SiteTreeException {
           assert subtreeRoot != null;
           assert newParent != null;
  @@ -562,7 +567,8 @@
               subtreeRoot.getLabels(),
               subtreeRoot.getHref(),
               subtreeRoot.getSuffix(),
  -            subtreeRoot.hasLink());
  +            subtreeRoot.hasLink(),
  +			refDocumentId);
           newParent = this.getNode(parentId + "/" + id);
           if (newParent == null) {
               throw new SiteTreeException(
  @@ -574,7 +580,7 @@
               return;
           } else {
               for (int i = 0; i < children.length; i++) {
  -                importSubtree(newParent, children[i], children[i].getId());
  +                importSubtree(newParent, children[i], children[i].getId(), null);
               }
           }
       }
  
  
  
  1.9       +325 -325  cocoon-lenya/src/test/org/apache/lenya/cms/publication/DefaultSiteTreeTest.java
  
  Index: DefaultSiteTreeTest.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/test/org/apache/lenya/cms/publication/DefaultSiteTreeTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultSiteTreeTest.java	27 Aug 2003 14:45:19 -0000	1.8
  +++ DefaultSiteTreeTest.java	23 Sep 2003 13:50:40 -0000	1.9
  @@ -1,325 +1,325 @@
  -/*
  -$Id$
  -<License>
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Apache Lenya" and  "Apache Software Foundation"  must  not  be
  -    used to  endorse or promote  products derived from  this software without
  -    prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation and was  originally created by
  - Michael Wechner <mi...@apache.org>. For more information on the Apache Soft-
  - ware Foundation, please see <http://www.apache.org/>.
  -
  - Lenya includes software developed by the Apache Software Foundation, W3C,
  - DOM4J Project, BitfluxEditor, Xopus, and WebSHPINX.
  -</License>
  -*/
  - 
  -package org.apache.lenya.cms.publication;
  -
  -import java.io.IOException;
  -
  -import javax.xml.parsers.ParserConfigurationException;
  -import javax.xml.transform.TransformerException;
  -
  -import org.xml.sax.SAXException;
  -
  -import junit.framework.TestCase;
  -
  -/**
  - * 
  - * @author egli
  - * 
  - */
  -public class DefaultSiteTreeTest extends TestCase {
  -	
  -	private DefaultSiteTree siteTree = null;
  -
  -	/**
  -	 * Constructor.
  -	 * @param test The test.
  -	 */
  -	public DefaultSiteTreeTest(String test) {
  -        super(test);
  -    }
  -
  -	/**
  -	 * The main program.
  -	 * The parameters are set from the command line arguments.
  -	 *
  -	 * @param args The command line arguments.
  -	 */
  -	public static void main(String[] args) {
  -        junit.textui.TestRunner.run(DefaultSiteTreeTest.class);
  -    }
  -
  -    /**
  -     * @see TestCase#setUp()
  -     */
  -    protected void setUp() throws Exception {
  -        super.setUp();
  -		siteTree = new DefaultSiteTree("testTree.xml");
  -		Label label = new Label("Foo", "en");
  -		Label[] fooLabels = { label };
  -		siteTree.addNode("/foo", fooLabels, null, null, false);
  -		label = new Label("Home", "en");
  -		Label[] homeLabels = { label };
  -		siteTree.addNode("/index", homeLabels, null, null, false);
  -		label = new Label("Bar", "en");
  -		Label label_de = new Label("Stab", "de");
  -		Label[] barLabels = { label, label_de };
  -		siteTree.addNode("/foo/bar", barLabels, "http://exact.biz", "suffix", true);
  -		label = new Label("Lala", "en");
  -		Label[] lalaLabels = { label };
  -		siteTree.addNode("/foo/lala", lalaLabels, null, null, false);
  -	}
  -
  -    /**
  -     * @see TestCase#tearDown()
  -     */
  -    protected void tearDown() throws Exception {
  -        super.tearDown();
  -    }
  -
  -    /**
  -     * Test for void DefaultSiteTree(String)
  -     */
  -    final public void testDefaultSiteTreeString() {
  -        //TODO Implement DefaultSiteTree().
  -    }
  -
  -    /**
  -     * Test for void DefaultSiteTree(File)
  -     */
  -    final public void testDefaultSiteTreeFile() {
  -        //TODO Implement DefaultSiteTree().
  -    }
  -
  -    /**
  -     * Test for void addNode(String, String, Label[])
  -     * 
  -     * @throws SiteTreeException if an error occurs
  -     */
  -    final public void testAddNodeStringStringLabelArray() throws SiteTreeException {
  -		Label label = new Label("Tutorial", null);
  -		Label[] labels = { label };
  -
  -		siteTree.addNode("/foo", "tutorial", labels);
  -		SiteTreeNode node =  siteTree.getNode("/foo/tutorial");
  -		assertNotNull(node);
  -		assertEquals(node.getId(), "tutorial");
  -    }
  -
  -    /**
  -     * Test for void addNode(SiteTreeNode)
  -     */
  -    final public void testAddNodeSiteTreeNode() {
  -        //TODO Implement addNode().
  -    }
  -
  -    /**
  -     * Test for void addNode(String, Label[], String, String, boolean)
  -     * 
  -     * @throws SiteTreeException if an error occurs
  -     */
  -    final public void testAddNodeStringLabelArrayStringStringboolean() throws SiteTreeException {
  -		Label label1 = new Label("Doh", "en");
  -		Label label2 = new Label("Ding", "en");
  -		Label[] labels = { label1, label2};
  -
  -		siteTree.addNode("/foo/ding", labels, null, null, false);
  -		
  -		assertNotNull(siteTree.getNode("/foo/ding"));
  -		assertEquals(siteTree.getNode("/foo/ding").getId(), "ding");
  -    }
  -
  -    /**
  -     * Test for void addNode(String, String, Label[], String, String, boolean)
  -     * 
  -     * @throws SiteTreeException if an error occurs
  -     */
  -    final public void testAddNodeStringStringLabelArrayStringStringboolean() throws SiteTreeException {
  -		Label label1 = new Label("Doh", "en");
  -		Label label2 = new Label("Ding", "en");
  -		Label[] labels = { label1, label2};
  -
  -		siteTree.addNode("/foo", "baz", labels, null, null, false);
  -		
  -		assertNotNull(siteTree.getNode("/foo/baz"));
  -		assertEquals(siteTree.getNode("/foo/baz").getId(), "baz");		
  -    }
  -
  -	/**
  -	 * Test addLabel
  -	 * 
  -	 * @throws SiteTreeException if an error occurs
  -	 */
  -    final public void testAddLabel() throws SiteTreeException {
  -		Label label = new Label("Tutorial", null);
  -		Label[] labels = null;
  -
  -		siteTree.addLabel("/foo/bar", label);
  -		labels = siteTree.getNode("/foo/bar").getLabels();
  -		assertEquals(labels.length, 3);
  -		label = siteTree.getNode("/foo/bar").getLabel("");
  -		assertNotNull(label);
  -		assertEquals(label.getLabel(), "Tutorial");
  -    }
  -
  -	/**
  -	 * Test removeLabel
  -	 *
  -	 */
  -    final public void testRemoveLabel() {
  -		assertEquals(siteTree.getNode("/foo/bar").getLabels().length, 2);
  -		
  -		Label label = new Label("Stab", "de");
  -		siteTree.removeLabel("/foo/bar", label);
  -		assertEquals(siteTree.getNode("/foo/bar").getLabels().length, 1);
  -		
  -		assertEquals(siteTree.getNode("/foo/bar").getLabels()[0], new Label("Bar", "en"));
  -		
  -		siteTree.addLabel("/foo/bar", label);
  -		assertEquals(siteTree.getNode("/foo/bar").getLabels().length, 2);
  -    }
  -
  -	/**
  -	 * Test removeNode
  -	 * 
  -	 * @throws SiteTreeException if an error occurs
  -	 */
  -    final public void testRemoveNode() throws SiteTreeException {
  -    	Label label1 = new Label("Hi", "en");
  -    	Label label2 = new Label("Ho", "en");
  -    	Label[] labels1 = { label1, label2};
  -    	
  -    	siteTree.addNode("/hi", labels1, null, null, false);
  -
  -		Label[] labels2 = { label1, label2};
  -
  -		siteTree.addNode("/hi/ho", labels2, null, null, false);
  -		
  -		assertNotNull(siteTree.getNode("/hi/ho"));
  -		
  -		siteTree.removeNode("/hi");
  -		
  -		assertNull(siteTree.getNode("/hi/ho"));
  -		assertNull(siteTree.getNode("/hi"));
  -    }
  -
  -	/**
  -	 * Test getNode
  -	 *
  -	 */
  -    final public void testGetNode() {
  -		assertNotNull(siteTree.getNode("/foo/bar"));
  -		
  -		assertNull(siteTree.getNode("/foo/baz"));
  -    }
  -
  -	/**
  -	 * Test save
  -	 *
  -	 */
  -    final public void testSave() {
  -        //TODO Implement save().
  -    }
  -    
  -	/**
  -	 * Test moving a node up
  -	 * 
  -	 * @throws SiteTreeException if an error occurs
  -	 * @throws IOException if an error occurs
  -	 * @throws TransformerException if an error occurs
  -	 */
  -	final public void testMoveUp() throws SiteTreeException, IOException, TransformerException {
  -		siteTree.moveUp("/foo/lala");
  -		siteTree.save();
  -		assertNotNull(siteTree.getNode("/foo/lala"));
  -	}
  -	
  -	/**
  -	 * Test moving a node down
  -	 * 
  -	 * @throws SiteTreeException if an error occurs
  -	 * @throws IOException if an error occurs
  -	 * @throws TransformerException if an error occurs
  -	 */
  -	final public void testMoveDown() throws SiteTreeException, IOException, TransformerException {
  -		siteTree.moveDown("/foo");
  -		siteTree.save();
  -		assertNotNull(siteTree.getNode("/foo"));
  -	}
  -    
  -    /**
  -     * Test the import of a subtree
  -     * 
  -     * @throws ParserConfigurationException if an error occurs.
  -     * @throws SAXException if an error occurs.
  -     * @throws SiteTreeException if an error occurs.
  -     * @throws IOException if an error occurs.
  -     * @throws TransformerException if an error occurs.
  -     */
  -	final public void testImportSubtree() throws ParserConfigurationException, SAXException, SiteTreeException, IOException, TransformerException {
  -		DefaultSiteTree newSiteTree = new DefaultSiteTree("importedTree.xml");
  -		Label label = new Label("root", "en");
  -		Label[] rootLabels = { label };
  -		newSiteTree.addNode("/root", rootLabels, null, null, false);
  -		label = new Label("foo", "en");
  -		Label[] fooLabels = { label };
  -		newSiteTree.addNode("/root/foo", fooLabels, null, null, false);
  -		label = new Label("subtree", "en");
  -		Label[] subtreeLabels = { label };
  -		newSiteTree.addNode("/root/subtree", subtreeLabels, "http://exact.biz", "suffix", true);
  -		label = new Label("child", "en");
  -		Label[] childLabels = { label };
  -		newSiteTree.addNode("/root/subtree/child", childLabels, null, null, false);
  -		SiteTreeNode node=newSiteTree.getNode("/root/subtree");
  -		assertNotNull(node);
  -		SiteTreeNode parentNode=siteTree.getNode("/foo/lala");
  -		assertNotNull(parentNode);
  -        siteTree.importSubtree(parentNode,node, "subtree");
  -		siteTree.save();
  -		assertNotNull(siteTree.getNode("/foo/lala/subtree"));
  -		assertNotNull(siteTree.getNode("/foo/lala/subtree/child"));
  -	}
  -}
  +/*
  +$Id$
  +<License>
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Apache Lenya" and  "Apache Software Foundation"  must  not  be
  +    used to  endorse or promote  products derived from  this software without
  +    prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation and was  originally created by
  + Michael Wechner <mi...@apache.org>. For more information on the Apache Soft-
  + ware Foundation, please see <http://www.apache.org/>.
  +
  + Lenya includes software developed by the Apache Software Foundation, W3C,
  + DOM4J Project, BitfluxEditor, Xopus, and WebSHPINX.
  +</License>
  +*/
  + 
  +package org.apache.lenya.cms.publication;
  +
  +import java.io.IOException;
  +
  +import javax.xml.parsers.ParserConfigurationException;
  +import javax.xml.transform.TransformerException;
  +
  +import org.xml.sax.SAXException;
  +
  +import junit.framework.TestCase;
  +
  +/**
  + * 
  + * @author egli
  + * 
  + */
  +public class DefaultSiteTreeTest extends TestCase {
  +	
  +	private DefaultSiteTree siteTree = null;
  +
  +	/**
  +	 * Constructor.
  +	 * @param test The test.
  +	 */
  +	public DefaultSiteTreeTest(String test) {
  +        super(test);
  +    }
  +
  +	/**
  +	 * The main program.
  +	 * The parameters are set from the command line arguments.
  +	 *
  +	 * @param args The command line arguments.
  +	 */
  +	public static void main(String[] args) {
  +        junit.textui.TestRunner.run(DefaultSiteTreeTest.class);
  +    }
  +
  +    /**
  +     * @see TestCase#setUp()
  +     */
  +    protected void setUp() throws Exception {
  +        super.setUp();
  +		siteTree = new DefaultSiteTree("testTree.xml");
  +		Label label = new Label("Foo", "en");
  +		Label[] fooLabels = { label };
  +		siteTree.addNode("/foo", fooLabels, null, null, false);
  +		label = new Label("Home", "en");
  +		Label[] homeLabels = { label };
  +		siteTree.addNode("/index", homeLabels, null, null, false);
  +		label = new Label("Bar", "en");
  +		Label label_de = new Label("Stab", "de");
  +		Label[] barLabels = { label, label_de };
  +		siteTree.addNode("/foo/bar", barLabels, "http://exact.biz", "suffix", true);
  +		label = new Label("Lala", "en");
  +		Label[] lalaLabels = { label };
  +		siteTree.addNode("/foo/lala", lalaLabels, null, null, false);
  +	}
  +
  +    /**
  +     * @see TestCase#tearDown()
  +     */
  +    protected void tearDown() throws Exception {
  +        super.tearDown();
  +    }
  +
  +    /**
  +     * Test for void DefaultSiteTree(String)
  +     */
  +    final public void testDefaultSiteTreeString() {
  +        //TODO Implement DefaultSiteTree().
  +    }
  +
  +    /**
  +     * Test for void DefaultSiteTree(File)
  +     */
  +    final public void testDefaultSiteTreeFile() {
  +        //TODO Implement DefaultSiteTree().
  +    }
  +
  +    /**
  +     * Test for void addNode(String, String, Label[])
  +     * 
  +     * @throws SiteTreeException if an error occurs
  +     */
  +    final public void testAddNodeStringStringLabelArray() throws SiteTreeException {
  +		Label label = new Label("Tutorial", null);
  +		Label[] labels = { label };
  +
  +		siteTree.addNode("/foo", "tutorial", labels);
  +		SiteTreeNode node =  siteTree.getNode("/foo/tutorial");
  +		assertNotNull(node);
  +		assertEquals(node.getId(), "tutorial");
  +    }
  +
  +    /**
  +     * Test for void addNode(SiteTreeNode)
  +     */
  +    final public void testAddNodeSiteTreeNode() {
  +        //TODO Implement addNode().
  +    }
  +
  +    /**
  +     * Test for void addNode(String, Label[], String, String, boolean)
  +     * 
  +     * @throws SiteTreeException if an error occurs
  +     */
  +    final public void testAddNodeStringLabelArrayStringStringboolean() throws SiteTreeException {
  +		Label label1 = new Label("Doh", "en");
  +		Label label2 = new Label("Ding", "en");
  +		Label[] labels = { label1, label2};
  +
  +		siteTree.addNode("/foo/ding", labels, null, null, false);
  +		
  +		assertNotNull(siteTree.getNode("/foo/ding"));
  +		assertEquals(siteTree.getNode("/foo/ding").getId(), "ding");
  +    }
  +
  +    /**
  +     * Test for void addNode(String, String, Label[], String, String, boolean)
  +     * 
  +     * @throws SiteTreeException if an error occurs
  +     */
  +    final public void testAddNodeStringStringLabelArrayStringStringboolean() throws SiteTreeException {
  +		Label label1 = new Label("Doh", "en");
  +		Label label2 = new Label("Ding", "en");
  +		Label[] labels = { label1, label2};
  +
  +		siteTree.addNode("/foo", "baz", labels, null, null, false);
  +		
  +		assertNotNull(siteTree.getNode("/foo/baz"));
  +		assertEquals(siteTree.getNode("/foo/baz").getId(), "baz");		
  +    }
  +
  +	/**
  +	 * Test addLabel
  +	 * 
  +	 * @throws SiteTreeException if an error occurs
  +	 */
  +    final public void testAddLabel() throws SiteTreeException {
  +		Label label = new Label("Tutorial", null);
  +		Label[] labels = null;
  +
  +		siteTree.addLabel("/foo/bar", label);
  +		labels = siteTree.getNode("/foo/bar").getLabels();
  +		assertEquals(labels.length, 3);
  +		label = siteTree.getNode("/foo/bar").getLabel("");
  +		assertNotNull(label);
  +		assertEquals(label.getLabel(), "Tutorial");
  +    }
  +
  +	/**
  +	 * Test removeLabel
  +	 *
  +	 */
  +    final public void testRemoveLabel() {
  +		assertEquals(siteTree.getNode("/foo/bar").getLabels().length, 2);
  +		
  +		Label label = new Label("Stab", "de");
  +		siteTree.removeLabel("/foo/bar", label);
  +		assertEquals(siteTree.getNode("/foo/bar").getLabels().length, 1);
  +		
  +		assertEquals(siteTree.getNode("/foo/bar").getLabels()[0], new Label("Bar", "en"));
  +		
  +		siteTree.addLabel("/foo/bar", label);
  +		assertEquals(siteTree.getNode("/foo/bar").getLabels().length, 2);
  +    }
  +
  +	/**
  +	 * Test removeNode
  +	 * 
  +	 * @throws SiteTreeException if an error occurs
  +	 */
  +    final public void testRemoveNode() throws SiteTreeException {
  +    	Label label1 = new Label("Hi", "en");
  +    	Label label2 = new Label("Ho", "en");
  +    	Label[] labels1 = { label1, label2};
  +    	
  +    	siteTree.addNode("/hi", labels1, null, null, false);
  +
  +		Label[] labels2 = { label1, label2};
  +
  +		siteTree.addNode("/hi/ho", labels2, null, null, false);
  +		
  +		assertNotNull(siteTree.getNode("/hi/ho"));
  +		
  +		siteTree.removeNode("/hi");
  +		
  +		assertNull(siteTree.getNode("/hi/ho"));
  +		assertNull(siteTree.getNode("/hi"));
  +    }
  +
  +	/**
  +	 * Test getNode
  +	 *
  +	 */
  +    final public void testGetNode() {
  +		assertNotNull(siteTree.getNode("/foo/bar"));
  +		
  +		assertNull(siteTree.getNode("/foo/baz"));
  +    }
  +
  +	/**
  +	 * Test save
  +	 *
  +	 */
  +    final public void testSave() {
  +        //TODO Implement save().
  +    }
  +    
  +	/**
  +	 * Test moving a node up
  +	 * 
  +	 * @throws SiteTreeException if an error occurs
  +	 * @throws IOException if an error occurs
  +	 * @throws TransformerException if an error occurs
  +	 */
  +	final public void testMoveUp() throws SiteTreeException, IOException, TransformerException {
  +		siteTree.moveUp("/foo/lala");
  +		siteTree.save();
  +		assertNotNull(siteTree.getNode("/foo/lala"));
  +	}
  +	
  +	/**
  +	 * Test moving a node down
  +	 * 
  +	 * @throws SiteTreeException if an error occurs
  +	 * @throws IOException if an error occurs
  +	 * @throws TransformerException if an error occurs
  +	 */
  +	final public void testMoveDown() throws SiteTreeException, IOException, TransformerException {
  +		siteTree.moveDown("/foo");
  +		siteTree.save();
  +		assertNotNull(siteTree.getNode("/foo"));
  +	}
  +    
  +    /**
  +     * Test the import of a subtree
  +     * 
  +     * @throws ParserConfigurationException if an error occurs.
  +     * @throws SAXException if an error occurs.
  +     * @throws SiteTreeException if an error occurs.
  +     * @throws IOException if an error occurs.
  +     * @throws TransformerException if an error occurs.
  +     */
  +	final public void testImportSubtree() throws ParserConfigurationException, SAXException, SiteTreeException, IOException, TransformerException {
  +		DefaultSiteTree newSiteTree = new DefaultSiteTree("importedTree.xml");
  +		Label label = new Label("root", "en");
  +		Label[] rootLabels = { label };
  +		newSiteTree.addNode("/root", rootLabels, null, null, false);
  +		label = new Label("foo", "en");
  +		Label[] fooLabels = { label };
  +		newSiteTree.addNode("/root/foo", fooLabels, null, null, false);
  +		label = new Label("subtree", "en");
  +		Label[] subtreeLabels = { label };
  +		newSiteTree.addNode("/root/subtree", subtreeLabels, "http://exact.biz", "suffix", true);
  +		label = new Label("child", "en");
  +		Label[] childLabels = { label };
  +		newSiteTree.addNode("/root/subtree/child", childLabels, null, null, false);
  +		SiteTreeNode node=newSiteTree.getNode("/root/subtree");
  +		assertNotNull(node);
  +		SiteTreeNode parentNode=siteTree.getNode("/foo/lala");
  +		assertNotNull(parentNode);
  +        siteTree.importSubtree(parentNode,node, "subtree", null);
  +		siteTree.save();
  +		assertNotNull(siteTree.getNode("/foo/lala/subtree"));
  +		assertNotNull(siteTree.getNode("/foo/lala/subtree/child"));
  +	}
  +}
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org