jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r598665 - in /jackrabbit/trunk/jackrabbit-spi-commons/src: main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java test/java/org/apache/jackrabbit/value/QValueTest.java test/java/org/apache/jackrabbit/value/TestAll.java
Date Tue, 27 Nov 2007 15:13:18 GMT
Author: angela
Date: Tue Nov 27 07:13:17 2007
New Revision: 598665

URL: http://svn.apache.org/viewvc?rev=598665&view=rev
Log:
JCR-1190 : QValueFactory improvements

Added:
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/value/TestAll.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/value/QValueTest.java

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java?rev=598665&r1=598664&r2=598665&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java
Tue Nov 27 07:13:17 2007
@@ -105,14 +105,17 @@
                     return new QValueImpl(value, type);
                 case PropertyType.BINARY:
                     return new BinaryQValue(value.getBytes(DEFAULT_ENCODING));
-                default:
-                    throw new IllegalArgumentException("illegal type");
+                // default: invalid type specified -> see below.
             }
-        } catch (NumberFormatException ex) {
+        } catch (IllegalArgumentException ex) {
+            // given String value cannot be converted to Long/Double/Path/Name
             throw new ValueFormatException(ex);
         } catch (UnsupportedEncodingException ex) {
             throw new RepositoryException(ex);
         }
