You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2005/02/18 10:10:41 UTC
svn commit: r154254 - in incubator/jackrabbit/trunk: applications/test/
src/test/org/apache/jackrabbit/init/ src/test/org/apache/jackrabbit/test/
src/test/org/apache/jackrabbit/test/api/
Author: mreutegg
Date: Fri Feb 18 01:10:36 2005
New Revision: 154254
URL: http://svn.apache.org/viewcvs?view=rev&rev=154254
Log:
Adding more level 1 test cases.
Added:
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NamespaceRegistryReadMethodsTest.java (with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NamespaceRemappingTest.java (with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeIteratorTest.java (with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/PropertyReadMethodsTest.java (with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/RepositoryDescriptorTest.java (with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionReadMethodsTest.java (with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceReadMethodsTest.java (with props)
Modified:
incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/init/PropertyTestData.java
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/AbstractJCRTest.java
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java
Modified: incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties?view=diff&r1=154253&r2=154254
==============================================================================
--- incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties (original)
+++ incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties Fri Feb 18 01:10:36 2005
@@ -84,6 +84,27 @@
# Test class: UndefinedPropertyTest
javax.jcr.tck.UndefinedPropertyTest.testroot=/
+# Test class: PropertyReadMethodsTest
+javax.jcr.tck.PropertyReadMethodsTest.testroot=/
+
+# Test class: NodeIteratorTest
+javax.jcr.tck.NodeIteratorTest.testroot=/
+
+# Test class: RepositoryDescriptorTest
+javax.jcr.tck.RepositoryDescriptorTest.testroot=/
+
+# Test class: WorkspaceReadMethodsTest
+javax.jcr.tck.WorkspaceReadMethodsTest.testroot=/
+
+# Test class: SessionReadMethodsTest
+javax.jcr.tck.SessionReadMethodsTest.testroot=/
+
+# Test class: NamespaceRegistryReadMethodsTest
+javax.jcr.tck.NamespaceRegistryReadMethodsTest.testroot=/
+
+# Test class: NamespaceRemappingTest
+javax.jcr.tck.NamespaceRemappingTest.testroot=/
+
# ==============================================================================
# JAVAX.JCR.QUERY CONFIGURATION
# ==============================================================================
Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/init/PropertyTestData.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/init/PropertyTestData.java?view=diff&r1=154253&r2=154254
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/init/PropertyTestData.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/init/PropertyTestData.java Fri Feb 18 01:10:36 2005
@@ -62,6 +62,7 @@
c.set(2005, 6, 18, 17, 30);
dataRoot.setProperty("calendar", c);
dataRoot.setProperty("path", PathValue.valueOf("/"));
+ dataRoot.setProperty("multi", new String[]{"one", "two", "three"});
superuser.save();
}
}
Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/AbstractJCRTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/AbstractJCRTest.java?view=diff&r1=154253&r2=154254
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/AbstractJCRTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/AbstractJCRTest.java Fri Feb 18 01:10:36 2005
@@ -71,6 +71,11 @@
protected String jcrBaseVersion;
/**
+ * JCR Name jcr:uuid using the namespace resolver of the current session.
+ */
+ protected String jcrUUID;
+
+ /**
* JCR Name nt:base using the namespace resolver of the current session.
*/
protected String ntBase;
@@ -206,6 +211,7 @@
jcrPrimaryType = superuser.getNamespacePrefix(NS_JCR_URI) + ":primaryType";
jcrPredecessors = superuser.getNamespacePrefix(NS_JCR_URI) + ":predecessors";
jcrBaseVersion = superuser.getNamespacePrefix(NS_JCR_URI) + ":baseVersion";
+ jcrUUID = superuser.getNamespacePrefix(NS_JCR_URI) + ":uuid";
ntBase = superuser.getNamespacePrefix(NS_NT_URI) + ":base";
mixReferenceable = superuser.getNamespacePrefix(NS_MIX_URI) + ":referenceable";
mixVersionable = superuser.getNamespacePrefix(NS_MIX_URI) + ":versionable";
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NamespaceRegistryReadMethodsTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NamespaceRegistryReadMethodsTest.java?view=auto&rev=154254
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NamespaceRegistryReadMethodsTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NamespaceRegistryReadMethodsTest.java Fri Feb 18 01:10:36 2005
@@ -0,0 +1,136 @@
+/*
+ * 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.test.api;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.Session;
+import javax.jcr.Workspace;
+import javax.jcr.RepositoryException;
+import javax.jcr.NamespaceException;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Arrays;
+
+/**
+ * <code>NamespaceRegistryTestLevel1</code> This class tests read method of the
+ * NamespaceRegistry class and also the correct Exception throwing for methods
+ * not supported in level 1.
+ *
+ * @test
+ * @sources NamespaceRegistryTestLevel1.java
+ * @executeClass org.apache.jackrabbit.test.api.NamespaceRegistryTestLevel1
+ * @keywords level1
+ */
+public class NamespaceRegistryReadMethodsTest extends AbstractJCRTest {
+
+ /** The built in namespace prefixes */
+ private static final String[] BUILTIN_PREFIXES = {"jcr", "nt", "mix", "sv", ""};
+
+ /** The built in namespace uris */
+ private static final String[] BUILTIN_URIS = {NS_JCR_URI, NS_NT_URI, NS_MIX_URI, NS_SV_URI, ""};
+
+ /** The NamespaceRegistry of the repository */
+ private NamespaceRegistry nsr;
+
+ public void setUp() throws Exception {
+ isReadOnly = true;
+ super.setUp();
+ Session session = helper.getReadOnlySession();
+ Workspace ws = session.getWorkspace();
+ nsr = ws.getNamespaceRegistry();
+ }
+
+ /**
+ * Tests if {@link javax.jcr.NamespaceRegistry#getPrefixes()} returns the
+ * required namespace prefixes and if they are mapped to the correct URIs.
+ */
+ public void testGetNamespacePrefixes() throws RepositoryException {
+ Set prefixes = new HashSet();
+ prefixes.addAll(Arrays.asList(nsr.getPrefixes()));
+ for (int i = 0; i < BUILTIN_PREFIXES.length; i++) {
+ String prefix = BUILTIN_PREFIXES[i];
+ assertTrue("NamespaceRegistry does not contain built in prefix: " + prefix, prefixes.contains(prefix));
+ String uri = nsr.getURI(prefix);
+ assertEquals("Wrong namespace mapping for prefix: " + prefix, BUILTIN_URIS[i], uri);
+ }
+ }
+
+ /**
+ * Tests if {@link javax.jcr.NamespaceRegistry#getURIs()} returns the
+ * required namespace URIs and if they are mapped to the correct prefixes.
+ */
+ public void testGetNamespaceURIs() throws RepositoryException {
+ Set uris = new HashSet();
+ uris.addAll(Arrays.asList(nsr.getURIs()));
+ for (int i = 0; i < BUILTIN_URIS.length; i++) {
+ String uri = BUILTIN_URIS[i];
+ assertTrue("NamespaceRegistry does not contain built in uri: " + uri, uris.contains(uri));
+ String prefix = nsr.getPrefix(uri);
+ assertEquals("Wrong namespace mapping for uri: " + uri, BUILTIN_PREFIXES[i], prefix);
+ }
+ }
+
+ /**
+ * Tests if a {@link javax.jcr.NamespaceException} is thrown when
+ * {@link javax.jcr.NamespaceRegistry#getURI(String)} is called for an
+ * unknown prefix.
+ */
+ public void testGetURINamespaceException() throws RepositoryException, NotExecutableException {
+ Set prefixes = new HashSet();
+ prefixes.addAll(Arrays.asList(nsr.getPrefixes()));
+ String prefix = "myapp";
+ int count = 0;
+ while (prefixes.contains(prefix + count)) {
+ count++;
+ }
+ String testPrefix = prefix + count;
+ try {
+ nsr.getURI(testPrefix);
+ fail("NamespaceRegistry.getURI should throw a NamespaceException " +
+ "in case of an unmapped prefix.");
+ } catch (NamespaceException nse) {
+ //ok
+ }
+ }
+
+ /**
+ * Tests if a {@link javax.jcr.NamespaceException} is thrown when
+ * {@link javax.jcr.NamespaceRegistry#getPrefix(String)} is called for an
+ * unknown URI.
+ */
+ public void testGetPrefixNamespaceException() throws RepositoryException, NotExecutableException {
+ Set uris = new HashSet();
+ uris.addAll(Arrays.asList(nsr.getURIs()));
+ String uri = "http://www.unknown-company.com/namespace";
+ int count = 0;
+ while (uris.contains(uri + count)) {
+ count++;
+ }
+ String testURI = uri + count;
+ try {
+ nsr.getPrefix(testURI);
+ fail("NamespaceRegistry.getPrefix should throw a NamespaceException " +
+ "in case of an unregistered URI.");
+ } catch (NamespaceException nse) {
+ //ok
+ }
+ }
+
+}
\ No newline at end of file
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NamespaceRegistryReadMethodsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NamespaceRemappingTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NamespaceRemappingTest.java?view=auto&rev=154254
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NamespaceRemappingTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NamespaceRemappingTest.java Fri Feb 18 01:10:36 2005
@@ -0,0 +1,192 @@
+/*
+ * 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.test.api;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+import javax.jcr.Session;
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.RepositoryException;
+import javax.jcr.NamespaceException;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Arrays;
+
+/**
+ * <code>NamespaceRemappingTest</code> tests transient namespace remapping.
+ *
+ * @test
+ * @sources NamespaceRemappingTest.java
+ * @executeClass org.apache.jackrabbit.test.api.NamespaceRemappingTest
+ * @keywords level1
+ */
+public class NamespaceRemappingTest extends AbstractJCRTest {
+
+ /**
+ * The read only session for the test cases
+ */
+ private Session session;
+
+ /**
+ * The namespace registry of the current session
+ */
+ private NamespaceRegistry nsr;
+
+ /**
+ * Sets up the fixture for the tests.
+ */
+ protected void setUp() throws Exception {
+ isReadOnly = true;
+ super.setUp();
+ session = helper.getReadOnlySession();
+ nsr = session.getWorkspace().getNamespaceRegistry();
+ }
+
+ protected void tearDown() throws Exception {
+ try {
+ if (session != null) {
+ session.logout();
+ }
+ } finally {
+ super.tearDown();
+ }
+ }
+
+ /**
+ * Tests if the remapping of jcr:primaryType to a different prefix works and
+ * returns the property with the correct primaryType value.
+ */
+ public void testNamespaceRemapping() throws RepositoryException {
+ // find an unused prefix
+ String testPrefix = getUnusedPrefix();
+ // remap jcr prefix
+ session.setNamespacePrefix(testPrefix, NS_JCR_URI);
+
+ String propval = session.getRootNode().getProperty(testPrefix + ":primaryType").getString();
+ String primaryType = session.getRootNode().getPrimaryNodeType().getName();
+ assertEquals("Remapping of jcr prefix failed", primaryType, propval);
+ }
+
+ /**
+ * Tests if the remapping is cleared in a new session object
+ */
+ public void testRemapClearing() throws RepositoryException {
+ // find an unused prefix
+ String testPrefix = getUnusedPrefix();
+ // remap jcr prefix
+ session.setNamespacePrefix(testPrefix, NS_JCR_URI);
+ session.logout();
+
+ session = helper.getReadOnlySession();
+ try {
+ session.getNamespaceURI(testPrefix);
+ fail("Must throw a NamespaceException on unknown prefix.");
+ } catch (NamespaceException nse) {
+ // correct
+ }
+ }
+
+ /**
+ * Tests if a remapping to "xml" fails correctly
+ */
+ public void testXmlRemapping() throws RepositoryException {
+ try {
+ session.setNamespacePrefix("xml", NS_JCR_URI);
+ fail("Remapping a namespace uri to 'xml' must not be possible");
+ } catch (NamespaceException nse) {
+ // correct
+ }
+ try {
+ session.setNamespacePrefix("xmlfoo", NS_JCR_URI);
+ fail("Remapping a namespace uri to 'xmlfoo' must not be possible");
+ } catch (NamespaceException nse) {
+ // correct
+ }
+ }
+
+ /**
+ * tests that when a prefix which is mapped to a URI yet globally registered
+ * this prefix cannot be remapped to another URI with
+ * session.setNamespacePrefix()
+ */
+ public void testNamespaceException() throws RepositoryException {
+ String testURI = getUnusedURI();
+ String prefix = session.getNamespacePrefix(NS_JCR_URI);
+ try {
+ session.setNamespacePrefix(prefix, testURI);
+ fail("NamespaceRegistry must not register a URI with an already assign prefix");
+ } catch (NamespaceException nse) {
+ // ok
+ }
+ }
+
+ /**
+ * Tests that Session.getNamespaceURI() returns according the session scoped
+ * mapping
+ */
+ public void testGetNamespaceURI() throws RepositoryException {
+ String testPrefix = getUnusedPrefix();
+ // remap the jcr uri
+ session.setNamespacePrefix(testPrefix, NS_JCR_URI);
+ String uri = session.getNamespaceURI(testPrefix);
+ assertEquals("Session.getNamespaceURI does not return the correct value.", NS_JCR_URI, uri);
+ }
+
+ /**
+ * Tests that Session.getNamespacePrefix returns the session scoped
+ * mapping.
+ */
+ public void testGetNamespacePrefix() throws RepositoryException {
+ String testPrefix = getUnusedPrefix();
+ // remap the jcr uri
+ session.setNamespacePrefix(testPrefix, NS_JCR_URI);
+ String prefix = session.getNamespacePrefix(NS_JCR_URI);
+ assertEquals("Session.getNamespacePrefix does not return the correct value.", testPrefix, prefix);
+ }
+
+ /**
+ * Returns a namespace prefix that is not in use.
+ *
+ * @return a namespace prefix that is not in use.
+ */
+ private String getUnusedPrefix() throws RepositoryException {
+ Set prefixes = new HashSet();
+ prefixes.addAll(Arrays.asList(nsr.getPrefixes()));
+ String prefix = "myapp";
+ int count = 0;
+ while (prefixes.contains(prefix + count)) {
+ count++;
+ }
+ return prefix + count;
+ }
+
+ /**
+ * Returns a namespace uri that is not in use.
+ *
+ * @return a namespace uri that is not in use.
+ */
+ private String getUnusedURI() throws RepositoryException {
+ Set uris = new HashSet();
+ uris.addAll(Arrays.asList(nsr.getURIs()));
+ String uri = "http://www.unknown-company.com/namespace";
+ int count = 0;
+ while (uris.contains(uri + count)) {
+ count++;
+ }
+ return uri + count;
+ }
+}
\ No newline at end of file
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NamespaceRemappingTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeIteratorTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeIteratorTest.java?view=auto&rev=154254
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeIteratorTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeIteratorTest.java Fri Feb 18 01:10:36 2005
@@ -0,0 +1,122 @@
+/*
+ * 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.test.api;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.NodeIterator;
+import java.util.NoSuchElementException;
+
+/**
+ * Tests the {@link javax.jcr.NodeIterator} implementation.
+ *
+ * @test
+ * @sources NodeIteratorTest.java
+ * @executeClass org.apache.jackrabbit.test.api.NodeIteratorTest
+ * @keywords level1
+ */
+public class NodeIteratorTest extends AbstractJCRTest {
+
+ protected void setUp() throws Exception {
+ isReadOnly = true;
+ super.setUp();
+ }
+
+ /**
+ * Tests if {@link javax.jcr.NodeIterator#getSize()} returns the correct
+ * size.
+ */
+ public void testGetSize() throws RepositoryException {
+ NodeIterator iter = testRootNode.getNodes();
+ long size = testRootNode.getNodes().getSize();
+ if (size != -1) {
+ long count = 0;
+ while (iter.hasNext()) {
+ iter.nextNode();
+ count++;
+ }
+ assertEquals("NodeIterator.getSize does not return correct number.", size, count);
+ } else {
+ // NodeIterator does not return size information
+ }
+ }
+
+ /**
+ * Tests if {@link javax.jcr.NodeIterator#getPos()} return correct values.
+ */
+ public void testGetPos() throws RepositoryException {
+ NodeIterator iter = testRootNode.getNodes();
+ assertEquals("Initial call to getPos() must return zero", 0, iter.getPos());
+ int index = 0;
+ while (iter.hasNext()) {
+ iter.nextNode();
+ assertEquals("Wrong position returned by getPos()", ++index, iter.getPos());
+ }
+ }
+
+ /**
+ * Tests if a {@link java.util.NoSuchElementException} is thrown when {@link
+ * javax.jcr.NodeIterator#nextNode()} is called and there are no more nodes
+ * available.
+ */
+ public void testNoSuchElementException() throws RepositoryException {
+ NodeIterator iter = testRootNode.getNodes();
+ while (iter.hasNext()) {
+ iter.nextNode();
+ }
+ try {
+ iter.nextNode();
+ fail("nextNode() must throw a NoSuchElementException when no nodes are available");
+ } catch (NoSuchElementException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if {@link javax.jcr.NodeIterator#skip(long)} works correctly.
+ */
+ public void testSkip() throws RepositoryException {
+ NodeIterator iter = testRootNode.getNodes();
+ // find out if there is anything we can skip
+ int count = 0;
+ while (iter.hasNext()) {
+ iter.nextNode();
+ count++;
+ }
+ if (count > 0) {
+ // re-aquire iterator
+ iter = testRootNode.getNodes();
+ iter.skip(count);
+ try {
+ iter.nextNode();
+ fail("nextNode() must throw a NoSuchElementException when no nodes are available");
+ } catch (NoSuchElementException e) {
+ // success
+ }
+
+ // re-aquire iterator
+ iter = testRootNode.getNodes();
+ try {
+ iter.skip(count + 1);
+ fail("skip() must throw a NoSuchElementException if one tries to skip past the end of the iterator");
+ } catch (NoSuchElementException e) {
+ // success
+ }
+ }
+ }
+}
\ No newline at end of file
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeIteratorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/PropertyReadMethodsTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/PropertyReadMethodsTest.java?view=auto&rev=154254
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/PropertyReadMethodsTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/PropertyReadMethodsTest.java Fri Feb 18 01:10:36 2005
@@ -0,0 +1,107 @@
+/*
+ * 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.test.api;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.*;
+
+/**
+ * Tests general aspects of multi valued properties.
+ *
+ * @test
+ * @sources PropertyReadMethodsTest.java
+ * @executeClass org.apache.jackrabbit.test.api.PropertyReadMethodsTest
+ * @keywords level1
+ */
+public class PropertyReadMethodsTest extends AbstractJCRTest {
+
+ /** A single value property */
+ private Property singleProp;
+
+ /** A multi value property */
+ private Property multiValProp;
+
+ /**
+ * Sets up the fixture for this test.
+ */
+ protected void setUp() throws Exception {
+ isReadOnly = true;
+ super.setUp();
+ multiValProp = PropertyUtil.searchMultivalProp(testRootNode);
+ singleProp = testRootNode.getProperty(jcrPrimaryType);
+ }
+
+ /**
+ * Tests that no null value property exists in a given node tree.
+ */
+ public void testNoNullValue() throws RepositoryException {
+ assertFalse("Single property with null value found.",
+ PropertyUtil.nullValues(testRootNode));
+ }
+
+ /**
+ * Tests that all values of a multivalue property have the same property
+ * type.
+ */
+ public void testMultiValueType() throws RepositoryException, NotExecutableException {
+ if (multiValProp != null) {
+ Value[] vals = multiValProp.getValues();
+ if (vals.length > 0) {
+ int type = vals[0].getType();
+ for (int i = 1; i < vals.length; i++) {
+ assertEquals("Multivalue property has values with different types.",
+ type, vals[i].getType());
+ }
+ }
+ } else {
+ throw new NotExecutableException("Workspace does not contain a node with a multi valued property");
+ }
+ }
+
+ /**
+ * Tests failure of Property.getValue() method for a multivalue property.
+ */
+ public void testGetValue() throws RepositoryException, NotExecutableException {
+ if (multiValProp != null) {
+ try {
+ multiValProp.getValue();
+ fail("Property.getValue() called on a multivalue property " +
+ "should throw a ValueFormatException.");
+ } catch (ValueFormatException vfe) {
+ // ok
+ }
+ } else {
+ throw new NotExecutableException("Workspace does not contain a node with a multi valued property");
+ }
+ }
+
+ /**
+ * Tests failure of Property.getValues() method for a single value
+ * property.
+ */
+ public void testGetValues() throws RepositoryException {
+ try {
+ singleProp.getValues();
+ fail("Property.getValues() called on a single property " +
+ "should throw a ValueFormatException.");
+ } catch (ValueFormatException vfe) {
+ // ok
+ }
+ }
+}
\ No newline at end of file
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/PropertyReadMethodsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/RepositoryDescriptorTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/RepositoryDescriptorTest.java?view=auto&rev=154254
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/RepositoryDescriptorTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/RepositoryDescriptorTest.java Fri Feb 18 01:10:36 2005
@@ -0,0 +1,72 @@
+/*
+ * 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.test.api;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Iterator;
+
+/**
+ * Tests if the required repository descriptors are available.
+ *
+ * @test
+ * @sources RepositoryDescriptorTest.java
+ * @executeClass org.apache.jackrabbit.test.api.RepositoryDescriptorTest
+ * @keywords level1
+ */
+public class RepositoryDescriptorTest extends AbstractJCRTest {
+
+ private static final Set requiredDescriptorKeys = new HashSet();
+
+ static {
+ requiredDescriptorKeys.add(Repository.SPEC_VERSION_DESC);
+ requiredDescriptorKeys.add(Repository.LEVEL_1_SUPPORTED);
+ requiredDescriptorKeys.add(Repository.SPEC_NAME_DESC);
+ requiredDescriptorKeys.add(Repository.REP_VENDOR_DESC);
+ requiredDescriptorKeys.add(Repository.REP_VENDOR_URL_DESC);
+ requiredDescriptorKeys.add(Repository.REP_VERSION_DESC);
+ requiredDescriptorKeys.add(Repository.REP_NAME_DESC);
+ }
+
+ /** The session for the tests */
+ private Session session;
+
+ /**
+ * Sets up the fixture for this test.
+ */
+ protected void setUp() throws Exception {
+ isReadOnly = true;
+ super.setUp();
+ session = helper.getReadOnlySession();
+ }
+
+ /**
+ * Tests that the required repository descriptors are available.
+ */
+ public void testRequiredDescriptors() {
+ for (Iterator it = requiredDescriptorKeys.iterator(); it.hasNext();) {
+ String descriptor = session.getRepository().getDescriptor((String) it.next());
+ assertNotNull("Not all required descriptors are available.",
+ descriptor);
+ }
+ }
+
+}
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/RepositoryDescriptorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionReadMethodsTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionReadMethodsTest.java?view=auto&rev=154254
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionReadMethodsTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionReadMethodsTest.java Fri Feb 18 01:10:36 2005
@@ -0,0 +1,164 @@
+/*
+ * 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.test.api;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.Session;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Item;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.NodeIterator;
+
+/**
+ * <code>SessionReadMethodsTest</code>...
+ *
+ * @test
+ * @sources SessionReadMethodsTest.java
+ * @executeClass org.apache.jackrabbit.test.api.SessionReadMethodsTest
+ * @keywords level1
+ */
+public class SessionReadMethodsTest extends AbstractJCRTest {
+
+ /**
+ * A Version 1 UUID
+ */
+ private final String RANDOM_UUID = "710def90-80cd-11d9-9669-0800200c9a66";
+
+ /**
+ * The read only session for the tests
+ */
+ private Session session;
+
+ protected void setUp() throws Exception {
+ isReadOnly = true;
+ super.setUp();
+ session = helper.getReadOnlySession();
+ }
+
+ /**
+ * Tests that session.getItem() throws a PathNotFoundException with a given
+ * path to nowhere.
+ */
+ public void testGetItemFailure()
+ throws RepositoryException, NotExecutableException {
+ try {
+ session.getItem(getNonExistingPath());
+ fail("Session.getItem() does not throw PathNotFoundException in " +
+ "case a invalid path is provided.");
+ } catch (PathNotFoundException pnfe) {
+ // ok
+ }
+ }
+
+ /**
+ * Tests session.getItem() with the testRootNode and assures that the
+ * returned node represents the same node in the repository as
+ * testRootNode.
+ */
+ public void testGetItem() throws RepositoryException {
+ Item item = session.getItem(testRoot);
+ assertTrue("Session.getItem doesn't return the correct item.",
+ item.isSame(testRootNode));
+ }
+
+ /**
+ * Tests session.itemExists() in the case of a valid and an invalid path.
+ */
+ public void testItemExists() throws RepositoryException {
+ assertTrue("Session.itemExists() returns false on the testRootNode.",
+ session.itemExists(testRootNode.getPath()));
+ assertFalse("Session.itemExists() returns true on a malformed path.",
+ session.itemExists(getNonExistingPath()));
+ }
+
+ /**
+ * Tests that session.getNodeByUUID() throws a ItemNotFoundException in case
+ * of an invalid uuid.
+ */
+ public void testGetNodeByUUIDFailure() throws RepositoryException {
+ try {
+ session.getNodeByUUID(RANDOM_UUID);
+ fail("Not valid UUID should throw a ItemNotFoundException.");
+ } catch (ItemNotFoundException infe) {
+ // ok
+ }
+ }
+
+ /**
+ * Tests session.getNodeByUUID() using a valid uuid of a referenceable node
+ */
+ public void testGetNodeByUUID() throws RepositoryException, NotExecutableException {
+ Node referenced = findReferenceable(testRootNode);
+ if (referenced == null) {
+ throw new NotExecutableException("Workspace does not contain a referenceable node.");
+ }
+ String uuid = referenced.getProperty(jcrUUID).getString();
+ Node node = session.getNodeByUUID(uuid);
+ assertTrue("Node retrieved with session.getNodeByUUID is not the same " +
+ "as the node having the given uuid.",
+ referenced.isSame(node));
+ }
+
+ //----------------------< internal >----------------------------------------
+
+ /**
+ * Returns a path to a node that does not exist.
+ *
+ * @return a path to a node that does not exist.
+ */
+ private String getNonExistingPath() throws RepositoryException {
+ // build path to a node that does not exist
+ StringBuffer tmp = new StringBuffer();
+ if (testRootNode.getName().length() > 0) {
+ tmp.append("/").append(testRootNode.getName());
+ }
+ int count = 0;
+ String nodeName = "node";
+ while (testRootNode.hasNode(nodeName + count)) {
+ count++;
+ }
+ tmp.append("/").append(nodeName + count);
+ return tmp.toString();
+ }
+
+ /**
+ * Find a referenceable node for uuid test.
+ *
+ * @param node the <code>Node</code> where to start the search.
+ * @return a referenceable node or <code>null</code> if none was found.
+ */
+ private Node findReferenceable(Node node) throws RepositoryException {
+ Node referenced = null;
+ if (node.isNodeType(mixReferenceable)) {
+ return node;
+ } else {
+ NodeIterator iter = node.getNodes();
+ while (iter.hasNext()) {
+ Node n = iter.nextNode();
+ referenced = findReferenceable(n);
+ if (referenced != null) {
+ return referenced;
+ }
+ }
+ }
+ return referenced;
+ }
+}
\ No newline at end of file
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionReadMethodsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java?view=diff&r1=154253&r2=154254
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java Fri Feb 18 01:10:36 2005
@@ -58,6 +58,14 @@
suite.addTestSuite(StringPropertyTest.class);
suite.addTestSuite(UndefinedPropertyTest.class);
+ suite.addTestSuite(NamespaceRegistryReadMethodsTest.class);
+ suite.addTestSuite(NamespaceRemappingTest.class);
+ suite.addTestSuite(NodeIteratorTest.class);
+ suite.addTestSuite(PropertyReadMethodsTest.class);
+ suite.addTestSuite(RepositoryDescriptorTest.class);
+ suite.addTestSuite(SessionReadMethodsTest.class);
+ suite.addTestSuite(WorkspaceReadMethodsTest.class);
+
return suite;
}
}
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceReadMethodsTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceReadMethodsTest.java?view=auto&rev=154254
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceReadMethodsTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceReadMethodsTest.java Fri Feb 18 01:10:36 2005
@@ -0,0 +1,94 @@
+/*
+ * 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.test.api;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Workspace;
+
+/**
+ * <code>WorkspaceReadMethodsTest</code>...
+ *
+ * @test
+ * @sources WorkspaceReadMethodsTest.java
+ * @executeClass org.apache.jackrabbit.test.api.WorkspaceReadMethodsTest
+ * @keywords level1
+ */
+public class WorkspaceReadMethodsTest extends AbstractJCRTest {
+
+ /**
+ * Sets up the fixture for the test.
+ */
+ protected void setUp() throws Exception {
+ isReadOnly = true;
+ super.setUp();
+ }
+
+ /**
+ * Tests the getSession() method which returns the same session object as
+ * this workspace was requested from.
+ */
+ public void testGetSession() throws RepositoryException {
+ Session session = helper.getReadOnlySession();
+ Session otherSession = session.getWorkspace().getSession();
+ assertSame("Workspace.getSession() returns not the same session object.",
+ session, otherSession);
+ session.logout();
+ }
+
+ /**
+ * Tests that the name returned by Workspace.getName() is equal to the one
+ * used for login.
+ */
+ public void testGetName() throws RepositoryException {
+ Session session = helper.getReadOnlySession(workspaceName);
+ String name = session.getWorkspace().getName();
+ if (workspaceName != null) {
+ assertEquals("Workspace.getName() returns wrong name.",
+ workspaceName, name);
+ }
+ session.logout();
+ }
+
+ /**
+ * Tests Workspace.getQueryManager. This should just return correctly a
+ * QueryManager object.
+ */
+ public void testGetQueryManager() throws RepositoryException {
+ Workspace ws = helper.getReadOnlySession().getWorkspace();
+ assertNotNull("Workspace does not return a QueryManager object.", ws.getQueryManager());
+ ws.getSession().logout();
+ }
+
+ /**
+ * Tests Workspace.getAccessibleWorkspaceNames() by logging into the
+ * Workspaces given by the returned names. The credentials are the same as
+ * used for accessing the current workspace.
+ */
+ public void testGetAccessibleWorkspaceNames() throws RepositoryException {
+ Session session = helper.getReadOnlySession();
+ String[] wsNames = session.getWorkspace().getAccessibleWorkspaceNames();
+ for (int i = 0; i < wsNames.length; i++) {
+ // login
+ Session s = helper.getReadOnlySession(wsNames[i]);
+ s.logout();
+ }
+ session.logout();
+ }
+}
\ No newline at end of file
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceReadMethodsTest.java
------------------------------------------------------------------------------
svn:eol-style = native