jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1080259 - /jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/SimpleValueFactoryTest.java
Date Thu, 10 Mar 2011 15:58:51 GMT
Author: jukka
Date: Thu Mar 10 15:58:51 2011
New Revision: 1080259

URL: http://svn.apache.org/viewvc?rev=1080259&view=rev
Log:
JCR-2853: QOM utility classes in jcr-commons

Add some tests for the simple value factory

Added:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/SimpleValueFactoryTest.java

Added: jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/SimpleValueFactoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/SimpleValueFactoryTest.java?rev=1080259&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/SimpleValueFactoryTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/SimpleValueFactoryTest.java
Thu Mar 10 15:58:51 2011
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.commons;
+
+import java.math.BigDecimal;
+import java.util.Calendar;
+import java.util.TimeZone;
+
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+import javax.jcr.ValueFormatException;
+
+import junit.framework.TestCase;
+
+/**
+ * Test cases for the {@link SimpleValueFactory} class.
+ */
+public class SimpleValueFactoryTest extends TestCase {
+
+    private final ValueFactory factory = new SimpleValueFactory();
+
+    public void testBoolean() throws RepositoryException {
+        Value value = factory.createValue(true);
+
+        assertEquals(PropertyType.BOOLEAN, value.getType());
+        assertEquals(value, factory.createValue(true));
+
+        assertTrue(value.getBoolean());
+        try { value.getDate(); fail(); } catch (ValueFormatException e) {}
+        try { value.getDecimal(); fail(); } catch (ValueFormatException e) {}
+        try { value.getDouble(); fail(); } catch (ValueFormatException e) {}
+        try { value.getLong(); fail(); } catch (ValueFormatException e) {}
+        assertEquals(Boolean.TRUE.toString(), value.getString());
+
+        // TODO: binary representation
+    }
+
+    public void testDate() throws RepositoryException {
+        Calendar a = Calendar.getInstance();
+        a.setTimeInMillis(1234567890);
+        a.setTimeZone(TimeZone.getTimeZone("GMT"));
+        Value value = factory.createValue(a);
+
+        assertEquals(PropertyType.DATE, value.getType());
+        assertEquals(value, factory.createValue(a));
+
+        try { value.getBoolean(); fail(); } catch (ValueFormatException e) {}
+        assertEquals(a, value.getDate());
+        assertEquals(new BigDecimal(a.getTimeInMillis()), value.getDecimal());
+        assertEquals((double) a.getTimeInMillis(), value.getDouble());
+        assertEquals(a.getTimeInMillis(), value.getLong());
+        assertEquals("1970-01-15T06:56:07.890Z", value.getString());
+
+        // TODO: binary representation
+    }
+
+    public void testDecimal() throws RepositoryException {
+        BigDecimal a = new BigDecimal(1234567890);
+        Value value = factory.createValue(a);
+
+        assertEquals(PropertyType.DECIMAL, value.getType());
+        assertEquals(value, factory.createValue(a));
+
+        try { value.getBoolean(); fail(); } catch (ValueFormatException e) {}
+        assertEquals(a.longValue(), value.getDate().getTimeInMillis());
+        assertEquals(a, value.getDecimal());
+        assertEquals(a.doubleValue(), value.getDouble());
+        assertEquals(a.longValue(), value.getLong());
+        assertEquals(a.toString(), value.getString());
+
+        // TODO: binary representation
+    }
+
+    public void testDouble() throws RepositoryException {
+        double a = 123456789.0;
+        Value value = factory.createValue(a);
+
+        assertEquals(PropertyType.DOUBLE, value.getType());
+        assertEquals(value, factory.createValue(a));
+
+        try { value.getBoolean(); fail(); } catch (ValueFormatException e) {}
+        assertEquals((long) a, value.getDate().getTimeInMillis());
+        assertEquals(new BigDecimal(a), value.getDecimal());
+        assertEquals(a, value.getDouble());
+        assertEquals((long) a, value.getLong());
+        assertEquals(Double.toString(a), value.getString());
+
+        // TODO: binary representation
+    }
+
+    public void testLong() throws RepositoryException {
+        long a = 1234567890;
+        Value value = factory.createValue(a);
+
+        assertEquals(PropertyType.LONG, value.getType());
+        assertEquals(value, factory.createValue(a));
+
+        try { value.getBoolean(); fail(); } catch (ValueFormatException e) {}
+        assertEquals(a, value.getDate().getTimeInMillis());
+        assertEquals(new BigDecimal(a), value.getDecimal());
+        assertEquals((double) a, value.getDouble());
+        assertEquals(a, value.getLong());
+        assertEquals(Long.toString(a), value.getString());
+
+        // TODO: binary representation
+    }
+
+    public void testString() throws RepositoryException {
+        String a = "test";
+        Value value = factory.createValue(a);
+
+        assertEquals(PropertyType.STRING, value.getType());
+        assertEquals(value, factory.createValue(a));
+
+        assertFalse(value.getBoolean());
+        try { value.getDate(); fail(); } catch (ValueFormatException e) {}
+        try { value.getDecimal(); fail(); } catch (ValueFormatException e) {}
+        try { value.getDouble(); fail(); } catch (ValueFormatException e) {}
+        try { value.getLong(); fail(); } catch (ValueFormatException e) {}
+        assertEquals(a, value.getString());
+
+        // TODO: binary representation
+    }
+
+}



Mime
View raw message