You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ed...@apache.org on 2005/08/11 20:06:07 UTC
svn commit: r231495 [7/7] - in
/incubator/jackrabbit/trunk/contrib/jcr-commands: ./ applications/test/
applications/test/fs/ applications/test/fs/dummy folder/ benchmarking/
src/java/ src/java/org/apache/jackrabbit/chain/
src/java/org/apache/jackrabbit...
Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/CliTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/CliTest.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/CliTest.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/CliTest.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.chain.test;
+
+import javax.jcr.Node;
+
+import org.apache.jackrabbit.chain.CtxHelper;
+import org.apache.jackrabbit.chain.cli.JcrParser;
+
+/**
+ * Command line interfaces tests
+ */
+public class CliTest extends AbstractCommandTest
+{
+ JcrParser parser = new JcrParser();
+
+ Node testNode;
+
+ /** execute the given command */
+ private void execute(String input) throws Exception
+ {
+ parser.parse(input);
+
+ // populate ctx
+ parser.populateContext(ctx);
+
+ // Execute command
+ long start = System.currentTimeMillis();
+ parser.getCommand().execute(ctx);
+ long elapsed = System.currentTimeMillis() - start;
+
+ // depopulate ctx
+ parser.dePopulateContext(ctx);
+ }
+
+ public void testAddMixin() throws Exception
+ {
+ execute("addmixin test mix:referenceable");
+ assertTrue(testNode.isNodeType("mix:referenceable"));
+ }
+
+ public void testAddNode() throws Exception
+ {
+ CtxHelper.setCurrentNode(ctx, testNode);
+ execute("addnode mynode");
+ assertTrue(testNode.hasNode("mynode"));
+ }
+
+ public void testCopy() throws Exception
+ {
+ getRoot().save();
+ execute("copy test /test2");
+ assertTrue(getRoot().hasNode("test2"));
+ }
+
+ public void testCd() throws Exception
+ {
+ execute("cd test");
+ assertTrue(CtxHelper.getCurrentNode(ctx).isSame(testNode));
+ }
+
+ public void testMove() throws Exception
+ {
+ execute("move test /test2");
+ assertFalse(getRoot().hasNode("test"));
+ assertTrue(getRoot().hasNode("test2"));
+ }
+
+ public void testRefresh() throws Exception
+ {
+ testNode.remove();
+ assertFalse(getRoot().hasNode("test"));
+ execute("refresh");
+ assertTrue(getRoot().hasNode("test"));
+ }
+
+ public void testRemoveItem() throws Exception
+ {
+ assertTrue(getRoot().hasNode("test"));
+ execute("remove test");
+ assertFalse(getRoot().hasNode("test"));
+ }
+
+ public void testRemoveItems() throws Exception
+ {
+ getRoot().addNode("test2");
+ assertTrue(getRoot().hasNode("test"));
+ assertTrue(getRoot().hasNode("test2"));
+ execute("removeitems test*");
+ assertFalse(getRoot().hasNode("test"));
+ assertFalse(getRoot().hasNode("test2"));
+ }
+
+ public void testRemoveMixin() throws Exception
+ {
+ testNode.addMixin("mix:referenceable");
+ assertTrue(testNode.isNodeType("mix:referenceable"));
+ execute("removemixin test mix:referenceable");
+ assertFalse(testNode.isNodeType("mix:referenceable"));
+ }
+
+ public void testRename() throws Exception
+ {
+ execute("rename test test2");
+ assertFalse(getRoot().hasNode("test"));
+ assertTrue(getRoot().hasNode("test2"));
+ }
+
+ public void testSetMultivalueProperty() throws Exception
+ {
+ // Comma separated
+ execute("setmultivalueproperty multiprop \"prop1,prop2\" -regexp ,");
+ assertTrue(getRoot().hasProperty("multiprop"));
+ assertTrue(getRoot().getProperty("multiprop").getValues()[0]
+ .getString().equals("prop1"));
+ assertTrue(getRoot().getProperty("multiprop").getValues()[1]
+ .getString().equals("prop2"));
+
+ // Semicolon separated
+ execute("setmultivalueproperty multiprop \"prop1;prop2\" -regexp ;");
+ assertTrue(getRoot().hasProperty("multiprop"));
+ assertTrue(getRoot().getProperty("multiprop").getValues()[0]
+ .getString().equals("prop1"));
+ assertTrue(getRoot().getProperty("multiprop").getValues()[1]
+ .getString().equals("prop2"));
+ }
+
+ public void testSetProperty() throws Exception
+ {
+ execute("setproperty myprop myvalue");
+ assertFalse(getRoot().hasNode("myprop"));
+ assertTrue(getRoot().getProperty("myprop").getValue().getString()
+ .equals("myvalue"));
+ }
+
+ /**
+ * @inheritDoc
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ testNode = CtxHelper.getCurrentNode(ctx).addNode("test");
+ }
+}
Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/CliTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/CommandsTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/CommandsTest.java?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/CommandsTest.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/CommandsTest.java Thu Aug 11 11:04:29 2005
@@ -0,0 +1,345 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.chain.test;
+
+import java.io.File;
+import java.util.Iterator;
+
+import javax.jcr.Node;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.collections.IteratorUtils;
+import org.apache.jackrabbit.chain.CtxHelper;
+
+/**
+ * Commands tests
+ */
+public class CommandsTest extends AbstractCommandTest
+{
+
+ /**
+ * Tests AddNode
+ *
+ * @throws Exception
+ */
+ public void testAddNode() throws Exception
+ {
+ this.testAddNode(catalog.getCommand("addTestNode"));
+ }
+
+ /**
+ * Tests AddNode with context attributes
+ *
+ * @throws Exception
+ */
+ public void testAddNodeWithKey() throws Exception
+ {
+ this.testAddNode(catalog.getCommand("addTestNodeWithKey"));
+ }
+
+ private void testAddNode(Command cmd) throws Exception
+ {
+ Node n = CtxHelper.getCurrentNode(ctx);
+ assertFalse(n.hasNode("test"));
+ cmd.execute(ctx);
+ assertTrue(n.hasNode("test"));
+ }
+
+ /**
+ * Tests ClearWorkspace
+ *
+ * @throws Exception
+ */
+ public void testClearWorkspace() throws Exception
+ {
+ Node n = CtxHelper.getCurrentNode(ctx);
+ assertFalse(n.hasNode("test"));
+ catalog.getCommand("addTestNode").execute(ctx);
+ assertTrue(n.hasNode("test"));
+ clear();
+ assertFalse(n.hasNode("test"));
+ }
+
+ /**
+ * Tests ClearWorkspace
+ *
+ * @throws Exception
+ */
+ public void testCollect() throws Exception
+ {
+ Node n = CtxHelper.getCurrentNode(ctx);
+ // Add node
+ assertFalse(n.hasNode("test"));
+ addTestNode();
+ assertTrue(n.hasNode("test"));
+ // Collect
+ assertFalse(ctx.get("children") != null);
+ catalog.getCommand("collect").execute(ctx);
+ assertTrue(ctx.get("children") != null);
+ assertTrue(ctx.get("children") != null);
+ int length = IteratorUtils.toArray((Iterator) ctx.get("children")).length;
+ assertTrue(length == 2);
+ }
+
+ /**
+ * Tests CD
+ *
+ * @throws Exception
+ */
+ public void testCd() throws Exception
+ {
+ this.testCd(catalog.getCommand("cd"));
+ }
+
+ /**
+ * Tests CD with key
+ *
+ * @throws Exception
+ */
+ public void testCdWithKey() throws Exception
+ {
+ this.testCd(catalog.getCommand("cdWithKey"));
+ }
+
+ private void testCd(Command cmd) throws Exception
+ {
+ Node n = CtxHelper.getCurrentNode(ctx);
+ addTestNode();
+ assertTrue(n.getPath().equals("/"));
+ // cd
+ cmd.execute(ctx);
+ n = CtxHelper.getCurrentNode(ctx);
+ assertTrue(n.getPath().equals("/test"));
+ }
+
+ private void clear() throws Exception
+ {
+ catalog.getCommand("clear").execute(ctx);
+ }
+
+ /**
+ * Tests Export Doc
+ *
+ * @throws Exception
+ */
+ public void testExportDoc() throws Exception
+ {
+ testExport(catalog.getCommand("exportDoc"));
+ }
+
+ /**
+ * Tests Export Doc
+ *
+ * @throws Exception
+ */
+ public void testExportDocWithKey() throws Exception
+ {
+ testExport(catalog.getCommand("exportDocWithKey"));
+ }
+
+ /**
+ * Tests Export Sys
+ *
+ * @throws Exception
+ */
+ public void testExportSys() throws Exception
+ {
+ testExport(catalog.getCommand("exportSys"));
+ }
+
+ /**
+ * Tests Export Sys with Key
+ *
+ * @throws Exception
+ */
+ public void testExportSysWithKey() throws Exception
+ {
+ testExport(catalog.getCommand("exportSysWithKey"));
+ }
+
+ private void testExport(Command cmd) throws Exception
+ {
+ File f = new File("applications/test/export.xml");
+ if (f.exists())
+ {
+ f.delete();
+ }
+ assertFalse(f.exists());
+ Node n = CtxHelper.getCurrentNode(ctx);
+ CtxHelper.setCurrentNode(ctx, n.addNode("test"));
+ cmd.execute(ctx);
+ assertTrue(f.exists());
+ f.delete();
+ assertFalse(f.exists());
+ }
+
+ /**
+ * Tests read value
+ *
+ * @throws Exception
+ */
+ public void testRead() throws Exception
+ {
+ catalog.getCommand("read").execute(ctx);
+ assertTrue(ctx.get("value").equals("rep:root"));
+ }
+
+ /**
+ * Tests read value with key
+ *
+ * @throws Exception
+ */
+ public void testReadWithKey() throws Exception
+ {
+ catalog.getCommand("readWithKey").execute(ctx);
+ assertTrue(ctx.get("value").equals("rep:root"));
+ }
+
+ /**
+ * Tests remove
+ *
+ * @throws Exception
+ */
+ public void testRemove() throws Exception
+ {
+ testRemove(catalog.getCommand("remove"));
+ }
+
+ /**
+ * Tests remove with key
+ *
+ * @throws Exception
+ */
+ public void testRemoveWithKey() throws Exception
+ {
+ testRemove(catalog.getCommand("removeWithKey"));
+ }
+
+ /**
+ * Tests remove items
+ *
+ * @throws Exception
+ */
+ public void testRemoveItems() throws Exception
+ {
+ testRemove(catalog.getCommand("removeItems"));
+ }
+
+ /**
+ * Tests remove items with key
+ *
+ * @throws Exception
+ */
+ public void testRemoveItemsWithKey() throws Exception
+ {
+ testRemove(catalog.getCommand("removeItemsWithKey"));
+ }
+
+ private void testRemove(Command cmd) throws Exception
+ {
+ Node n = CtxHelper.getCurrentNode(ctx);
+ assertFalse(n.hasNode("test"));
+ n.addNode("test");
+ assertTrue(n.hasNode("test"));
+ cmd.execute(ctx);
+ assertFalse(n.hasNode("test"));
+ }
+
+ private void testSetProp(Command cmd) throws Exception
+ {
+ Node n = CtxHelper.getCurrentNode(ctx);
+ assertFalse(n.hasProperty("testProp"));
+ cmd.execute(ctx);
+ assertTrue(n.hasProperty("testProp"));
+ // TODO: .trim() is only for xxxfromfile, remove it
+ assertTrue(n.getProperty("testProp").getValue().getString().trim()
+ .equals("testValue"));
+ }
+
+ /**
+ * Tests set property
+ *
+ * @throws Exception
+ */
+ public void testSetProp() throws Exception
+ {
+ testSetProp(catalog.getCommand("setProp"));
+ }
+
+ /**
+ * Tests remove items with key
+ *
+ * @throws Exception
+ */
+ public void testSetPropWithKey() throws Exception
+ {
+ testSetProp(catalog.getCommand("setPropWithKey"));
+ }
+
+ /**
+ * Tests set property from file
+ *
+ * @throws Exception
+ */
+ public void testSetPropFromFile() throws Exception
+ {
+ testSetProp(catalog.getCommand("setPropFromFile"));
+ }
+
+ /**
+ * Tests remove items with key
+ *
+ * @throws Exception
+ */
+ public void testSetPropFromFileWithKey() throws Exception
+ {
+ testSetProp(catalog.getCommand("setPropFromFileWithKey"));
+ }
+
+ /**
+ * Tests set property from file
+ *
+ * @throws Exception
+ */
+ public void testSetMultiProp() throws Exception
+ {
+ testSetMultiProp(catalog.getCommand("setMultiProp"));
+ }
+
+ /**
+ * Tests remove items with key
+ *
+ * @throws Exception
+ */
+ public void testSetMultiWithKey() throws Exception
+ {
+ testSetMultiProp(catalog.getCommand("setMultiPropWithKey"));
+ }
+
+ private void testSetMultiProp(Command cmd) throws Exception
+ {
+ Node n = CtxHelper.getCurrentNode(ctx);
+ assertFalse(n.hasProperty("testProp"));
+ cmd.execute(ctx);
+ assertTrue(n.hasProperty("testProp"));
+ assertTrue(n.getProperty("testProp").getValues()[0].getString().equals(
+ "testValue"));
+ assertTrue(n.getProperty("testProp").getValues()[1].getString().equals(
+ "testValue1"));
+ }
+
+}
Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/CommandsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/chains.xml
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/chains.xml?rev=231495&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/chains.xml (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/chains.xml Thu Aug 11 11:04:29 2005
@@ -0,0 +1,210 @@
+<?xml version="1.0" ?>
+<chains>
+ <catalog name="test">
+
+ <command name="clear"
+ className="org.apache.jackrabbit.chain.command.ClearWorkspace" />
+
+ <chain name="addTestNodeWithKey">
+ <command name="copyNodeName"
+ className="org.apache.commons.chain.generic.CopyCommand"
+ value="test"
+ toKey="name"/>
+ <command name="copyNodeType"
+ className="org.apache.commons.chain.generic.CopyCommand"
+ value="nt:unstructured"
+ toKey="nodeType"/>
+ <command name="addnode"
+ className="org.apache.jackrabbit.chain.command.AddNode"
+ nodeNameKey="name"
+ nodeTypeKey="nodeType"/>
+ </chain>
+
+ <command name="addTestNode"
+ className="org.apache.jackrabbit.chain.command.AddNode"
+ nodeName="test"
+ nodeType="nt:unstructured"/>
+
+ <command name="collect"
+ className="org.apache.jackrabbit.chain.command.CollectNodes"
+ depth="1"
+ namePattern="*"
+ toKey="children"/>
+
+ <chain name="collectWithKey">
+ <command name="copyNodeName"
+ className="org.apache.commons.chain.generic.CopyCommand"
+ value="1"
+ toKey="depth"/>
+ <command name="copyNodeType"
+ className="org.apache.commons.chain.generic.CopyCommand"
+ value="*"
+ toKey="namePattern"/>
+ <command name="collect"
+ className="org.apache.jackrabbit.chain.command.CollectNodes"
+ depthKey="depth"
+ namePatternKey="namePattern"
+ toKey="children"/>
+ </chain>
+
+ <command name="cd"
+ className="org.apache.jackrabbit.chain.command.CurrentNode"
+ path="test" />
+
+ <chain name="cdWithKey">
+ <command name="copy"
+ className="org.apache.commons.chain.generic.CopyCommand"
+ value="test"
+ toKey="path"/>
+ <command name="cdTest"
+ className="org.apache.jackrabbit.chain.command.CurrentNode"
+ pathKey="path" />
+ </chain>
+
+ <command name="exportDoc"
+ className="org.apache.jackrabbit.chain.command.xml.ExportDocViewToFile"
+ to="applications/test/export.xml"
+ overwrite="true"/>
+
+ <chain name="exportDocWithKey">
+ <command name="copy"
+ className="org.apache.commons.chain.generic.CopyCommand"
+ value="applications/test/export.xml"
+ toKey="file"/>
+ <command name="copy"
+ className="org.apache.commons.chain.generic.CopyCommand"
+ value="true"
+ toKey="overwrite"/>
+ <command name="exportDoc"
+ className="org.apache.jackrabbit.chain.command.xml.ExportDocViewToFile"
+ toKey="file"
+ overwriteKey="overwrite"/>
+ </chain>
+
+ <command name="exportSys"
+ className="org.apache.jackrabbit.chain.command.xml.ExportSysViewToFile"
+ to="applications/test/export.xml"
+ overwrite="true"/>
+
+ <chain name="exportSysWithKey">
+ <command name="copy"
+ className="org.apache.commons.chain.generic.CopyCommand"
+ value="applications/test/export.xml"
+ toKey="file"/>
+ <command name="copy"
+ className="org.apache.commons.chain.generic.CopyCommand"
+ value="true"
+ toKey="overwrite"/>
+ <command name="exportSys"
+ className="org.apache.jackrabbit.chain.command.xml.ExportSysViewToFile"
+ toKey="file"
+ overwriteKey="overwrite"/>
+ </chain>
+
+ <command name="read"
+ className="org.apache.jackrabbit.chain.command.ReadValue"
+ path="jcr:primaryType"
+ toKey="value"/>
+
+ <chain name="readWithKey">
+ <command name="copy"
+ className="org.apache.commons.chain.generic.CopyCommand"
+ value="jcr:primaryType"
+ toKey="path"/>
+ <command name="read"
+ className="org.apache.jackrabbit.chain.command.ReadValue"
+ pathKey="path"
+ toKey="value"/>
+ </chain>
+
+ <command name="remove"
+ className="org.apache.jackrabbit.chain.command.RemoveItem"
+ path="test" />
+
+ <chain name="removeWithKey">
+ <command name="copy"
+ className="org.apache.commons.chain.generic.CopyCommand"
+ value="test"
+ toKey="path"/>
+ <command name="remove"
+ className="org.apache.jackrabbit.chain.command.RemoveItem"
+ pathKey="path" />
+ </chain>
+
+ <command name="removeItems"
+ className="org.apache.jackrabbit.chain.command.RemoveItems"
+ pattern="test" />
+
+ <chain name="removeItemsWithKey">
+ <command name="copy"
+ className="org.apache.commons.chain.generic.CopyCommand"
+ value="test"
+ toKey="pattern"/>
+ <command name="remove"
+ className="org.apache.jackrabbit.chain.command.RemoveItems"
+ patternKey="pattern" />
+ </chain>
+
+ <command name="setProp"
+ className="org.apache.jackrabbit.chain.command.SetProperty"
+ propertyName="testProp"
+ value="testValue" />
+
+ <chain name="setPropWithKey">
+ <command name="copy1"
+ className="org.apache.commons.chain.generic.CopyCommand"
+ value="testProp"
+ toKey="propertyName"/>
+ <command name="copy2"
+ className="org.apache.commons.chain.generic.CopyCommand"
+ value="testValue"
+ toKey="propertyValue"/>
+ <command name="setProp"
+ className="org.apache.jackrabbit.chain.command.SetProperty"
+ propertyNameKey="propertyName"
+ valueKey="propertyValue" />
+ </chain>
+
+
+ <command name="setPropFromFile"
+ className="org.apache.jackrabbit.chain.command.fs.SetPropertyFromFile"
+ propertyName="testProp"
+ value="applications/test/testSetPropertyFromFile.txt" />
+
+ <chain name="setPropFromFileWithKey">
+ <command name="copy1"
+ className="org.apache.commons.chain.generic.CopyCommand"
+ value="testProp"
+ toKey="propertyName"/>
+ <command name="copy2"
+ className="org.apache.commons.chain.generic.CopyCommand"
+ value="applications/test/testSetPropertyFromFile.txt"
+ toKey="propertyValue"/>
+ <command name="setProp"
+ className="org.apache.jackrabbit.chain.command.fs.SetPropertyFromFile"
+ propertyNameKey="propertyName"
+ valueKey="propertyValue" />
+ </chain>
+
+ <command name="setMultiProp"
+ className="org.apache.jackrabbit.chain.command.SetMultivalueProperty"
+ propertyName="testProp"
+ value="testValue,testValue1" />
+
+ <chain name="setMultiPropWithKey">
+ <command name="copy1"
+ className="org.apache.commons.chain.generic.CopyCommand"
+ value="testProp"
+ toKey="propertyName"/>
+ <command name="copy2"
+ className="org.apache.commons.chain.generic.CopyCommand"
+ value="testValue,testValue1"
+ toKey="propertyValue"/>
+ <command name="setProp"
+ className="org.apache.jackrabbit.chain.command.SetMultivalueProperty"
+ propertyNameKey="propertyName"
+ valueKey="propertyValue" />
+ </chain>
+
+ </catalog>
+</chains>
\ No newline at end of file
Propchange: incubator/jackrabbit/trunk/contrib/jcr-commands/src/test/org/apache/jackrabbit/chain/test/chains.xml
------------------------------------------------------------------------------
svn:eol-style = native