From: <jbo...@li...> - 2005-12-08 22:23:06
|
Author: adamw Date: 2005-12-08 17:22:54 -0500 (Thu, 08 Dec 2005) New Revision: 1749 Added: trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/CopyMoveTest.java Modified: trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/Resource.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnMemDirectory.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnMemNode.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/operations/DeleteOperation.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/test/StandaloneTest.java trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/PropertiesTest.java Log: http://jira.jboss.com/jira/browse/JBSHOTOKU-40 http://jira.jboss.com/jira/browse/JBSHOTOKU-13 http://jira.jboss.com/jira/browse/JBSHOTOKU-43 Tests + bug fixes Modified: trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/Resource.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/Resource.java 2005-12-08 20:31:17 UTC (rev 1748) +++ trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/Resource.java 2005-12-08 22:22:54 UTC (rev 1749) @@ -37,7 +37,8 @@ */ public interface Resource { /** - * Copies this resource to the given directory. + * Copies this resource to the given directory. This can't be called if + * this resource is new and not yet saved. * * @param dir * Directory to copy this resource to. This can't be a new and @@ -52,7 +53,9 @@ String logMessage) throws CopyException; /** - * Moves this resource to the given directory. + * Moves this resource to the given directory. This can't be called if + * this resource is new and not yet saved. This resource should not be + * used after performing this operation. * * @param dir * Directory to move this resource to. This can't be a new and @@ -121,7 +124,8 @@ /** * Deletes this node or directory (immediately, no <code>save()</code> is - * needed). This node should not be used after performing this operation. + * needed). This resource should not be used after performing this + * operation. * * @throws DeleteException * @throws RepositoryException Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnMemDirectory.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnMemDirectory.java 2005-12-08 20:31:17 UTC (rev 1748) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnMemDirectory.java 2005-12-08 22:22:54 UTC (rev 1749) @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.Map; +import org.jboss.shotoku.Directory; import org.jboss.shotoku.exceptions.RepositoryException; import org.jboss.shotoku.exceptions.ResourceAlreadyExists; import org.jboss.shotoku.svn.SvnContentManager.ExistsType; @@ -154,16 +155,28 @@ // saved. } + @Override public SvnNode newNode(String name) throws ResourceAlreadyExists { return newNode(basePath, Tools.concatenatePaths(newPath, name)); } + @Override public SvnDirectory newDirectory(String name) throws ResourceAlreadyExists { return newDirectory(basePath, Tools.concatenatePaths(newPath, name)); } @Override + public void moveTo(Directory dir, String logMessage) { + throw new RepositoryException("Resource not yet saved!"); + } + + @Override + public void copyTo(Directory dir, String newName, String logMessage) { + throw new RepositoryException("Resource not yet saved!"); + } + + @Override public void setIndex(String propertyName, boolean index) { throw new RepositoryException("Directory not yet saved."); } Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnMemNode.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnMemNode.java 2005-12-08 20:31:17 UTC (rev 1748) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnMemNode.java 2005-12-08 22:22:54 UTC (rev 1749) @@ -26,6 +26,8 @@ import java.util.HashMap; import java.util.Map; +import org.jboss.shotoku.Directory; +import org.jboss.shotoku.exceptions.RepositoryException; import org.jboss.shotoku.svn.SvnContentManager.ExistsType; import org.jboss.shotoku.svn.content.NodeContent; import org.jboss.shotoku.svn.operations.AddDirectoryOperation; @@ -149,6 +151,16 @@ * Node IMPLEMENTATION */ + @Override + public void moveTo(Directory dir, String logMessage) { + throw new RepositoryException("Resource not yet saved!"); + } + + @Override + public void copyTo(Directory dir, String newName, String logMessage) { + throw new RepositoryException("Resource not yet saved!"); + } + public long getLastModification() { // This node is brand new - so modified "now". return Calendar.getInstance().getTimeInMillis(); Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/operations/DeleteOperation.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/operations/DeleteOperation.java 2005-12-08 20:31:17 UTC (rev 1748) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/operations/DeleteOperation.java 2005-12-08 22:22:54 UTC (rev 1749) @@ -47,6 +47,6 @@ public void addModifiedPaths(SvnService service) { service.addDirectoryToModfied(id, parentPath); - service.addNodeToModfied(id, path); + service.addToDeleted(id, path); } } Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/test/StandaloneTest.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/test/StandaloneTest.java 2005-12-08 20:31:17 UTC (rev 1748) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/test/StandaloneTest.java 2005-12-08 22:22:54 UTC (rev 1749) @@ -416,15 +416,43 @@ } } + public static void testCopy() throws Exception { + try { + Directory parent = cm.getRootDirectory().newDirectory(TEST_DIR); + Directory dir1 = parent.newDirectory("dir1"); + Directory dir2 = parent.newDirectory("dir2"); + Node n1 = dir1.newNode("node1"); + n1.setContent(TEST_CONTENT); + + cm.save(parent, dir1, dir2, n1, "setup"); + + Node original = cm.getNode(TEST_DIR + "/dir1/node1"); + original.copyTo(cm.getDirectory(TEST_DIR + "/dir2"), "node2", "copy-node"); + + System.out.println(TEST_CONTENT.equals(original.getContent())); + System.out.println(TEST_CONTENT.equals(cm.getNode(TEST_DIR + "/dir2/node2").getContent())); + /* + // Waiting for a WC update. + Thread.sleep(1000 * 20); + + System.out.println(TEST_CONTENT.equals(cm.getNode(TEST_DIR + "/dir1/node1").getContent())); + System.out.println(TEST_CONTENT.equals(cm.getNode(TEST_DIR + "/dir2/node2").getContent()));*/ + } finally { + try { + cm.getDirectory(TEST_DIR).delete(); + } catch (ResourceDoesNotExist e) { + + } + } + } + public static void main(String[] argv) throws Exception { long now = Calendar.getInstance().getTimeInMillis(); ContentManager.setup(); cm = ContentManager.getContentManager("shotoku-test"); - Directory d = cm.getDirectory("dir1/dir3"); - d.moveTo(cm.getDirectory("test2/test3"), "yyy"); - + testCopy(); //multiSaveTest(); //testInject(); //testNested(); Added: trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/CopyMoveTest.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/CopyMoveTest.java 2005-12-08 20:31:17 UTC (rev 1748) +++ trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/CopyMoveTest.java 2005-12-08 22:22:54 UTC (rev 1749) @@ -0,0 +1,132 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.shotoku.test; + +import org.jboss.shotoku.Directory; +import org.jboss.shotoku.Node; +import org.jboss.shotoku.exceptions.ResourceAlreadyExists; +import org.jboss.shotoku.exceptions.ResourceDoesNotExist; + +/** + * + * @author Adam Warski (ad...@as...) + */ +public class CopyMoveTest extends ShotokuTest { + private final static String TEST_DIR = "copy-move-test"; + private final static String TEST_CONTENT = "test content"; + + @Override + protected void setUp() throws Exception { + Directory parent = cm.getRootDirectory().newDirectory(TEST_DIR); + Directory dir1 = parent.newDirectory("dir1"); + Directory dir2 = parent.newDirectory("dir2"); + Node n1 = dir1.newNode("node1"); + n1.setContent(TEST_CONTENT); + + cm.save(parent, dir1, dir2, n1, "setup"); + } + + public void testNodeCopy() throws Exception { + Node original = cm.getNode(TEST_DIR + "/dir1/node1"); + original.copyTo(cm.getDirectory(TEST_DIR + "/dir2"), "node2", "copy-node"); + + assertTrue(TEST_CONTENT.equals(original.getContent())); + assertTrue(TEST_CONTENT.equals(cm.getNode(TEST_DIR + "/dir2/node2").getContent())); + + // Waiting for a WC update. + Thread.sleep(1000 * 20); + + assertTrue(TEST_CONTENT.equals(cm.getNode(TEST_DIR + "/dir1/node1").getContent())); + assertTrue(TEST_CONTENT.equals(cm.getNode(TEST_DIR + "/dir2/node2").getContent())); + } + + public void testNodeMove() throws Exception { + Node original = cm.getNode(TEST_DIR + "/dir1/node1"); + original.moveTo(cm.getDirectory(TEST_DIR + "/dir2"), "move-node"); + + // The old node shouldn't exist. + try { + cm.getNode(TEST_DIR + "/dir1/node1"); + fail("A node which shouldn't exist - does"); + } catch (ResourceDoesNotExist e) { + + } + + assertTrue(TEST_CONTENT.equals(cm.getNode(TEST_DIR + "/dir2/node1").getContent())); + + // Waiting for a WC update. + Thread.sleep(1000 * 20); + + try { + cm.getNode(TEST_DIR + "/dir1/node1"); + fail("A node which shouldn't exist - does"); + } catch (ResourceDoesNotExist e) { + + } + assertTrue(TEST_CONTENT.equals(cm.getNode(TEST_DIR + "/dir2/node1").getContent())); + } + + public void testDirectoryCopy() throws Exception { + Directory original = cm.getDirectory(TEST_DIR + "/dir1"); + original.copyTo(cm.getDirectory(TEST_DIR + "/dir2"), "dir3", "copy-dir"); + + assertTrue(TEST_CONTENT.equals(cm.getNode(TEST_DIR + "/dir2/dir3/node1").getContent())); + + // Waiting for a WC update. + Thread.sleep(1000 * 20); + + assertTrue(TEST_CONTENT.equals(cm.getNode(TEST_DIR + "/dir2/dir3/node1").getContent())); + } + + public void testDirectoryMove() throws Exception { + Directory original = cm.getDirectory(TEST_DIR + "/dir1"); + original.moveTo(cm.getDirectory(TEST_DIR + "/dir2"), "move-dir"); + + try { + cm.getDirectory(TEST_DIR + "/dir1"); + fail("A directory which shouldn't exist - does"); + } catch (ResourceDoesNotExist e) { + + } + assertTrue(TEST_CONTENT.equals(cm.getNode(TEST_DIR + "/dir2/dir1/node1").getContent())); + + // Waiting for a WC update. + Thread.sleep(1000 * 20); + + try { + cm.getDirectory(TEST_DIR + "/dir1"); + fail("A directory which shouldn't exist - does"); + } catch (ResourceDoesNotExist e) { + + } + assertTrue(TEST_CONTENT.equals(cm.getNode(TEST_DIR + "/dir2/dir1/node1").getContent())); + } + + @Override + protected void tearDown() throws ResourceAlreadyExists, ResourceDoesNotExist { + try { + cm.getDirectory(TEST_DIR).delete(); + } catch (ResourceDoesNotExist e) { + + } + } +} Modified: trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/PropertiesTest.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/PropertiesTest.java 2005-12-08 20:31:17 UTC (rev 1748) +++ trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/PropertiesTest.java 2005-12-08 22:22:54 UTC (rev 1749) @@ -21,6 +21,8 @@ */ package org.jboss.shotoku.test; +import java.util.Map; + import org.jboss.shotoku.Node; import org.jboss.shotoku.exceptions.RepositoryException; import org.jboss.shotoku.exceptions.ResourceAlreadyExists; @@ -89,6 +91,31 @@ PROP_NAME))); } + private void checkProperties(Node n) { + Map<String, String> props = n.getAllProperties(); + + assertTrue(3 == props.size()); + assertTrue("v1".equals(props.get("p1"))); + assertTrue("v2".equals(props.get("p2"))); + assertTrue("v3".equals(props.get("p3"))); + } + + public void testGetAllProperties() throws Exception { + Node n = cm.getNode(TEST_FILE); + + n.setProperty("p1", "v1"); + n.setProperty("p2", "v2"); + n.setProperty("p3", "v3"); + n.save("a"); + + checkProperties(n); + + // Waiting for a WC update. + Thread.sleep(1000 * 20); + checkProperties(n); + checkProperties(cm.getNode(TEST_FILE)); + } + @Override protected void tearDown() throws ResourceAlreadyExists, ResourceDoesNotExist { cm.getNode(TEST_FILE).delete(); |