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/16 16:20:49 UTC
svn commit: r154030 [2/2] - in incubator/jackrabbit/trunk:
applications/test/ src/test/org/apache/jackrabbit/init/
src/test/org/apache/jackrabbit/test/api/
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/ReferencePropertyTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/ReferencePropertyTest.java?view=auto&rev=154030
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/ReferencePropertyTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/ReferencePropertyTest.java Wed Feb 16 07:20:44 2005
@@ -0,0 +1,176 @@
+/*
+ * 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 javax.jcr.RepositoryException;
+import javax.jcr.Node;
+import javax.jcr.PropertyType;
+import javax.jcr.PropertyIterator;
+import javax.jcr.Property;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+
+/**
+ * Tests a reference property. If the workspace does not contain a node with
+ * a reference property a {@link org.apache.jackrabbit.test.NotExecutableException}
+ * is thrown.
+ *
+ * @test
+ * @sources ReferencePropertyTest.java
+ * @executeClass org.apache.jackrabbit.test.api.ReferencePropertyTest
+ * @keywords level1
+ */
+public class ReferencePropertyTest extends AbstractPropertyTest {
+
+ /** The target of the reference */
+ private Node referencedNode;
+
+ /**
+ * Sets up the fixture for the test.
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ referencedNode = prop.getNode();
+ }
+
+ /**
+ * Returns {@link javax.jcr.PropertyType#REFERENCE}.
+ * @return {@link javax.jcr.PropertyType#REFERENCE}.
+ */
+ protected int getPropertyType() {
+ return PropertyType.REFERENCE;
+ }
+
+ /**
+ * Tests if the referenced node is of nodeType mix:referenceable.
+ */
+ public void testNodeType() throws RepositoryException {
+ assertTrue("Property " + prop.getName() + " refers to a node " +
+ "which is not of NodeType mix:referenceable.",
+ referencedNode.isNodeType(mixReferenceable));
+ }
+
+ /**
+ * Tests if the referenced node has this property in its referers list in
+ * case the property is not transient. Also tests in theis case that the
+ * node retrieved by property.getNode() is the same as the one retrieved by
+ * session.getNodeByUUID() .
+ */
+ public void testPropValue() throws RepositoryException {
+ Node referenced = session.getNodeByUUID(prop.getString());
+ PropertyIterator referers = referenced.getReferences();
+ if (!prop.isNew()) {
+ boolean found = false;
+ while (referers.hasNext()) {
+ Property propp = referers.nextProperty();
+ if (propp.isSame(prop)) {
+ found = true;
+ }
+ }
+ assertTrue("Referencing property of node " + referenced.getName() +
+ " nof found.", found);
+ assertTrue("Referenced node retrieved with getNode is different " +
+ "from the node retrieved with getNodeByUUID",
+ referenced.isSame(referencedNode));
+ } else {
+ log.println("Reference property " + prop.getName() + " is in transient state.");
+ }
+ }
+
+ /**
+ * Tests failure of conversion from Reference type to Boolean type.
+ */
+ public void testGetBoolean() throws RepositoryException {
+ try {
+ Value val = PropertyUtil.getValue(prop);
+ val.getBoolean();
+ fail("Conversion from a Reference value to a Boolean value " +
+ "should throw a ValueFormatException.");
+ } catch (ValueFormatException vfe) {
+ //ok
+ }
+ }
+
+ /**
+ * Tests failure of conversion from Reference type to Date type.
+ */
+ public void testGetDate() throws RepositoryException {
+ try {
+ Value val = PropertyUtil.getValue(prop);
+ val.getDate();
+ fail("Conversion from a Reference value to a Date value " +
+ "should throw a ValueFormatException.");
+ } catch (ValueFormatException vfe) {
+ //ok
+ }
+ }
+
+ /**
+ * Tests failure from Reference type to Double type.
+ */
+ public void testGetDouble() throws RepositoryException {
+ try {
+ Value val = PropertyUtil.getValue(prop);
+ val.getDouble();
+ fail("Conversion from a Reference value to a Double value " +
+ "should throw a ValueFormatException.");
+ } catch (ValueFormatException vfe) {
+ //ok
+ }
+ }
+
+ /**
+ * Tests failure of conversion from Reference type to Long type.
+ */
+ public void testGetLong() throws RepositoryException {
+ try {
+ Value val = PropertyUtil.getValue(prop);
+ val.getLong();
+ fail("Conversion from a Reference value to a Long value " +
+ "should throw a ValueFormatException.");
+ } catch (ValueFormatException vfe) {
+ //ok
+ }
+ }
+
+ /**
+ * Tests conversion from Reference type to String type.
+ */
+ public void testGetString() throws RepositoryException {
+ Value val = PropertyUtil.getValue(prop);
+ String ref = val.getString();
+ assertTrue("Reference property has not correct UUID format.", PropertyUtil.isUUID(ref));
+ }
+
+ /**
+ * Tests if Value.getType() returns the same as Property.getType() and also
+ * tests that prop.getDefinition().getRequiredType() returns the same type
+ * in case it is not of Undefined type.
+ */
+ public void testGetType() throws RepositoryException {
+ assertTrue("Value.getType() returns wrong type.", PropertyUtil.checkGetType(prop, PropertyType.REFERENCE));
+ }
+
+ /**
+ * Tests equals method of Reference value.
+ */
+ public void testEquals() throws RepositoryException {
+ Property prop2 = referencedNode.getProperty("jcr:uuid");
+ assertTrue("Incorrect equals method of Reference value.",
+ PropertyUtil.equalValues(prop2.getValue(), prop.getValue()));
+ }
+}
\ No newline at end of file
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/ReferencePropertyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/StringPropertyTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/StringPropertyTest.java?view=auto&rev=154030
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/StringPropertyTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/StringPropertyTest.java Wed Feb 16 07:20:44 2005
@@ -0,0 +1,288 @@
+/*
+ * 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.NotExecutableException;
+
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.ValueFormatException;
+import javax.jcr.Value;
+import java.io.IOException;
+import java.io.BufferedInputStream;
+
+/**
+ * <code>StringPropertyTest</code> tests a String property against the
+ * conversions to other Properties (except Name and Path property). If no String
+ * property is found or only a multivalue String property with an empty array, a
+ * NotExecutableException is thrown on setUp. More precisely, the tests are:
+ * <p/>
+ * - Value.getString() should return a string equals to Property.getString(),
+ * and in case of a multivalue property the failure of Property.getString() is
+ * checked.
+ * <p/>
+ * - Value.getBoolean() Conversion to Boolean property.
+ * <p/>
+ * - Value.getDate() Conversion to Date property is only valid when the String
+ * follows the required Date pattern (6.2.5.1 of jsr170 specification).
+ * <p/>
+ * - Value.getDouble() Conversion to Double are only valid when the String
+ * follows the correct patterns as required by the according Java classes.
+ * <p/>
+ * - Value.getLong() Conversion to Double are only valid when the String follows
+ * the correct patterns as required by the according Java classes.
+ * <p/>
+ * - Value.getStream() Conversion to a Binary property follows the rules of
+ * Value.getStream() as explained in chapter 6.2.7 of the jsr170 specification.
+ * The required encoding is utf-8.
+ * <p/>
+ * - Property.getNode() Conversion to a Reference property is tested with
+ * Property.getNode. The String should match the UUID pattern but this doesn't
+ * guarantee to be a reference (which especially requires integrity).
+ * <p/>
+ * - Property.getLength() .
+ * <p/>
+ * - Property.getLengths() .
+ * <p/>
+ * - Property.getType() is compared to Value.getType() .
+ *
+ * @test
+ * @sources StringPropertyTest.java
+ * @executeClass org.apache.jackrabbit.test.api.StringPropertyTest
+ * @keywords level1
+ */
+public class StringPropertyTest extends AbstractPropertyTest {
+
+ /**
+ * Returns {@link javax.jcr.PropertyType#STRING}.
+ *
+ * @return {@link javax.jcr.PropertyType#STRING}.
+ */
+ protected int getPropertyType() {
+ return PropertyType.STRING;
+ }
+
+ /**
+ * Tests that Property.getString() delivers a string equal to the string
+ * received with Value.getString().
+ */
+ public void testValue() throws RepositoryException {
+ if (multiple) {
+ try {
+ prop.getString();
+ fail("Property.getString() called on a multivalue property " +
+ "should throw a ValueFormatException.");
+ } catch (ValueFormatException vfe) {
+ // ok
+ }
+ }
+ assertEquals("Value.getString() and Property.getString() return different values.",
+ prop.getValue().getString(), prop.getString());
+ }
+
+ /**
+ * Tests conversion from String type to Boolean type.
+ */
+ public void testGetBoolean() throws RepositoryException {
+ Value val = PropertyUtil.getValue(prop);
+ String str = val.getString();
+ boolean bool = val.getBoolean();
+ assertEquals("Wrong conversion from String to Boolean.",
+ new Boolean(bool), Boolean.valueOf(str));
+ }
+
+ /**
+ * Tests conversion from String type to Date type.
+ */
+ public void testGetDate() throws RepositoryException {
+ Value val = PropertyUtil.getValue(prop);
+ if (PropertyUtil.isDateFormat(val.getString())) {
+ val.getDate();
+ } else {
+ try {
+ val.getDate();
+ fail("Conversion from a malformed String to a Date " +
+ "should throw a ValueFormatException.");
+ } catch (ValueFormatException vfe) {
+ // ok
+ }
+ }
+ }
+
+ /**
+ * Tests conversion from String type to Double type.
+ */
+ public void testGetDouble() throws RepositoryException {
+ Value val = PropertyUtil.getValue(prop);
+ String str = val.getString();
+ // double
+ try {
+ Double.parseDouble(str);
+ double d = val.getDouble();
+ assertEquals("Wrong conversion from String to Double.",
+ new Double(d), Double.valueOf(str));
+ } catch (NumberFormatException nfe) {
+ try {
+ val.getDouble();
+ fail("Conversion from malformed String to Double should throw ValueFormatException.");
+ } catch (ValueFormatException vfe) {
+ // ok
+ }
+ }
+ }
+
+ /**
+ * Tests conversion from String type to Long type.
+ */
+ public void testGetLong() throws RepositoryException {
+ Value val = PropertyUtil.getValue(prop);
+ String str = val.getString();
+ try {
+ Long.parseLong(str);
+ long l = val.getLong();
+ assertEquals("Wrong conversion from String to Long.",
+ new Long(l), Long.valueOf(str));
+ } catch (NumberFormatException nfe) {
+ try {
+ val.getLong();
+ fail("Conversion from malformed String to Long " +
+ "should throw ValueFormatException.");
+ } catch (ValueFormatException vfe) {
+ // ok
+ }
+ }
+ }
+
+ /**
+ * Tests conversion from String type to Binary type.
+ */
+ public void testGetStream() throws RepositoryException, IOException {
+ Value val = PropertyUtil.getValue(prop);
+ BufferedInputStream in = new BufferedInputStream(val.getStream());
+ Value otherVal = prop.getValue();
+ byte[] utf8bytes = otherVal.getString().getBytes(UTF8);
+ // compare the bytearray with the bytes received from a Stream created with this String
+ int i = 0;
+ byte b[] = new byte[1];
+ while (in.read(b) != -1) {
+ assertEquals("String as a Stream is not utf-8 encoded", utf8bytes[i], b[0]);
+ i++;
+ }
+ try {
+ val.getString();
+ fail("Non stream method call after stream method call " +
+ "should throw an IllegalStateException.");
+ } catch (IllegalStateException ise) {
+ //ok
+ }
+ try {
+ otherVal.getStream();
+ fail("Stream method call after a non stream method call " +
+ "should throw an IllegalStateException.");
+ } catch (IllegalStateException ise) {
+ // ok
+ }
+ in.close();
+ }
+
+ /**
+ * Tests conversion from String type to Reference type.
+ */
+ public void testAsReference() throws RepositoryException, NotExecutableException {
+ if (!multiple) {
+ if (!PropertyUtil.isUUID(prop.getString())) {
+ try {
+ prop.getNode();
+ fail("Conversion from a Path value to a Reference value " +
+ "should throw a ValueFormatException.");
+ } catch (ValueFormatException vfe) {
+ //ok
+ }
+ } else {
+ prop.getNode();
+ }
+ } else {
+ try {
+ prop.getNode();
+ fail("Property.getNode() called on a multivalue property " +
+ "should throw a ValueFormatException.");
+ } catch (ValueFormatException vfe) {
+ // ok
+ }
+ }
+ }
+
+ /**
+ * Tests the Property.getLength() method. The length returned is either -1
+ * or it is the length of the string.
+ */
+ public void testGetLength() throws RepositoryException {
+ if (multiple) {
+ try {
+ prop.getLength();
+ fail("Property.getLength() called on a multivalue property " +
+ "should throw a ValueFormatException.");
+
+ } catch (ValueFormatException vfe) {
+ // ok
+ }
+ } else {
+ long length = prop.getLength();
+ if (length > -1) {
+ assertEquals("Property.getLength() returns wrong number of bytes.",
+ length, prop.getString().length());
+ }
+ }
+ }
+
+ /**
+ * Tests the Property.getLengths() method. The returned values are either -1
+ * or the lengths of the according strings.
+ */
+ public void testGetLengths() throws RepositoryException {
+ if (multiple) {
+ Value[] values = prop.getValues();
+ long[] lengths = prop.getLengths();
+ for (int i = 0; i < lengths.length; i++) {
+ if (lengths[i] > -1) {
+ assertEquals("Property.getLengths() returns " +
+ "wrong array of the lengths of a multivalue property.",
+ values[i].getString().length(), lengths[i]);
+ }
+ }
+ } else {
+ try {
+ prop.getLengths();
+ fail("Property.getLengths() called on a sinlge value property " +
+ "should throw a ValueFormatException.");
+
+ } catch (ValueFormatException vfe) {
+ // ok
+ }
+ }
+ }
+
+ /**
+ * Tests if Value.getType() returns the same as Property.getType() and also
+ * tests that prop.getDefinition().getRequiredType() returns the same type
+ * in case it is not of Undefined type.
+ */
+ public void testGetType() throws RepositoryException {
+ assertTrue("Value.getType() returns wrong type.",
+ PropertyUtil.checkGetType(prop, PropertyType.STRING));
+ }
+}
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/StringPropertyTest.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=154029&r2=154030
==============================================================================
--- 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 Wed Feb 16 07:20:44 2005
@@ -47,6 +47,17 @@
suite.addTestSuite(NodeReadMethodsTest.class);
suite.addTestSuite(PropertyTypeTest.class);
+ suite.addTestSuite(BinaryPropertyTest.class);
+ suite.addTestSuite(BooleanPropertyTest.class);
+ suite.addTestSuite(DatePropertyTest.class);
+ suite.addTestSuite(DoublePropertyTest.class);
+ suite.addTestSuite(LongPropertyTest.class);
+ suite.addTestSuite(NamePropertyTest.class);
+ suite.addTestSuite(PathPropertyTest.class);
+ suite.addTestSuite(ReferencePropertyTest.class);
+ suite.addTestSuite(StringPropertyTest.class);
+ suite.addTestSuite(UndefinedPropertyTest.class);
+
return suite;
}
}
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/UndefinedPropertyTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/UndefinedPropertyTest.java?view=auto&rev=154030
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/UndefinedPropertyTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/UndefinedPropertyTest.java Wed Feb 16 07:20:44 2005
@@ -0,0 +1,54 @@
+/*
+ * 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.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+
+/**
+ * Tests if no property in the workspace is of type
+ * {@link javax.jcr.PropertyType#UNDEFINED}.
+ *
+ * @test
+ * @sources UndefinedPropertyTest.java
+ * @executeClass org.apache.jackrabbit.test.api.UndefinedPropertyTest
+ * @keywords level1
+ */
+public class UndefinedPropertyTest extends AbstractJCRTest {
+
+ /**
+ * Sets up the fixture for this test.
+ */
+ protected void setUp() throws NotExecutableException, Exception {
+ isReadOnly = true;
+ super.setUp();
+ }
+
+ /**
+ * Tests that no actual property with type Undefined exists.
+ */
+ public void testUndefinedProperty() throws RepositoryException {
+ Session session = helper.getReadOnlySession();
+ Property prop = PropertyUtil.searchProp(session, session.getRootNode(), PropertyType.UNDEFINED);
+ assertNull("Property with type Undefined found.", prop);
+ }
+}
\ No newline at end of file
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/UndefinedPropertyTest.java
------------------------------------------------------------------------------
svn:eol-style = native