[dna-commits] DNA SVN: r193 - in branches/federation/dna-spi/src: test/java/org/jboss/dna/spi/graph/impl and 1 other directory.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Fri May 23 23:52:30 EDT 2008


Author: rhauch
Date: 2008-05-23 23:52:30 -0400 (Fri, 23 May 2008)
New Revision: 193

Added:
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java
   branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactoryTest.java
Removed:
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateValueFactory.java
   branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DateValueFactoryTest.java
Modified:
   branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java
Log:
DNA-67: Create graph API for federation engine
http://jira.jboss.org/jira/browse/DNA-67

Renamed JodaDateValueFactory to JodaDateTimeValueFactory, and DateValueFactoryTest test case to JodaDateTimeFactoryTest

Copied: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java (from rev 192, branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateValueFactory.java)
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java	                        (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java	2008-05-24 03:52:30 UTC (rev 193)
@@ -0,0 +1,213 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.spi.graph.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.DateTime;
+import org.jboss.dna.spi.graph.DateTimeFactory;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * The standard {@link ValueFactory} for {@link PropertyType#DATE} values.
+ * @author Randall Hauch
+ */
+ at Immutable
+public class JodaDateTimeValueFactory extends AbstractValueFactory<DateTime> implements DateTimeFactory {
+
+    public JodaDateTimeValueFactory( TextEncoder encoder, ValueFactory<String> stringValueFactory ) {
+        super(PropertyType.DATE, encoder, stringValueFactory);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( String value ) throws ValueFormatException {
+        if (value == null) return null;
+        try {
+            return new JodaDateTime(value.trim());
+        } catch (IllegalArgumentException e) {
+            throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( String value, TextEncoder decoder ) {
+        // this probably doesn't really need to call the decoder, but by doing so then we don't care at all what the decoder does
+        return create(getEncoder(decoder).decode(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( int value ) {
+        return create((long)value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( long value ) {
+        return new JodaDateTime(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( boolean value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( float value ) throws ValueFormatException {
+        return create((long)value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( double value ) throws ValueFormatException {
+        return create((long)value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( BigDecimal value ) throws ValueFormatException {
+        if (value == null) return null;
+        return create(value.longValue());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( Calendar value ) throws ValueFormatException {
+        if (value == null) return null;
+        return new JodaDateTime(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( Date value ) throws ValueFormatException {
+        if (value == null) return null;
+        return new JodaDateTime(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( Name value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Name.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( Path value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( Reference value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Reference.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( URI value ) throws ValueFormatException {
+        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), URI.class.getSimpleName(), value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( byte[] value ) throws ValueFormatException {
+        // First attempt to create a string from the value, then a long from the string ...
+        return create(getStringValueFactory().create(value));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( InputStream stream, int approximateLength ) throws IOException, ValueFormatException {
+        // First attempt to create a string from the value, then a double from the string ...
+        return create(getStringValueFactory().create(stream, approximateLength));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( Reader reader, int approximateLength ) throws IOException, ValueFormatException {
+        // First attempt to create a string from the value, then a double from the string ...
+        return create(getStringValueFactory().create(reader, approximateLength));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create() {
+        return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisecondsOfSecond ) {
+        return new JodaDateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisecondsOfSecond);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisecondsOfSecond, int timeZoneOffsetHours ) {
+        return new JodaDateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisecondsOfSecond, timeZoneOffsetHours);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime create( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisecondsOfSecond, String timeZoneId ) {
+        return new JodaDateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisecondsOfSecond, timeZoneId);
+    }
+
+}


Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateValueFactory.java	2008-05-24 03:48:56 UTC (rev 192)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateValueFactory.java	2008-05-24 03:52:30 UTC (rev 193)
@@ -1,213 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors. 
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.spi.graph.impl;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.math.BigDecimal;
-import java.net.URI;
-import java.util.Calendar;
-import java.util.Date;
-import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.text.TextEncoder;
-import org.jboss.dna.spi.SpiI18n;
-import org.jboss.dna.spi.graph.DateTime;
-import org.jboss.dna.spi.graph.DateTimeFactory;
-import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.Path;
-import org.jboss.dna.spi.graph.PropertyType;
-import org.jboss.dna.spi.graph.Reference;
-import org.jboss.dna.spi.graph.ValueFactory;
-import org.jboss.dna.spi.graph.ValueFormatException;
-
-/**
- * The standard {@link ValueFactory} for {@link PropertyType#DATE} values.
- * @author Randall Hauch
- */
- at Immutable
-public class JodaDateValueFactory extends AbstractValueFactory<DateTime> implements DateTimeFactory {
-
-    public JodaDateValueFactory( TextEncoder encoder, ValueFactory<String> stringValueFactory ) {
-        super(PropertyType.DATE, encoder, stringValueFactory);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( String value ) throws ValueFormatException {
-        if (value == null) return null;
-        try {
-            return new JodaDateTime(value.trim());
-        } catch (IllegalArgumentException e) {
-            throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), e);
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( String value, TextEncoder decoder ) {
-        // this probably doesn't really need to call the decoder, but by doing so then we don't care at all what the decoder does
-        return create(getEncoder(decoder).decode(value));
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( int value ) {
-        return create((long)value);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( long value ) {
-        return new JodaDateTime(value);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( boolean value ) throws ValueFormatException {
-        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( float value ) throws ValueFormatException {
-        return create((long)value);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( double value ) throws ValueFormatException {
-        return create((long)value);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( BigDecimal value ) throws ValueFormatException {
-        if (value == null) return null;
-        return create(value.longValue());
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( Calendar value ) throws ValueFormatException {
-        if (value == null) return null;
-        return new JodaDateTime(value);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( Date value ) throws ValueFormatException {
-        if (value == null) return null;
-        return new JodaDateTime(value);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( Name value ) throws ValueFormatException {
-        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Name.class.getSimpleName(), value));
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( Path value ) throws ValueFormatException {
-        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value));
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( Reference value ) throws ValueFormatException {
-        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Reference.class.getSimpleName(), value));
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( URI value ) throws ValueFormatException {
-        throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), URI.class.getSimpleName(), value));
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( byte[] value ) throws ValueFormatException {
-        // First attempt to create a string from the value, then a long from the string ...
-        return create(getStringValueFactory().create(value));
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( InputStream stream, int approximateLength ) throws IOException, ValueFormatException {
-        // First attempt to create a string from the value, then a double from the string ...
-        return create(getStringValueFactory().create(stream, approximateLength));
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( Reader reader, int approximateLength ) throws IOException, ValueFormatException {
-        // First attempt to create a string from the value, then a double from the string ...
-        return create(getStringValueFactory().create(reader, approximateLength));
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create() {
-        return null;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisecondsOfSecond ) {
-        return new JodaDateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisecondsOfSecond);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisecondsOfSecond, int timeZoneOffsetHours ) {
-        return new JodaDateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisecondsOfSecond, timeZoneOffsetHours);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public DateTime create( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisecondsOfSecond, String timeZoneId ) {
-        return new JodaDateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisecondsOfSecond, timeZoneId);
-    }
-
-}

Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java	2008-05-24 03:48:56 UTC (rev 192)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java	2008-05-24 03:52:30 UTC (rev 193)
@@ -98,7 +98,7 @@
         this.stringFactory = getFactory(factories, new StringValueFactory(this.encoder));
         this.binaryFactory = getFactory(factories, new InMemoryBinaryValueFactory(this.encoder, this.stringFactory));
         this.booleanFactory = getFactory(factories, new BooleanValueFactory(this.encoder, this.stringFactory));
-        this.dateFactory = (DateTimeFactory)getFactory(factories, new JodaDateValueFactory(this.encoder, this.stringFactory));
+        this.dateFactory = (DateTimeFactory)getFactory(factories, new JodaDateTimeValueFactory(this.encoder, this.stringFactory));
         this.decimalFactory = getFactory(factories, new DecimalValueFactory(this.encoder, this.stringFactory));
         this.doubleFactory = getFactory(factories, new DoubleValueFactory(this.encoder, this.stringFactory));
         this.longFactory = getFactory(factories, new LongValueFactory(this.encoder, this.stringFactory));

Deleted: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DateValueFactoryTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DateValueFactoryTest.java	2008-05-24 03:48:56 UTC (rev 192)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DateValueFactoryTest.java	2008-05-24 03:52:30 UTC (rev 193)
@@ -1,182 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors. 
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.spi.graph.impl;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-import java.io.ByteArrayInputStream;
-import java.io.StringReader;
-import java.math.BigDecimal;
-import java.net.URI;
-import java.util.Calendar;
-import org.jboss.dna.common.text.TextEncoder;
-import org.jboss.dna.spi.graph.DateTime;
-import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.Path;
-import org.jboss.dna.spi.graph.Reference;
-import org.jboss.dna.spi.graph.ValueFormatException;
-import org.jmock.Mockery;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author Randall Hauch
- */
-public class DateValueFactoryTest {
-
-    public static final DateTime TODAY;
-    public static final DateTime LAST_YEAR;
-
-    static {
-        org.joda.time.DateTime now = new org.joda.time.DateTime();
-        TODAY = new JodaDateTime(now);
-        LAST_YEAR = new JodaDateTime(now.minusYears(1));
-    }
-
-    private JodaDateValueFactory factory;
-    private StringValueFactory stringFactory;
-    private Mockery context;
-
-    /**
-     * @throws java.lang.Exception
-     */
-    @Before
-    public void setUp() throws Exception {
-        TextEncoder encoder = Path.URL_ENCODER;
-        stringFactory = new StringValueFactory(encoder);
-        factory = new JodaDateValueFactory(encoder, stringFactory);
-        context = new Mockery();
-    }
-
-    @Test( expected = ValueFormatException.class )
-    public void shouldNotCreateDateFromBoolean() {
-        factory.create(true);
-    }
-
-    @Test
-    public void shouldCreateDateFromString() {
-        assertThat(factory.create(TODAY.getString()), is(TODAY));
-        assertThat(factory.create(LAST_YEAR.getString()), is(LAST_YEAR));
-    }
-
-    @Test
-    public void shouldCreateDateFromStringRegardlessOfLeadingAndTrailingWhitespace() {
-        assertThat(factory.create("  " + TODAY.getString() + "  "), is(TODAY));
-        assertThat(factory.create("  " + LAST_YEAR.getString() + "  "), is(LAST_YEAR));
-    }
-
-    @Test( expected = ValueFormatException.class )
-    public void shouldNotCreateDateFromStringThatIsNotInTheStandardFormat() {
-        factory.create("something");
-    }
-
-    @Test
-    public void shouldNotCreateDateFromIntegerValue() {
-        assertThat(factory.create(10000), is((DateTime)new JodaDateTime(10000)));
-    }
-
-    @Test
-    public void shouldNotCreateDateFromLongValue() {
-        assertThat(factory.create(10000l), is((DateTime)new JodaDateTime(10000l)));
-    }
-
-    @Test
-    public void shouldNotCreateDateFromFloatValue() {
-        assertThat(factory.create(10000.12345f), is((DateTime)new JodaDateTime(10000)));
-    }
-
-    @Test
-    public void shouldNotCreateDateFromDoubleValue() {
-        assertThat(factory.create(10000.12345d), is((DateTime)new JodaDateTime(10000)));
-    }
-
-    @Test
-    public void shouldCreateDateFromBigDecimal() {
-        assertThat(factory.create(new BigDecimal(10000)), is((DateTime)new JodaDateTime(10000)));
-    }
-
-    @Test
-    public void shouldCreateDateFromDate() {
-        Calendar value = Calendar.getInstance();
-        assertThat(factory.create(value.getTime()), is((DateTime)new JodaDateTime(value.getTime())));
-    }
-
-    @Test
-    public void shouldCreateDateFromCalendar() {
-        Calendar value = Calendar.getInstance();
-        value.setTimeInMillis(10000);
-        assertThat(factory.create(value), is((DateTime)new JodaDateTime(value)));
-    }
-
-    @Test( expected = ValueFormatException.class )
-    public void shouldNotCreateDateFromName() {
-        factory.create(context.mock(Name.class));
-    }
-
-    @Test( expected = ValueFormatException.class )
-    public void shouldNotCreateDateFromPath() {
-        factory.create(context.mock(Path.class));
-    }
-
-    @Test( expected = ValueFormatException.class )
-    public void shouldNotCreateDateFromReference() {
-        factory.create(context.mock(Reference.class));
-    }
-
-    @Test( expected = ValueFormatException.class )
-    public void shouldNotCreateDateFromUri() throws Exception {
-        factory.create(new URI("http://www.jboss.org"));
-    }
-
-    @Test
-    public void shouldCreateDateFromByteArrayContainingUtf8EncodingOfStringWithWellFormedDate() throws Exception {
-        assertThat(factory.create(TODAY.getString().getBytes("UTF-8")), is(TODAY));
-        assertThat(factory.create(LAST_YEAR.getString().getBytes("UTF-8")), is(LAST_YEAR));
-    }
-
-    @Test
-    public void shouldCreateDateFromInputStreamContainingUtf8EncodingOfStringWithWellFormedDate() throws Exception {
-        assertThat(factory.create(new ByteArrayInputStream(TODAY.getString().getBytes("UTF-8"))), is(TODAY));
-        assertThat(factory.create(new ByteArrayInputStream(LAST_YEAR.getString().getBytes("UTF-8"))), is(LAST_YEAR));
-    }
-
-    @Test
-    public void shouldCreateDateFromReaderContainingStringWithWellFormedDate() throws Exception {
-        assertThat(factory.create(new StringReader(TODAY.getString())), is(TODAY));
-        assertThat(factory.create(new StringReader(LAST_YEAR.getString())), is(LAST_YEAR));
-    }
-
-    @Test( expected = ValueFormatException.class )
-    public void shouldNotCreateDateFromByteArrayContainingUtf8EncodingOfStringWithContentThatIsNotWellFormedDate() throws Exception {
-        factory.create("something".getBytes("UTF-8"));
-    }
-
-    @Test( expected = ValueFormatException.class )
-    public void shouldNotCreateDateFromInputStreamContainingUtf8EncodingOfStringWithContentThatIsNotWellFormedDate() throws Exception {
-        factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
-    }
-
-    @Test( expected = ValueFormatException.class )
-    public void shouldNotCreateDateFromReaderContainingStringWithContentThatIsNotWellFormedDate() throws Exception {
-        factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
-    }
-}

Copied: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactoryTest.java (from rev 192, branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DateValueFactoryTest.java)
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactoryTest.java	                        (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactoryTest.java	2008-05-24 03:52:30 UTC (rev 193)
@@ -0,0 +1,182 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.spi.graph.impl;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import java.io.ByteArrayInputStream;
+import java.io.StringReader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.graph.DateTime;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFormatException;
+import org.jmock.Mockery;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class JodaDateTimeValueFactoryTest {
+
+    public static final DateTime TODAY;
+    public static final DateTime LAST_YEAR;
+
+    static {
+        org.joda.time.DateTime now = new org.joda.time.DateTime();
+        TODAY = new JodaDateTime(now);
+        LAST_YEAR = new JodaDateTime(now.minusYears(1));
+    }
+
+    private JodaDateTimeValueFactory factory;
+    private StringValueFactory stringFactory;
+    private Mockery context;
+
+    /**
+     * @throws java.lang.Exception
+     */
+    @Before
+    public void setUp() throws Exception {
+        TextEncoder encoder = Path.URL_ENCODER;
+        stringFactory = new StringValueFactory(encoder);
+        factory = new JodaDateTimeValueFactory(encoder, stringFactory);
+        context = new Mockery();
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateDateFromBoolean() {
+        factory.create(true);
+    }
+
+    @Test
+    public void shouldCreateDateFromString() {
+        assertThat(factory.create(TODAY.getString()), is(TODAY));
+        assertThat(factory.create(LAST_YEAR.getString()), is(LAST_YEAR));
+    }
+
+    @Test
+    public void shouldCreateDateFromStringRegardlessOfLeadingAndTrailingWhitespace() {
+        assertThat(factory.create("  " + TODAY.getString() + "  "), is(TODAY));
+        assertThat(factory.create("  " + LAST_YEAR.getString() + "  "), is(LAST_YEAR));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateDateFromStringThatIsNotInTheStandardFormat() {
+        factory.create("something");
+    }
+
+    @Test
+    public void shouldNotCreateDateFromIntegerValue() {
+        assertThat(factory.create(10000), is((DateTime)new JodaDateTime(10000)));
+    }
+
+    @Test
+    public void shouldNotCreateDateFromLongValue() {
+        assertThat(factory.create(10000l), is((DateTime)new JodaDateTime(10000l)));
+    }
+
+    @Test
+    public void shouldNotCreateDateFromFloatValue() {
+        assertThat(factory.create(10000.12345f), is((DateTime)new JodaDateTime(10000)));
+    }
+
+    @Test
+    public void shouldNotCreateDateFromDoubleValue() {
+        assertThat(factory.create(10000.12345d), is((DateTime)new JodaDateTime(10000)));
+    }
+
+    @Test
+    public void shouldCreateDateFromBigDecimal() {
+        assertThat(factory.create(new BigDecimal(10000)), is((DateTime)new JodaDateTime(10000)));
+    }
+
+    @Test
+    public void shouldCreateDateFromDate() {
+        Calendar value = Calendar.getInstance();
+        assertThat(factory.create(value.getTime()), is((DateTime)new JodaDateTime(value.getTime())));
+    }
+
+    @Test
+    public void shouldCreateDateFromCalendar() {
+        Calendar value = Calendar.getInstance();
+        value.setTimeInMillis(10000);
+        assertThat(factory.create(value), is((DateTime)new JodaDateTime(value)));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateDateFromName() {
+        factory.create(context.mock(Name.class));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateDateFromPath() {
+        factory.create(context.mock(Path.class));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateDateFromReference() {
+        factory.create(context.mock(Reference.class));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateDateFromUri() throws Exception {
+        factory.create(new URI("http://www.jboss.org"));
+    }
+
+    @Test
+    public void shouldCreateDateFromByteArrayContainingUtf8EncodingOfStringWithWellFormedDate() throws Exception {
+        assertThat(factory.create(TODAY.getString().getBytes("UTF-8")), is(TODAY));
+        assertThat(factory.create(LAST_YEAR.getString().getBytes("UTF-8")), is(LAST_YEAR));
+    }
+
+    @Test
+    public void shouldCreateDateFromInputStreamContainingUtf8EncodingOfStringWithWellFormedDate() throws Exception {
+        assertThat(factory.create(new ByteArrayInputStream(TODAY.getString().getBytes("UTF-8"))), is(TODAY));
+        assertThat(factory.create(new ByteArrayInputStream(LAST_YEAR.getString().getBytes("UTF-8"))), is(LAST_YEAR));
+    }
+
+    @Test
+    public void shouldCreateDateFromReaderContainingStringWithWellFormedDate() throws Exception {
+        assertThat(factory.create(new StringReader(TODAY.getString())), is(TODAY));
+        assertThat(factory.create(new StringReader(LAST_YEAR.getString())), is(LAST_YEAR));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateDateFromByteArrayContainingUtf8EncodingOfStringWithContentThatIsNotWellFormedDate() throws Exception {
+        factory.create("something".getBytes("UTF-8"));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateDateFromInputStreamContainingUtf8EncodingOfStringWithContentThatIsNotWellFormedDate() throws Exception {
+        factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
+    }
+
+    @Test( expected = ValueFormatException.class )
+    public void shouldNotCreateDateFromReaderContainingStringWithContentThatIsNotWellFormedDate() throws Exception {
+        factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
+    }
+}




More information about the dna-commits mailing list