+
+        // invalid type specified:
+        throw new IllegalArgumentException("illegal type " + type);
     }
 
     /**
@@ -298,7 +301,11 @@
             if (type == PropertyType.NAME) {
                 return (Name) val;
             } else {
-                return NAME_FACTORY.create(getString());
+                try {
+                    return NAME_FACTORY.create(getString());
+                } catch (IllegalArgumentException e) {
+                    throw new ValueFormatException("not a valid Name value: " + getString(),
e);
+                }
             }
         }
 
@@ -370,7 +377,11 @@
             if (type == PropertyType.PATH) {
                 return (Path) val;
             } else {
-                return PATH_FACTORY.create(getString());
+                try {
+                    return PATH_FACTORY.create(getString());
+                } catch (IllegalArgumentException e) {
+                    throw new ValueFormatException("not a valid Path: " + getString(), e);
+                }
             }
         }
 

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/value/QValueTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/value/QValueTest.java?rev=598665&r1=598664&r2=598665&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/value/QValueTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/value/QValueTest.java
Tue Nov 27 07:13:17 2007
@@ -56,6 +56,56 @@
 
     private static final QValueFactory factory = QValueFactoryImpl.getInstance();
 
+    public void testIllegalType() throws RepositoryException {
+        try {
+            factory.create("any", 54);
+            fail("54 is not a valid property type");
+        } catch (IllegalArgumentException e) {
+            // ok
+        }
+    }
+
+    //-------------------------------------------------------------< DOUBLE >---
+    public void testCreateInvalidDoubleValue() throws RepositoryException {
+        try {
+            factory.create("any", PropertyType.DOUBLE);
+            fail("'any' cannot be converted to a valid double value.");
+        } catch (ValueFormatException e) {
+            // ok
+        }
+    }
+
+    public void testGetDoubleOnBooleanValue() throws RepositoryException {
+        try {
+            QValue v = factory.create(Boolean.TRUE.toString(), PropertyType.BOOLEAN);
+            v.getDouble();
+            fail("'true' cannot be converted to a valid double value.");
+        } catch (ValueFormatException e) {
+            // ok
+        }
+    }
+
+    //---------------------------------------------------------------< LONG >---
+
+    public void testCreateInvalidLongValue() throws RepositoryException {
+        try {
+            factory.create("any", PropertyType.LONG);
+            fail("'any' cannot be converted to a valid long value.");
+        } catch (ValueFormatException e) {
+            // ok
+        }
+    }
+
+    public void testGetLongOnBooleanValue() throws RepositoryException {
+        try {
+            QValue v = factory.create(Boolean.TRUE.toString(), PropertyType.BOOLEAN);
+            v.getLong();
+            fail("'true' cannot be converted to a valid long value.");
+        } catch (ValueFormatException e) {
+            // ok
+        }
+    }
+
     //---------------------------------------------------------------< DATE >---
     public void testNullDateValue() throws IOException, RepositoryException {
         try {
@@ -123,7 +173,7 @@
 
 
     //---------------------------------------------------------------< Name >---
-    public void testNullQNameValue() throws IOException, RepositoryException {
+    public void testNullNameValue() throws IOException, RepositoryException {
         try {
             factory.create((Name) null);
             fail();
@@ -132,25 +182,48 @@
         }
     }
 
-    public void testQNameValueType() throws IOException, RepositoryException {
+    public void testNameValueType() throws IOException, RepositoryException {
         QValue v = factory.create(NameConstants.JCR_DATA);
         assertTrue(v.getType() == PropertyType.NAME);
         v = factory.create(NameConstants.JCR_DATA.toString(), PropertyType.NAME);
         assertTrue(v.getType() == PropertyType.NAME);
     }
 
-    public void testQNameValueEquality() throws IOException, RepositoryException {
+    public void testNameValueEquality() throws IOException, RepositoryException {
         QValue v = factory.create(NameConstants.JCR_DATA);
         QValue v2 = factory.create(NameConstants.JCR_DATA.toString(), PropertyType.NAME);
         assertTrue(v.equals(v2));
     }
 
-    public void testQNameValueGetString() throws IOException, RepositoryException {
+    public void testNameValueGetString() throws IOException, RepositoryException {
         QValue v = factory.create(NameConstants.JCR_DATA);
         assertTrue(v.getString().equals(NameConstants.JCR_DATA.toString()));
     }
 
-    //--------------------------------------------------------------< QPath >---
+    public void testNameValueGetName() throws RepositoryException {
+        QValue v = factory.create(NameConstants.JCR_DATA);
+        assertTrue(v.getName().equals(NameConstants.JCR_DATA));
+    }
+
+    public void testInvalidNameValue() throws RepositoryException {
+        try {
+            factory.create("abc", PropertyType.NAME);
+            fail("'abc' is not a valid Name -> creating QValue should fail.");
+        } catch (ValueFormatException e) {
+            // ok
+        }
+    }
+
+    public void testAnyValueGetName() throws RepositoryException {
+        try {
+            factory.create(12345).getName();
+            fail("12345 is not a valid Name value -> QValue.getName() should fail.");
+        } catch (ValueFormatException e) {
+            // ok
+        }
+    }
+
+    //---------------------------------------------------------------< Path >---
     public void testNullPathValue() throws IOException, RepositoryException {
         try {
             factory.create((Path) null);
@@ -179,6 +252,28 @@
         assertTrue(v.getString().equals(ROOT_PATH.toString()));
     }
 
+    public void testPathValueGetPath() throws RepositoryException {
+        QValue v = factory.create(ROOT_PATH);
+        assertTrue(v.getPath().equals(ROOT_PATH));
+    }
+
+    public void testInvalidPathValue() throws RepositoryException {
+        try {
+            factory.create("abc", PropertyType.PATH);
+            fail("'abc' is not a valid Path -> creating QValue should fail.");
+        } catch (ValueFormatException e) {
+            // ok
+        }
+    }
+
+    public void testAnyValueGetPath() throws RepositoryException {
+        try {
+            factory.create(12345).getPath();
+            fail("12345 is not a valid Path value -> QValue.getPath() should fail.");
+        } catch (ValueFormatException e) {
+            // ok
+        }
+    }
     //-------------------------------------------------------------< BINARY >---
     public void testNullBinaryValue() throws IOException, RepositoryException {
         try {

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/value/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/value/TestAll.java?rev=598665&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/value/TestAll.java
(added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/value/TestAll.java
Tue Nov 27 07:13:17 2007
@@ -0,0 +1,39 @@
+/*
+ * $Id$
+ *
+ * Copyright 1997-2005 Day Management AG
+ * Barfuesserplatz 6, 4001 Basel, Switzerland
+ * All Rights Reserved.
+ *
+ * This software is the confidential and proprietary information of
+ * Day Management AG, ("Confidential Information"). You shall not
+ * disclose such Confidential Information and shall use it only in
+ * accordance with the terms of the license agreement you entered into
+ * with Day.
+ */
+package org.apache.jackrabbit.value;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes all testcases for the Core module.
+ */
+public class TestAll extends TestCase {
+
+    /**
+     * Returns a <code>Test</code> suite that executes all tests inside this
+     * package.
+     *
+     * @return a <code>Test</code> suite that executes all tests inside this
+     *         package.
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("value tests");
+
+        suite.addTestSuite(QValueTest.class);
+
+        return suite;
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/value/TestAll.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/value/TestAll.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url



Mime
View raw message