Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 18699 invoked from network); 10 Mar 2011 15:59:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Mar 2011 15:59:13 -0000 Received: (qmail 96261 invoked by uid 500); 10 Mar 2011 15:59:12 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 96227 invoked by uid 500); 10 Mar 2011 15:59:12 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 96220 invoked by uid 99); 10 Mar 2011 15:59:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Mar 2011 15:59:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Mar 2011 15:59:11 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C473F2388999; Thu, 10 Mar 2011 15:58:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110310155851.C473F2388999@eris.apache.org> 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 + } + +}