DNA SVN: r195 - in branches/federation/dna-spi/src: test/java/org/jboss/dna/spi/graph/impl and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-24 12:36:24 -0400 (Sat, 24 May 2008)
New Revision: 195
Added:
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryTest.java
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BinaryContains.java
Log:
DNA-67: Create graph API for federation engine
http://jira.jboss.org/jira/browse/DNA-67
Added unit test for InMemoryBinary, added a factory method to the "BinaryContains" JUnit (Hamcrest) matcher, and added a no-arg constructor to the InMemoryBinary class so that it can be used as externalizable.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java 2008-05-24 15:44:34 UTC (rev 194)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java 2008-05-24 16:36:24 UTC (rev 195)
@@ -38,8 +38,14 @@
@Immutable
public class InMemoryBinary implements Binary {
+ protected static final byte[] EMPTY_CONTENT = new byte[0];
+
private byte[] bytes;
+ public InMemoryBinary() {
+ this.bytes = EMPTY_CONTENT;
+ }
+
public InMemoryBinary( byte[] bytes ) {
ArgCheck.isNotNull(bytes, "bytes");
this.bytes = bytes;
@@ -114,7 +120,7 @@
* {@inheritDoc}
*/
public void writeExternal( ObjectOutput out ) throws IOException {
- out.write(this.bytes.length);
+ out.writeInt(this.bytes.length);
out.write(this.bytes);
}
Modified: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BinaryContains.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BinaryContains.java 2008-05-24 15:44:34 UTC (rev 194)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BinaryContains.java 2008-05-24 16:36:24 UTC (rev 195)
@@ -93,4 +93,9 @@
return new BinaryContains(expectedContent);
}
+ @Factory
+ public static Matcher<Binary> hasNoContent() {
+ return new BinaryContains(new byte[0]);
+ }
+
}
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryTest.java 2008-05-24 16:36:24 UTC (rev 195)
@@ -0,0 +1,134 @@
+/*
+ * 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.jboss.dna.spi.graph.impl.BinaryContains.hasContent;
+import static org.jboss.dna.spi.graph.impl.BinaryContains.hasNoContent;
+import static org.junit.Assert.assertThat;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import org.jboss.dna.common.util.IoUtil;
+import org.jboss.dna.spi.graph.Binary;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class InMemoryBinaryTest {
+
+ private byte[] validByteArrayContent;
+ private String validStringContent;
+ private InMemoryBinary binary;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ validStringContent = "This is a valid string content";
+ validByteArrayContent = this.validStringContent.getBytes("UTF-8");
+ binary = new InMemoryBinary(validByteArrayContent);
+ }
+
+ @Test
+ public void shouldConstructFromByteArray() {
+ binary = new InMemoryBinary(validByteArrayContent);
+ assertThat(binary.getSize(), is((long)validByteArrayContent.length));
+ assertThat(binary, hasContent(validByteArrayContent));
+ }
+
+ @Test
+ public void shouldConstructFromEmptyByteArray() {
+ validByteArrayContent = new byte[0];
+ binary = new InMemoryBinary(validByteArrayContent);
+ assertThat(binary.getSize(), is(0l));
+ assertThat(binary, hasNoContent());
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotConstructFromNullByteArray() {
+ new InMemoryBinary(null);
+ }
+
+ @Test
+ public void shouldHaveSizeThatMatchesContentLength() {
+ assertThat(binary.getSize(), is((long)validByteArrayContent.length));
+ }
+
+ @Test
+ public void shouldProvideInputStreamToContent() throws IOException {
+ InputStream stream = binary.getStream();
+ byte[] actual = IoUtil.readBytes(stream); // closes the stream
+ assertThat(actual.length, is(validByteArrayContent.length));
+ for (int i = 0, len = actual.length; i != len; ++i) {
+ assertThat(actual[i], is(validByteArrayContent[i]));
+ }
+ }
+
+ @Test
+ public void shouldConsiderEquivalentThoseInstancesWithSameContent() {
+ Binary another = new InMemoryBinary(validByteArrayContent);
+ assertThat(binary.equals(another), is(true));
+ assertThat(binary.compareTo(another), is(0));
+ assertThat(binary, is(another));
+ assertThat(binary, hasContent(validByteArrayContent));
+ assertThat(another, hasContent(validByteArrayContent));
+ }
+
+ @Test
+ public void shouldUseSizeWhenComparing() {
+ byte[] shorterContent = new byte[validByteArrayContent.length - 2];
+ for (int i = 0; i != shorterContent.length; ++i) {
+ shorterContent[i] = validByteArrayContent[i];
+ }
+ Binary another = new InMemoryBinary(shorterContent);
+ assertThat(binary.equals(another), is(false));
+ assertThat(binary.compareTo(another), is(1));
+ assertThat(another.compareTo(binary), is(-1));
+ assertThat(another, hasContent(shorterContent));
+ }
+
+ @Test
+ public void shouldBeRecoverableFromExternalizedForm() throws Exception {
+ ByteArrayOutputStream contentStream = new ByteArrayOutputStream();
+ ObjectOutputStream output = new ObjectOutputStream(contentStream);
+ // Write the binary object ...
+ binary.writeExternal(output);
+ output.close();
+ // Now read the object back in ...
+ ByteArrayInputStream contentInputStream = new ByteArrayInputStream(contentStream.toByteArray());
+ ObjectInputStream input = new ObjectInputStream(contentInputStream);
+ InMemoryBinary recovered = new InMemoryBinary();
+ recovered.readExternal(input);
+ input.close();
+ // Compare ...
+ assertThat(recovered, is(binary));
+ assertThat(recovered, hasContent(binary));
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 11 months
DNA SVN: r194 - in branches/federation/dna-spi/src: test/java/org/jboss/dna/spi/graph/impl and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-24 11:44:34 -0400 (Sat, 24 May 2008)
New Revision: 194
Added:
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BinaryContains.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactoryTest.java
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java
Log:
DNA-67: Create graph API for federation engine
http://jira.jboss.org/jira/browse/DNA-67
Added unit test for InMemoryBinaryValueFactory, and added new "BinaryContains" JUnit (Hamcrest) matcher.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java 2008-05-24 03:52:30 UTC (rev 193)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java 2008-05-24 15:44:34 UTC (rev 194)
@@ -90,6 +90,20 @@
/**
* {@inheritDoc}
*/
+ @Override
+ public boolean equals( Object obj ) {
+ if (obj == this) return true;
+ if (obj instanceof Binary) {
+ Binary that = (Binary)obj;
+ if (this.getSize() != that.getSize()) return false;
+ return ValueComparators.BINARY_COMPARATOR.compare(this, that) == 0;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public void readExternal( ObjectInput in ) throws IOException {
int length = in.readInt();
this.bytes = new byte[length];
@@ -104,4 +118,19 @@
out.write(this.bytes);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(super.toString());
+ sb.append(" len=").append(getSize()).append("; [");
+ int len = (int)Math.min(getSize(), 20l);
+ for (int i = 0; i != len; ++i) {
+ if (i != 0) sb.append(',');
+ sb.append(this.bytes[i]);
+ }
+ return sb.toString();
+ }
+
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java 2008-05-24 03:52:30 UTC (rev 193)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java 2008-05-24 15:44:34 UTC (rev 194)
@@ -31,7 +31,6 @@
import java.util.Date;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextEncoder;
-import org.jboss.dna.common.util.DateUtil;
import org.jboss.dna.common.util.IoUtil;
import org.jboss.dna.spi.SpiI18n;
import org.jboss.dna.spi.graph.Name;
@@ -124,7 +123,7 @@
*/
public String create( Calendar value ) {
if (value == null) return null;
- return DateUtil.getDateAsStandardString(value);
+ return new JodaDateTime(value).getString();
}
/**
@@ -132,7 +131,7 @@
*/
public String create( Date value ) {
if (value == null) return null;
- return DateUtil.getDateAsStandardString(value);
+ return new JodaDateTime(value).getString();
}
/**
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BinaryContains.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BinaryContains.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BinaryContains.java 2008-05-24 15:44:34 UTC (rev 194)
@@ -0,0 +1,96 @@
+/*
+ * 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.UnsupportedEncodingException;
+import org.hamcrest.Description;
+import org.hamcrest.Factory;
+import org.hamcrest.Matcher;
+import org.jboss.dna.spi.graph.Binary;
+import org.junit.matchers.TypeSafeMatcher;
+
+/**
+ * @author Randall Hauch
+ */
+public class BinaryContains extends TypeSafeMatcher<Binary> {
+
+ private byte[] expectedContent;
+
+ public BinaryContains( byte[] expectedContent ) {
+ this.expectedContent = expectedContent;
+ }
+
+ public BinaryContains( Binary expectedContent ) {
+ try {
+ expectedContent.acquire();
+ this.expectedContent = expectedContent.getBytes();
+ } finally {
+ expectedContent.release();
+ }
+ }
+
+ @Override
+ public boolean matchesSafely( Binary content ) {
+ try {
+ content.acquire();
+ byte[] actualContents = content.getBytes();
+ if (actualContents.length != expectedContent.length) return false;
+ for (int i = 0, len = actualContents.length; i != len; ++i) {
+ if (actualContents[i] != expectedContent[i]) return false;
+ }
+ return true;
+ } finally {
+ content.release();
+ }
+ }
+
+ protected String getDisplayableString( byte[] values ) {
+ StringBuilder sb = new StringBuilder("byte[]: ");
+ sb.append(" len=").append(values.length).append("; [");
+ int len = (int)Math.min(values.length, 20l);
+ for (int i = 0; i != len; ++i) {
+ if (i != 0) sb.append(',');
+ sb.append(values[i]);
+ }
+ return sb.toString();
+ }
+
+ public void describeTo( Description description ) {
+ description.appendText("a binary containing ").appendValue(getDisplayableString(expectedContent));
+ }
+
+ @Factory
+ public static Matcher<Binary> hasContent( Binary expectedContent ) {
+ return new BinaryContains(expectedContent);
+ }
+
+ @Factory
+ public static Matcher<Binary> hasContent( String expectedContent ) throws UnsupportedEncodingException {
+ return new BinaryContains(expectedContent.getBytes("UTF-8"));
+ }
+
+ @Factory
+ public static Matcher<Binary> hasContent( byte[] expectedContent ) {
+ return new BinaryContains(expectedContent);
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BinaryContains.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactoryTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactoryTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactoryTest.java 2008-05-24 15:44:34 UTC (rev 194)
@@ -0,0 +1,177 @@
+/*
+ * 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.jboss.dna.spi.graph.impl.BinaryContains.hasContent;
+import static org.junit.Assert.assertThat;
+import java.io.ByteArrayInputStream;
+import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.UUID;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Reference;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class InMemoryBinaryValueFactoryTest {
+
+ private InMemoryBinaryValueFactory factory;
+ private StringValueFactory stringFactory;
+ private NameValueFactory nameFactory;
+ private BasicNamespaceRegistry namespaceRegistry;
+ private PathValueFactory pathFactory;
+ private TextEncoder encoder;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ encoder = Path.URL_ENCODER;
+ stringFactory = new StringValueFactory(encoder);
+ factory = new InMemoryBinaryValueFactory(encoder, stringFactory);
+ namespaceRegistry = new BasicNamespaceRegistry();
+ namespaceRegistry.register("jboss", "http://www.jboss.org");
+ namespaceRegistry.register("dna", "http://www.jboss.org/dna");
+ nameFactory = new NameValueFactory(namespaceRegistry, encoder, stringFactory);
+ pathFactory = new PathValueFactory(encoder, stringFactory, nameFactory);
+ }
+
+ @Test
+ public void shouldCreateBinaryFromBooleanValue() {
+ factory.create(true);
+ }
+
+ @Test
+ public void shouldCreateDecimalFromString() throws UnsupportedEncodingException {
+ assertThat(factory.create("1"), hasContent("1"));
+ assertThat(factory.create("-1.0"), hasContent("-1.0"));
+ assertThat(factory.create("100.000101"), hasContent("100.000101"));
+ assertThat(factory.create("quick brown fox."), hasContent("quick brown fox."));
+ }
+
+ @Test
+ public void shouldCreateBinaryFromStringIncludingfLeadingAndTrailingWhitespace() throws UnsupportedEncodingException {
+ assertThat(factory.create(" 1 "), hasContent(" 1 "));
+ assertThat(factory.create(" -1.0 "), hasContent(" -1.0 "));
+ assertThat(factory.create(" 100.000101 "), hasContent(" 100.000101 "));
+ assertThat(factory.create(" quick brown fox. "), hasContent(" quick brown fox. "));
+ }
+
+ @Test
+ public void shouldCreateBinaryFromIntegerValue() throws UnsupportedEncodingException {
+ assertThat(factory.create(1), hasContent(Integer.toString(1)));
+ assertThat(factory.create(-1), hasContent(Integer.toString(-1)));
+ assertThat(factory.create(123456), hasContent(Integer.toString(123456)));
+ }
+
+ @Test
+ public void shouldCreateBinaryFromLongValue() throws UnsupportedEncodingException {
+ assertThat(factory.create(1l), hasContent(Long.toString(1)));
+ assertThat(factory.create(-1l), hasContent(Long.toString(-1)));
+ assertThat(factory.create(123456l), hasContent(Long.toString(123456)));
+ }
+
+ @Test
+ public void shouldCreateBinaryFromFloatValue() throws UnsupportedEncodingException {
+ assertThat(factory.create(1.0f), hasContent(Float.toString(1.0f)));
+ assertThat(factory.create(-1.0f), hasContent(Float.toString(-1.0f)));
+ assertThat(factory.create(123456.23f), hasContent(Float.toString(123456.23f)));
+ }
+
+ @Test
+ public void shouldCreateBinaryFromDoubleValue() throws UnsupportedEncodingException {
+ assertThat(factory.create(1.0d), hasContent(Double.toString(1.0d)));
+ assertThat(factory.create(-1.0d), hasContent(Double.toString(-1.0)));
+ assertThat(factory.create(123456.23d), hasContent(Double.toString(123456.23)));
+ }
+
+ @Test
+ public void shouldCreateBinaryFromBigDecimal() throws UnsupportedEncodingException {
+ BigDecimal value = new BigDecimal(100);
+ assertThat(factory.create(value), hasContent(value.toString()));
+ }
+
+ @Test
+ public void shouldCreateBinaryFromDate() throws UnsupportedEncodingException {
+ Date value = new Date();
+ assertThat(factory.create(value), hasContent(new JodaDateTime(value).toString()));
+ }
+
+ @Test
+ public void shouldCreateBinaryFromCalendar() throws UnsupportedEncodingException {
+ Calendar value = Calendar.getInstance();
+ assertThat(factory.create(value), hasContent(new JodaDateTime(value).toString()));
+ }
+
+ @Test
+ public void shouldCreateBinaryFromName() throws UnsupportedEncodingException {
+ Name value = nameFactory.create("jboss:localName");
+ assertThat(factory.create(value), hasContent("{" + encoder.encode("http://www.jboss.org") + "}" + encoder.encode("localName")));
+ }
+
+ @Test
+ public void shouldCreateBinaryFromPath() throws UnsupportedEncodingException {
+ Path value = pathFactory.create("/a/b/c/jboss:localName");
+ assertThat(factory.create(value), hasContent("/{}a/{}b/{}c/{" + encoder.encode("http://www.jboss.org") + "}" + encoder.encode("localName")));
+ }
+
+ @Test
+ public void shouldCreateBinaryFromReference() throws UnsupportedEncodingException {
+ UUID uuid = UUID.randomUUID();
+ Reference value = new UuidReference(uuid);
+ assertThat(factory.create(value), hasContent(uuid.toString()));
+ }
+
+ @Test
+ public void shouldCreateBinaryFromUri() throws Exception {
+ URI value = new URI("http://www.jboss.org");
+ assertThat(factory.create(value), hasContent("http://www.jboss.org"));
+ }
+
+ @Test
+ public void shouldCreateBinaryFromByteArray() throws Exception {
+ byte[] value = "Some byte string".getBytes("UTF-8");
+ assertThat(factory.create(value), hasContent(value));
+ }
+
+ @Test
+ public void shouldCreateBinaryFromInputStream() throws Exception {
+ String value = "Some test string";
+ assertThat(factory.create(new ByteArrayInputStream(value.getBytes("UTF-8"))), hasContent(value));
+ }
+
+ @Test
+ public void shouldCreateBinaryFromReader() throws Exception {
+ String value = "Some test string";
+ assertThat(factory.create(new StringReader(value)), hasContent(value));
+ }
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactoryTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 11 months
DNA SVN: r193 - in branches/federation/dna-spi/src: test/java/org/jboss/dna/spi/graph/impl and 1 other directory.
by dna-commits@lists.jboss.org
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
+ */
+@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
- */
-@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")));
+ }
+}
15 years, 11 months
DNA SVN: r192 - in branches/federation/dna-spi/src: main/java/org/jboss/dna/spi/graph/impl and 1 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-23 23:48:56 -0400 (Fri, 23 May 2008)
New Revision: 192
Added:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTimeFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateValueFactory.java
Removed:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DateValueFactory.java
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DateValueFactoryTest.java
Log:
DNA-67: Create graph API for federation engine
http://jira.jboss.org/jira/browse/DNA-67
Added DateTimeFactory interface with additional methods for create DateTime instances.
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTimeFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTimeFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTimeFactory.java 2008-05-24 03:48:56 UTC (rev 192)
@@ -0,0 +1,76 @@
+/*
+ * 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;
+
+/**
+ * @author Randall Hauch
+ */
+public interface DateTimeFactory extends ValueFactory<DateTime> {
+
+ /**
+ * Create a date-time instance for the current time.
+ * @return the date-time instance
+ */
+ DateTime create();
+
+ /**
+ * Create a date-time instance given the individual values for the fields
+ * @param year the year of the era
+ * @param monthOfYear the month of the year
+ * @param dayOfMonth the day of the month
+ * @param hourOfDay the hour of the day
+ * @param minuteOfHour the minute of the hour
+ * @param secondOfMinute the second of the minute
+ * @param millisecondsOfSecond the milliseconds of the second
+ * @return the date-time instance
+ */
+ DateTime create( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisecondsOfSecond );
+
+ /**
+ * Create a date-time instance given the individual values for the fields
+ * @param year the year of the era
+ * @param monthOfYear the month of the year
+ * @param dayOfMonth the day of the month
+ * @param hourOfDay the hour of the day
+ * @param minuteOfHour the minute of the hour
+ * @param secondOfMinute the second of the minute
+ * @param millisecondsOfSecond the milliseconds of the second
+ * @param timeZoneOffsetHours the number of hours offset from UTC for the time zone
+ * @return the date-time instance
+ */
+ DateTime create( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisecondsOfSecond, int timeZoneOffsetHours );
+
+ /**
+ * Create a date-time instance given the individual values for the fields
+ * @param year the year of the era
+ * @param monthOfYear the month of the year
+ * @param dayOfMonth the day of the month
+ * @param hourOfDay the hour of the day
+ * @param minuteOfHour the minute of the hour
+ * @param secondOfMinute the second of the minute
+ * @param millisecondsOfSecond the milliseconds of the second
+ * @param timeZoneId the ID of the time zone (e.g, "PST", "UTC", "EDT"); may not be null
+ * @return the date-time instance
+ */
+ DateTime create( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisecondsOfSecond, String timeZoneId );
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTimeFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java 2008-05-24 03:23:42 UTC (rev 191)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java 2008-05-24 03:48:56 UTC (rev 192)
@@ -80,7 +80,7 @@
* Get the value factory for {@link PropertyType#DATE date} properties.
* @return the factory; never null
*/
- ValueFactory<DateTime> getDateFactory();
+ DateTimeFactory getDateFactory();
/**
* Get the value factory for {@link PropertyType#BOOLEAN boolean} properties.
Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DateValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DateValueFactory.java 2008-05-24 03:23:42 UTC (rev 191)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DateValueFactory.java 2008-05-24 03:48:56 UTC (rev 192)
@@ -1,184 +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.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
- */
-@Immutable
-public class DateValueFactory extends AbstractValueFactory<DateTime> {
-
- public DateValueFactory( 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));
- }
-
-}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-05-24 03:23:42 UTC (rev 191)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-05-24 03:48:56 UTC (rev 192)
@@ -71,6 +71,14 @@
this.instance = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisecondsOfSecond, dateTimeZone);
}
+ public JodaDateTime( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisecondsOfSecond, int timeZoneOffsetHours ) {
+ this.instance = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisecondsOfSecond, DateTimeZone.forOffsetHours(timeZoneOffsetHours));
+ }
+
+ public JodaDateTime( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisecondsOfSecond, String timeZoneId ) {
+ this.instance = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisecondsOfSecond, DateTimeZone.forID(timeZoneId));
+ }
+
public JodaDateTime( java.util.Date jdkDate ) {
this.instance = new DateTime(jdkDate);
}
Copied: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateValueFactory.java (from rev 191, branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DateValueFactory.java)
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateValueFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateValueFactory.java 2008-05-24 03:48:56 UTC (rev 192)
@@ -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
+ */
+@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);
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateValueFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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:23:42 UTC (rev 191)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java 2008-05-24 03:48:56 UTC (rev 192)
@@ -31,7 +31,7 @@
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.graph.Binary;
-import org.jboss.dna.spi.graph.DateTime;
+import org.jboss.dna.spi.graph.DateTimeFactory;
import org.jboss.dna.spi.graph.NameFactory;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.PathFactory;
@@ -51,7 +51,7 @@
private final ValueFactory<String> stringFactory;
private final ValueFactory<Binary> binaryFactory;
private final ValueFactory<Boolean> booleanFactory;
- private final ValueFactory<DateTime> dateFactory;
+ private final DateTimeFactory dateFactory;
private final ValueFactory<BigDecimal> decimalFactory;
private final ValueFactory<Double> doubleFactory;
private final ValueFactory<Long> longFactory;
@@ -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 = getFactory(factories, new DateValueFactory(this.encoder, this.stringFactory));
+ this.dateFactory = (DateTimeFactory)getFactory(factories, new JodaDateValueFactory(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));
@@ -161,7 +161,7 @@
/**
* {@inheritDoc}
*/
- public ValueFactory<DateTime> getDateFactory() {
+ public DateTimeFactory getDateFactory() {
return this.dateFactory;
}
Modified: 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:23:42 UTC (rev 191)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DateValueFactoryTest.java 2008-05-24 03:48:56 UTC (rev 192)
@@ -52,7 +52,7 @@
LAST_YEAR = new JodaDateTime(now.minusYears(1));
}
- private DateValueFactory factory;
+ private JodaDateValueFactory factory;
private StringValueFactory stringFactory;
private Mockery context;
@@ -63,7 +63,7 @@
public void setUp() throws Exception {
TextEncoder encoder = Path.URL_ENCODER;
stringFactory = new StringValueFactory(encoder);
- factory = new DateValueFactory(encoder, stringFactory);
+ factory = new JodaDateValueFactory(encoder, stringFactory);
context = new Mockery();
}
15 years, 11 months
DNA SVN: r191 - in branches/federation: dna-common/src/main/java/org/jboss/dna/common/util and 5 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-23 23:23:42 -0400 (Fri, 23 May 2008)
New Revision: 191
Added:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
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/LongValueFactoryTest.java
Modified:
branches/federation/dna-common/src/main/java/org/jboss/dna/common/util/DateUtil.java
branches/federation/dna-common/src/test/java/org/jboss/dna/common/util/DateUtilTest.java
branches/federation/dna-spi/pom.xml
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DateValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java
branches/federation/pom.xml
Log:
After being fed up with java.util.Date and java.util.Calendar problems and inaccuracies, I created a DateTime interface in the graph SPI to wrap Joda-Time DateTime instances and to provide a migration path to JSR-310, which will be based upon Joda-Time.
Modified: branches/federation/dna-common/src/main/java/org/jboss/dna/common/util/DateUtil.java
===================================================================
--- branches/federation/dna-common/src/main/java/org/jboss/dna/common/util/DateUtil.java 2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-common/src/main/java/org/jboss/dna/common/util/DateUtil.java 2008-05-24 03:23:42 UTC (rev 191)
@@ -180,7 +180,7 @@
}
// Create the calendar object and start setting the fields ...
- GregorianCalendar calendar = new GregorianCalendar();
+ Calendar calendar = Calendar.getInstance();
calendar.clear();
// And start setting the fields. Note that Integer.parseInt should never fail, since we're checking for null and the
Modified: branches/federation/dna-common/src/test/java/org/jboss/dna/common/util/DateUtilTest.java
===================================================================
--- branches/federation/dna-common/src/test/java/org/jboss/dna/common/util/DateUtilTest.java 2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-common/src/test/java/org/jboss/dna/common/util/DateUtilTest.java 2008-05-24 03:23:42 UTC (rev 191)
@@ -180,4 +180,29 @@
assertThat(DateUtil.getCalendarFromStandardString("2008-W216").get(Calendar.WEEK_OF_YEAR), is(21));
}
+ @Test
+ public void shouldConvertCalendarToStringAndBackMultipleTimes() throws Exception {
+ Calendar cal1 = Calendar.getInstance();
+ String cal1Str = DateUtil.getDateAsStandardString(cal1);
+ Calendar cal2 = DateUtil.getCalendarFromStandardString(cal1Str);
+ // Force the calculation of all fields for both calendars ...
+ cal1.add(Calendar.DAY_OF_YEAR, 1);
+ cal2.add(Calendar.DAY_OF_YEAR, 1);
+ cal1.add(Calendar.DAY_OF_YEAR, -1);
+ cal2.add(Calendar.DAY_OF_YEAR, -1);
+ assertThat(cal1.getTimeInMillis(), is(cal2.getTimeInMillis()));
+ assertThat(cal1.compareTo(cal2), is(0));
+ assertThat(cal1, is(cal2));
+ String cal2Str = DateUtil.getDateAsStandardString(cal2);
+ assertThat(cal1Str, is(cal2Str));
+ Calendar cal3 = DateUtil.getCalendarFromStandardString(cal2Str);
+ cal3.add(Calendar.DAY_OF_YEAR, 1);
+ cal3.add(Calendar.DAY_OF_YEAR, -1);
+ assertThat(cal1, is(cal3));
+ assertThat(cal3, is(cal3));
+ String cal3Str = DateUtil.getDateAsStandardString(cal3);
+ assertThat(cal1Str, is(cal3Str));
+ assertThat(cal2Str, is(cal3Str));
+ }
+
}
Modified: branches/federation/dna-spi/pom.xml
===================================================================
--- branches/federation/dna-spi/pom.xml 2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-spi/pom.xml 2008-05-24 03:23:42 UTC (rev 191)
@@ -31,6 +31,10 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>joda-time</groupId>
+ <artifactId>joda-time</artifactId>
+ </dependency>
<!--
Testing (note the scope)
-->
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java 2008-05-24 03:23:42 UTC (rev 191)
@@ -0,0 +1,167 @@
+/*
+ * 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;
+
+import java.io.Externalizable;
+import java.util.Locale;
+
+/**
+ * An immutable date-time class that represents an instance in time. This class is designed to hide the horrible implementations
+ * of the JDK date and calendar classes, which are being overhauled (and replaced) under <a
+ * href="http://jcp.org/en/jsr/detail?id=310">JSR-310</a>, which will be based upon <a
+ * href="http://joda-time.sourceforge.net/">Joda-Time</a>. This class serves as a stable migration path toward the new JSR 310
+ * classes.
+ * @author Randall Hauch
+ */
+public interface DateTime extends Comparable<DateTime>, Externalizable {
+
+ /**
+ * Get the ISO-8601 representation of this instance in time.
+ * @return the string representation; never null
+ */
+ String getString();
+
+ /**
+ * Get the number of milliseconds from 1970-01-01T00:00Z. This value is consistent with the JDK {@link java.util.Date Date}
+ * and {@link java.util.Calendar Calendar} classes.
+ * @return the number of milliseconds from 1970-01-01T00:00Z
+ */
+ long getMilliseconds();
+
+ /**
+ * Get this instance represented as a standard JDK {@link java.util.Date} instance. Note that this conversion loses the time
+ * zone information, as the standard JDK {@link java.util.Date} does not represent time zones.
+ * @return this instance in time as a JDK Date; never null
+ */
+ java.util.Date toDate();
+
+ /**
+ * Get this instance represented as a standard JDK {@link java.util.Calendar} instance, in the
+ * {@link Locale#getDefault() default locale}.
+ * @return this instance in time as a JDK Calendar; never null
+ */
+ java.util.Calendar toCalendar();
+
+ /**
+ * Get this instance represented as a standard JDK {@link java.util.Calendar} instance, in the specified {@link Locale locale}.
+ * @param locale the locale in which the Calendar instance is desired; may be null if the
+ * {@link Locale#getDefault() default locale} is to be used.
+ * @return this instance in time as a JDK Calendar; never null
+ */
+ java.util.Calendar toCalendar( Locale locale );
+
+ /**
+ * Get this instance represented as a standard JDK {@link java.util.GregorianCalendar} instance.
+ * @return this instance in time as a JDK GregorianCalendar; never null
+ */
+ java.util.GregorianCalendar toGregorianCalendar();
+
+ /**
+ * Get the era of this instance in time.
+ * @return the era
+ */
+ int getEra();
+
+ /**
+ * Get the era of this instance in time.
+ * @return the era
+ */
+ int getYear();
+
+ /**
+ * Get the era of this instance in time.
+ * @return the era
+ */
+ int getWeekyear();
+
+ /**
+ * Get the era of this instance in time.
+ * @return the era
+ */
+ int getCenturyOfEra();
+
+ /**
+ * Get the year of the era of this instance in time.
+ * @return the year of the era
+ */
+ int getYearOfEra();
+
+ /**
+ * Get the year of this century of this instance in time.
+ * @return the year of the century
+ */
+ int getYearOfCentury();
+
+ /**
+ * Get the month of the year of this instance in time.
+ * @return the month number
+ */
+ int getMonthOfYear();
+
+ /**
+ * Get the week of the weekyear of this instance in time.
+ * @return the week of the weekyear
+ */
+ int getWeekOfWeekyear();
+
+ /**
+ * Get the day of the year of this instance in time.
+ * @return the day of the year
+ */
+ int getDayOfYear();
+
+ /**
+ * Get the day of the month value of this instance in time.
+ * @return the day of the month
+ */
+ int getDayOfMonth();
+
+ /**
+ * Get the day of the week value of this instance in time.
+ * @return the day of the week
+ */
+ int getDayOfWeek();
+
+ /**
+ * Get the hour of the day of this instance in time.
+ * @return the hour of the day
+ */
+ int getHourOfDay();
+
+ /**
+ * Get the minute of this instance in time.
+ * @return the minute of the hour
+ */
+ int getMinuteOfHour();
+
+ /**
+ * Get the seconds of the minute value of this instance in time.
+ * @return the seconds of the minute
+ */
+ int getSecondOfMinute();
+
+ /**
+ * Get the milliseconds of the second value of this instance in time.
+ * @return the milliseconds
+ */
+ int getMillisOfSecond();
+}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java 2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java 2008-05-24 03:23:42 UTC (rev 191)
@@ -23,7 +23,6 @@
import java.math.BigDecimal;
import java.net.URI;
-import java.util.Calendar;
import java.util.Comparator;
import net.jcip.annotations.Immutable;
import org.jboss.dna.spi.SpiI18n;
@@ -39,7 +38,7 @@
LONG("Long", ValueComparators.LONG_COMPARATOR, Long.class),
DOUBLE("Double", ValueComparators.DOUBLE_COMPARATOR, Double.class),
DECIMAL("Decimal", ValueComparators.DECIMAL_COMPARATOR, BigDecimal.class),
- DATE("Date", ValueComparators.CALENDAR_COMPARATOR, Calendar.class),
+ DATE("Date", ValueComparators.DATE_TIME_COMPARATOR, DateTime.class),
BOOLEAN("Boolean", ValueComparators.BOOLEAN_COMPARATOR, Boolean.class),
NAME("Name", ValueComparators.NAME_COMPARATOR, Name.class),
PATH("Path", ValueComparators.PATH_COMPARATOR, Path.class),
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java 2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java 2008-05-24 03:23:42 UTC (rev 191)
@@ -163,6 +163,18 @@
}
};
/**
+ * A comparator of date-time instances.
+ */
+ public static final Comparator<DateTime> DATE_TIME_COMPARATOR = new Comparator<DateTime>() {
+
+ public int compare( DateTime o1, DateTime o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
+ return o1.compareTo(o2);
+ }
+ };
+ /**
* A comparator of date values.
*/
public static final Comparator<Date> DATE_COMPARATOR = new Comparator<Date>() {
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java 2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java 2008-05-24 03:23:42 UTC (rev 191)
@@ -23,7 +23,6 @@
import java.math.BigDecimal;
import java.net.URI;
-import java.util.Calendar;
/**
* The set of standard {@link ValueFactory} instances.
@@ -81,7 +80,7 @@
* Get the value factory for {@link PropertyType#DATE date} properties.
* @return the factory; never null
*/
- ValueFactory<Calendar> getDateFactory();
+ ValueFactory<DateTime> getDateFactory();
/**
* Get the value factory for {@link PropertyType#BOOLEAN boolean} properties.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DateValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DateValueFactory.java 2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DateValueFactory.java 2008-05-24 03:23:42 UTC (rev 191)
@@ -26,13 +26,12 @@
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URI;
-import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextEncoder;
-import org.jboss.dna.common.util.DateUtil;
import org.jboss.dna.spi.SpiI18n;
+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.PropertyType;
@@ -45,7 +44,7 @@
* @author Randall Hauch
*/
@Immutable
-public class DateValueFactory extends AbstractValueFactory<Calendar> {
+public class DateValueFactory extends AbstractValueFactory<DateTime> {
public DateValueFactory( TextEncoder encoder, ValueFactory<String> stringValueFactory ) {
super(PropertyType.DATE, encoder, stringValueFactory);
@@ -54,11 +53,11 @@
/**
* {@inheritDoc}
*/
- public Calendar create( String value ) throws ValueFormatException {
+ public DateTime create( String value ) throws ValueFormatException {
if (value == null) return null;
try {
- return DateUtil.getCalendarFromStandardString(value);
- } catch (ParseException e) {
+ return new JodaDateTime(value.trim());
+ } catch (IllegalArgumentException e) {
throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), e);
}
}
@@ -66,7 +65,7 @@
/**
* {@inheritDoc}
*/
- public Calendar create( String value, TextEncoder decoder ) {
+ 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));
}
@@ -74,44 +73,42 @@
/**
* {@inheritDoc}
*/
- public Calendar create( int value ) {
+ public DateTime create( int value ) {
return create((long)value);
}
/**
* {@inheritDoc}
*/
- public Calendar create( long value ) {
- Calendar result = Calendar.getInstance();
- result.setTimeInMillis(value);
- return result;
+ public DateTime create( long value ) {
+ return new JodaDateTime(value);
}
/**
* {@inheritDoc}
*/
- public Calendar create( boolean value ) throws ValueFormatException {
+ public DateTime create( boolean value ) throws ValueFormatException {
throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
}
/**
* {@inheritDoc}
*/
- public Calendar create( float value ) throws ValueFormatException {
+ public DateTime create( float value ) throws ValueFormatException {
return create((long)value);
}
/**
* {@inheritDoc}
*/
- public Calendar create( double value ) throws ValueFormatException {
+ public DateTime create( double value ) throws ValueFormatException {
return create((long)value);
}
/**
* {@inheritDoc}
*/
- public Calendar create( BigDecimal value ) throws ValueFormatException {
+ public DateTime create( BigDecimal value ) throws ValueFormatException {
if (value == null) return null;
return create(value.longValue());
}
@@ -119,51 +116,51 @@
/**
* {@inheritDoc}
*/
- public Calendar create( Calendar value ) throws ValueFormatException {
+ public DateTime create( Calendar value ) throws ValueFormatException {
if (value == null) return null;
- return create(value.getTimeInMillis());
+ return new JodaDateTime(value);
}
/**
* {@inheritDoc}
*/
- public Calendar create( Date value ) throws ValueFormatException {
+ public DateTime create( Date value ) throws ValueFormatException {
if (value == null) return null;
- return create(value.getTime());
+ return new JodaDateTime(value);
}
/**
* {@inheritDoc}
*/
- public Calendar create( Name value ) throws ValueFormatException {
+ public DateTime create( Name value ) throws ValueFormatException {
throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Name.class.getSimpleName(), value));
}
/**
* {@inheritDoc}
*/
- public Calendar create( Path value ) throws ValueFormatException {
+ public DateTime create( Path value ) throws ValueFormatException {
throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value));
}
/**
* {@inheritDoc}
*/
- public Calendar create( Reference value ) throws ValueFormatException {
+ public DateTime create( Reference value ) throws ValueFormatException {
throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Reference.class.getSimpleName(), value));
}
/**
* {@inheritDoc}
*/
- public Calendar create( URI value ) throws ValueFormatException {
+ public DateTime create( URI value ) throws ValueFormatException {
throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), URI.class.getSimpleName(), value));
}
/**
* {@inheritDoc}
*/
- public Calendar create( byte[] value ) throws ValueFormatException {
+ 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));
}
@@ -171,7 +168,7 @@
/**
* {@inheritDoc}
*/
- public Calendar create( InputStream stream, int approximateLength ) throws IOException, ValueFormatException {
+ 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));
}
@@ -179,7 +176,7 @@
/**
* {@inheritDoc}
*/
- public Calendar create( Reader reader, int approximateLength ) throws IOException, ValueFormatException {
+ 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));
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java 2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java 2008-05-24 03:23:42 UTC (rev 191)
@@ -55,7 +55,7 @@
public Double create( String value ) throws ValueFormatException {
if (value == null) return null;
try {
- return Double.valueOf(value);
+ return Double.valueOf(value.trim());
} catch (NumberFormatException e) {
throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), e);
}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-05-24 03:23:42 UTC (rev 191)
@@ -0,0 +1,291 @@
+/*
+ * 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.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import net.jcip.annotations.Immutable;
+import org.joda.time.Chronology;
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
+
+/**
+ * Implementation of DateTime based upon the Joda-Time library.
+ * @author Randall Hauch
+ */
+@Immutable
+public class JodaDateTime implements org.jboss.dna.spi.graph.DateTime {
+
+ private DateTime instance;
+ private transient String formattedString;
+
+ public JodaDateTime( String iso8601 ) {
+ this.instance = new DateTime(iso8601);
+ }
+
+ public JodaDateTime( long milliseconds ) {
+ this.instance = new DateTime(milliseconds);
+ }
+
+ public JodaDateTime( long milliseconds, Chronology chronology ) {
+ this.instance = new DateTime(milliseconds, chronology);
+ }
+
+ public JodaDateTime( DateTimeZone dateTimeZone ) {
+ this.instance = new DateTime(dateTimeZone);
+ }
+
+ public JodaDateTime( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisecondsOfSecond ) {
+ this.instance = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisecondsOfSecond);
+ }
+
+ public JodaDateTime( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisecondsOfSecond, Chronology chronology ) {
+ this.instance = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisecondsOfSecond, chronology);
+ }
+
+ public JodaDateTime( int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisecondsOfSecond, DateTimeZone dateTimeZone ) {
+ this.instance = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisecondsOfSecond, dateTimeZone);
+ }
+
+ public JodaDateTime( java.util.Date jdkDate ) {
+ this.instance = new DateTime(jdkDate);
+ }
+
+ public JodaDateTime( java.util.Calendar jdkCalendar ) {
+ this.instance = new DateTime(jdkCalendar);
+ }
+
+ public JodaDateTime( DateTime dateTime ) {
+ this.instance = dateTime; // it's immutable, so just hold onto the supplied instance
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getCenturyOfEra() {
+ return this.instance.getCenturyOfEra();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getDayOfMonth() {
+ return this.instance.getDayOfMonth();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getDayOfWeek() {
+ return this.instance.getDayOfWeek();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getDayOfYear() {
+ return this.instance.getDayOfYear();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getEra() {
+ return this.instance.getEra();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getHourOfDay() {
+ return this.instance.getHourOfDay();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getMillisOfSecond() {
+ return this.instance.getMillisOfSecond();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getMilliseconds() {
+ return this.instance.getMillis();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getMinuteOfHour() {
+ return this.instance.getMinuteOfHour();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getMonthOfYear() {
+ return this.instance.getMonthOfYear();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getSecondOfMinute() {
+ return this.instance.getSecondOfMinute();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString() {
+ if (this.formattedString == null) {
+ // This is transient and can be done multiple times by concurrent threads (without locking),
+ // since the object is immutable
+ this.formattedString = this.instance.toString(org.joda.time.format.ISODateTimeFormat.dateTime());
+ }
+ return this.formattedString;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getWeekOfWeekyear() {
+ return this.instance.getWeekOfWeekyear();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getWeekyear() {
+ return this.instance.getWeekyear();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getYear() {
+ return this.instance.getYear();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getYearOfCentury() {
+ return this.instance.getYearOfCentury();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getYearOfEra() {
+ return this.instance.getYearOfEra();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Calendar toCalendar() {
+ return toCalendar(null);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Calendar toCalendar( Locale locale ) {
+ return this.instance.toCalendar(locale);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Date toDate() {
+ return this.instance.toDate();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public GregorianCalendar toGregorianCalendar() {
+ return this.instance.toGregorianCalendar();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int compareTo( org.jboss.dna.spi.graph.DateTime that ) {
+ return this.instance.compareTo(that);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ return this.instance.hashCode();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (obj == this) return true;
+ if (obj instanceof JodaDateTime) {
+ JodaDateTime that = (JodaDateTime)obj;
+ return this.instance.equals(that.instance);
+ }
+ if (obj instanceof DateTime) {
+ return this.instance.equals(obj);
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return getString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void readExternal( ObjectInput in ) throws IOException {
+ this.instance = new DateTime(in.readUTF());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void writeExternal( ObjectOutput out ) throws IOException {
+ out.writeUTF(this.getString());
+ }
+
+}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java 2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java 2008-05-24 03:23:42 UTC (rev 191)
@@ -55,7 +55,7 @@
public Long create( String value ) throws ValueFormatException {
if (value == null) return null;
try {
- return Long.valueOf(value);
+ return Long.valueOf(value.trim());
} catch (NumberFormatException e) {
throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), e);
}
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-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java 2008-05-24 03:23:42 UTC (rev 191)
@@ -23,7 +23,6 @@
import java.math.BigDecimal;
import java.net.URI;
-import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@@ -32,6 +31,7 @@
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.NameFactory;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.PathFactory;
@@ -51,7 +51,7 @@
private final ValueFactory<String> stringFactory;
private final ValueFactory<Binary> binaryFactory;
private final ValueFactory<Boolean> booleanFactory;
- private final ValueFactory<Calendar> dateFactory;
+ private final ValueFactory<DateTime> dateFactory;
private final ValueFactory<BigDecimal> decimalFactory;
private final ValueFactory<Double> doubleFactory;
private final ValueFactory<Long> longFactory;
@@ -161,7 +161,7 @@
/**
* {@inheritDoc}
*/
- public ValueFactory<Calendar> getDateFactory() {
+ public ValueFactory<DateTime> getDateFactory() {
return this.dateFactory;
}
Added: 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 (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DateValueFactoryTest.java 2008-05-24 03:23:42 UTC (rev 191)
@@ -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 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 DateValueFactory 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 DateValueFactory(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")));
+ }
+}
Modified: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java 2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java 2008-05-24 03:23:42 UTC (rev 191)
@@ -24,6 +24,7 @@
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;
@@ -152,10 +153,10 @@
@Test
public void shouldCreateDoubleFromReaderContainingStringWithDouble() throws Exception {
- assertThat(factory.create(new ByteArrayInputStream("0.1".getBytes("UTF-8"))), is(0.1d));
- assertThat(factory.create(new ByteArrayInputStream("1".getBytes("UTF-8"))), is(1.0d));
- assertThat(factory.create(new ByteArrayInputStream("-1.03".getBytes("UTF-8"))), is(-1.03));
- assertThat(factory.create(new ByteArrayInputStream("1003044".getBytes("UTF-8"))), is(1003044.d));
+ assertThat(factory.create(new StringReader("0.1")), is(0.1d));
+ assertThat(factory.create(new StringReader("1")), is(1.0d));
+ assertThat(factory.create(new StringReader("-1.03")), is(-1.03));
+ assertThat(factory.create(new StringReader("1003044")), is(1003044.d));
}
@Test( expected = ValueFormatException.class )
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/LongValueFactoryTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/LongValueFactoryTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/LongValueFactoryTest.java 2008-05-24 03:23:42 UTC (rev 191)
@@ -0,0 +1,178 @@
+/*
+ * 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 java.util.Date;
+import org.jboss.dna.common.text.TextEncoder;
+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 LongValueFactoryTest {
+
+ private LongValueFactory 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 LongValueFactory(encoder, stringFactory);
+ context = new Mockery();
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateDoubleFromBooleanValue() {
+ factory.create(true);
+ }
+
+ @Test
+ public void shouldCreateLongFromString() {
+ assertThat(factory.create("1"), is(Long.valueOf(1)));
+ assertThat(factory.create("-10"), is(Long.valueOf(-10)));
+ assertThat(factory.create("100000101"), is(Long.valueOf(100000101)));
+ }
+
+ @Test
+ public void shouldCreateLongFromStringRegardlessOfLeadingAndTrailingWhitespace() {
+ assertThat(factory.create(" 1 "), is(Long.valueOf(1)));
+ assertThat(factory.create(" -10 "), is(Long.valueOf(-10)));
+ assertThat(factory.create(" 100000101 "), is(Long.valueOf(100000101)));
+ }
+
+ @Test
+ public void shouldNotCreateLongFromIntegerValue() {
+ assertThat(factory.create(1), is(1l));
+ }
+
+ @Test
+ public void shouldNotCreateLongFromLongValue() {
+ assertThat(factory.create(1l), is(1l));
+ }
+
+ @Test
+ public void shouldNotCreateLongFromFloatValue() {
+ assertThat(factory.create(1.0f), is(1l));
+ assertThat(factory.create(1.023f), is(1l));
+ assertThat(factory.create(1.923f), is(1l));
+ }
+
+ @Test
+ public void shouldNotCreateLongFromDoubleValue() {
+ assertThat(factory.create(1.0122d), is(1l));
+ }
+
+ @Test
+ public void shouldCreateLongFromBigDecimal() {
+ BigDecimal value = new BigDecimal(100);
+ assertThat(factory.create(value), is(value.longValue()));
+ }
+
+ @Test
+ public void shouldCreateLongFromDate() {
+ Date value = new Date();
+ assertThat(factory.create(value), is(Long.valueOf(value.getTime())));
+ }
+
+ @Test
+ public void shouldCreateLongFromCalendar() {
+ Calendar value = Calendar.getInstance();
+ assertThat(factory.create(value), is(Long.valueOf(value.getTimeInMillis())));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateLongFromName() {
+ factory.create(context.mock(Name.class));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateLongFromPath() {
+ factory.create(context.mock(Path.class));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateLongFromReference() {
+ factory.create(context.mock(Reference.class));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateLongFromUri() throws Exception {
+ factory.create(new URI("http://www.jboss.org"));
+ }
+
+ @Test
+ public void shouldCreateLongFromByteArrayContainingUtf8EncodingOfStringWithLong() throws Exception {
+ assertThat(factory.create("0".getBytes("UTF-8")), is(0l));
+ assertThat(factory.create("10".getBytes("UTF-8")), is(10l));
+ assertThat(factory.create("-103".getBytes("UTF-8")), is(-103l));
+ assertThat(factory.create("1003044".getBytes("UTF-8")), is(1003044l));
+ }
+
+ @Test
+ public void shouldCreateLongFromInputStreamContainingUtf8EncodingOfStringWithLong() throws Exception {
+ assertThat(factory.create(new ByteArrayInputStream("0".getBytes("UTF-8"))), is(0l));
+ assertThat(factory.create(new ByteArrayInputStream("10".getBytes("UTF-8"))), is(10l));
+ assertThat(factory.create(new ByteArrayInputStream("-103".getBytes("UTF-8"))), is(-103l));
+ assertThat(factory.create(new ByteArrayInputStream("1003044".getBytes("UTF-8"))), is(1003044l));
+ }
+
+ @Test
+ public void shouldCreateLongFromReaderContainingStringWithLong() throws Exception {
+ assertThat(factory.create(new StringReader("0")), is(0l));
+ assertThat(factory.create(new StringReader("10")), is(10l));
+ assertThat(factory.create(new StringReader("-103")), is(-103l));
+ assertThat(factory.create(new StringReader("1003044")), is(1003044l));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateLongFromByteArrayContainingUtf8EncodingOfStringWithContentsOtherThanLong() throws Exception {
+ factory.create("something".getBytes("UTF-8"));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateLongFromInputStreamContainingUtf8EncodingOfStringWithContentsOtherThanLong() throws Exception {
+ factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateLongFromReaderContainingStringWithContentsOtherThanLong() throws Exception {
+ factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
+ }
+}
Modified: branches/federation/pom.xml
===================================================================
--- branches/federation/pom.xml 2008-05-23 20:44:56 UTC (rev 190)
+++ branches/federation/pom.xml 2008-05-24 03:23:42 UTC (rev 191)
@@ -274,6 +274,14 @@
<version>${dna-version}</version>
</dependency>
<!--
+ Time and Date
+ -->
+ <dependency>
+ <groupId>joda-time</groupId>
+ <artifactId>joda-time</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <!--
Rules
-->
<dependency>
15 years, 11 months
DNA SVN: r190 - in branches/federation/dna-spi/src: test/java/org/jboss/dna/spi/graph/impl and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-23 16:44:56 -0400 (Fri, 23 May 2008)
New Revision: 190
Added:
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistryTest.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BooleanValueFactoryTest.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DecimalValueFactoryTest.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java
Log:
DNA-67: Create graph API for federation engine
http://jira.jboss.org/jira/browse/DNA-67
Created unit tests for several of the basic implementation classes, and in the process changes some of the interfaces to handle functionality that was missing or incorrect.
Added more unit tests for the basic implementations.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java 2008-05-23 19:01:39 UTC (rev 189)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java 2008-05-23 20:44:56 UTC (rev 190)
@@ -21,6 +21,9 @@
*/
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;
@@ -103,6 +106,21 @@
if (value instanceof Path) return create((Path)value);
if (value instanceof Reference) return create((Reference)value);
if (value instanceof URI) return create((URI)value);
+ if (value instanceof byte[]) return create((byte[])value);
+ if (value instanceof InputStream) {
+ try {
+ return create((InputStream)value, 0);
+ } catch (IOException e) {
+ throw new ValueFormatException(e);
+ }
+ }
+ if (value instanceof Reader) {
+ try {
+ return create((Reader)value, 0);
+ } catch (IOException e) {
+ throw new ValueFormatException(e);
+ }
+ }
return create(value.toString());
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java 2008-05-23 19:01:39 UTC (rev 189)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java 2008-05-23 20:44:56 UTC (rev 190)
@@ -54,7 +54,7 @@
*/
public Boolean create( String value ) {
if (value == null) return null;
- return Boolean.valueOf(value);
+ return Boolean.valueOf(value.trim());
}
/**
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java 2008-05-23 19:01:39 UTC (rev 189)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java 2008-05-23 20:44:56 UTC (rev 190)
@@ -55,7 +55,7 @@
public BigDecimal create( String value ) throws ValueFormatException {
if (value == null) return null;
try {
- return new BigDecimal(value);
+ return new BigDecimal(value.trim());
} catch (NumberFormatException e) {
throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), e);
}
@@ -66,7 +66,7 @@
*/
public BigDecimal 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));
+ return create(getEncoder(decoder).decode(value.trim()));
}
/**
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistryTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistryTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistryTest.java 2008-05-23 20:44:56 UTC (rev 190)
@@ -0,0 +1,135 @@
+/*
+ * 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.hamcrest.core.IsNull.nullValue;
+import static org.junit.Assert.assertThat;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class BasicNamespaceRegistryTest {
+
+ private String validNamespaceUri1;
+ private String validNamespaceUri2;
+ private String validNamespaceUri3;
+ private String validPrefix1;
+ private String validPrefix2;
+ private BasicNamespaceRegistry namespaceRegistry;
+
+ @Before
+ public void setUp() throws Exception {
+ namespaceRegistry = new BasicNamespaceRegistry();
+ validNamespaceUri1 = "http://www.jboss.org/dna";
+ validNamespaceUri2 = "http://acme.com/something";
+ validNamespaceUri3 = "http://www.redhat.com";
+ validPrefix1 = "dna";
+ validPrefix2 = "acme";
+ }
+
+ @Test
+ public void shouldReturnNullForNamespaceUriIfPrefixIsNotRegistered() {
+ assertThat(namespaceRegistry.getNamespaceForPrefix("notfound"), is(nullValue()));
+ // now register some namespaces ...
+ namespaceRegistry.register(validPrefix1, validNamespaceUri1);
+ namespaceRegistry.register(validPrefix2, validNamespaceUri2);
+ assertThat(namespaceRegistry.getNamespaceForPrefix("notfound"), is(nullValue()));
+ }
+
+ @Test
+ public void shouldReturnNamespaceUriForPrefixThatIsRegistered() {
+ namespaceRegistry.register(validPrefix1, validNamespaceUri1);
+ namespaceRegistry.register(validPrefix2, validNamespaceUri2);
+ assertThat(namespaceRegistry.getNamespaceForPrefix(validPrefix1), is(validNamespaceUri1));
+ assertThat(namespaceRegistry.getNamespaceForPrefix(validPrefix2), is(validNamespaceUri2));
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowNullPrefixParameterWhenGettingNamespaceUri() {
+ namespaceRegistry.getNamespaceForPrefix(null);
+ }
+
+ @Test
+ public void shouldReturnNullForPrefixIfNamespaceUriIsNotRegistered() {
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri3), is(nullValue()));
+ // now register some namespaces ...
+ namespaceRegistry.register(validPrefix1, validNamespaceUri1);
+ namespaceRegistry.register(validPrefix2, validNamespaceUri2);
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri3), is(nullValue()));
+ }
+
+ @Test
+ public void shouldReturnPrefixForNamespaceUriThatIsRegistered() {
+ namespaceRegistry.register(validPrefix1, validNamespaceUri1);
+ namespaceRegistry.register(validPrefix2, validNamespaceUri2);
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri1), is(validPrefix1));
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri2), is(validPrefix2));
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowNullNamespaceUriParameterWhenGettingPrefix() {
+ namespaceRegistry.getPrefixForNamespaceUri(null);
+ }
+
+ @Test
+ public void shouldReturnNullDefaultNamespaceUriWhenNoNamespacesAreRegistered() {
+ assertThat(namespaceRegistry.getDefaultNamespaceUri(), is(nullValue()));
+ }
+
+ @Test
+ public void shouldReturnNullDefaultNamespaceUriWhenThereAreNamespacesRegisteredButNoneRegisteredWithZeroLengthPrefix() {
+ namespaceRegistry.register(validPrefix1, validNamespaceUri1);
+ namespaceRegistry.register(validPrefix2, validNamespaceUri2);
+ assertThat(namespaceRegistry.getDefaultNamespaceUri(), is(nullValue()));
+ }
+
+ @Test
+ public void shouldReturnNonNullDefaultNamespaceUriWhenThereAreNamespacesRegisteredIncludineOneWithZeroLengthPrefix() {
+ namespaceRegistry.register(validPrefix1, validNamespaceUri1);
+ namespaceRegistry.register("", validNamespaceUri2);
+ assertThat(namespaceRegistry.getDefaultNamespaceUri(), is(validNamespaceUri2));
+ }
+
+ @Test
+ public void shouldNotFindRegisteredNamespaceIfNamespaceNotRegistered() {
+ assertThat(namespaceRegistry.isRegisteredNamespaceUri(validNamespaceUri1), is(false));
+ assertThat(namespaceRegistry.isRegisteredNamespaceUri(validNamespaceUri2), is(false));
+ assertThat(namespaceRegistry.isRegisteredNamespaceUri(validNamespaceUri3), is(false));
+ namespaceRegistry.register(validPrefix1, validNamespaceUri1);
+ namespaceRegistry.register(validPrefix2, validNamespaceUri2);
+ assertThat(namespaceRegistry.isRegisteredNamespaceUri(validNamespaceUri1), is(true));
+ assertThat(namespaceRegistry.isRegisteredNamespaceUri(validNamespaceUri2), is(true));
+ assertThat(namespaceRegistry.isRegisteredNamespaceUri(validNamespaceUri3), is(false));
+ }
+
+ @Test
+ public void shouldFindRegisteredNamespace() {
+ namespaceRegistry.register(validPrefix1, validNamespaceUri1);
+ namespaceRegistry.register(validPrefix2, validNamespaceUri2);
+ assertThat(namespaceRegistry.isRegisteredNamespaceUri(validNamespaceUri1), is(true));
+ assertThat(namespaceRegistry.isRegisteredNamespaceUri(validNamespaceUri2), is(true));
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistryTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BooleanValueFactoryTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BooleanValueFactoryTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BooleanValueFactoryTest.java 2008-05-23 20:44:56 UTC (rev 190)
@@ -0,0 +1,171 @@
+/*
+ * 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.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import org.jboss.dna.common.text.TextEncoder;
+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 BooleanValueFactoryTest {
+
+ private BooleanValueFactory 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 BooleanValueFactory(encoder, stringFactory);
+ context = new Mockery();
+ }
+
+ @Test
+ public void shouldCreateBooleanFromBoolean() {
+ assertThat(factory.create(true), is(true));
+ assertThat(factory.create(false), is(false));
+ }
+
+ @Test
+ public void shouldCreateBooleanFromTrueAndFalseStringRegardlessOfCase() {
+ assertThat(factory.create("true"), is(true));
+ assertThat(factory.create("false"), is(false));
+ assertThat(factory.create("TRUE"), is(true));
+ assertThat(factory.create("FALSE"), is(false));
+ }
+
+ @Test
+ public void shouldCreateBooleanFromTrueAndFalseStringRegardlessOfLeadingAndTrailingWhitespace() {
+ assertThat(factory.create(" true "), is(true));
+ assertThat(factory.create(" false "), is(false));
+ assertThat(factory.create(" TRUE "), is(true));
+ assertThat(factory.create(" FALSE "), is(false));
+ }
+
+ @Test
+ public void shouldCreateFalseFromStringContainingOneOrZero() {
+ assertThat(factory.create("1"), is(false));
+ assertThat(factory.create("0"), is(false));
+ assertThat(factory.create(" 0 "), is(false));
+ assertThat(factory.create(" 1 "), is(false));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateBooleanFromIntegerValue() {
+ factory.create(1);
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateBooleanFromLongValue() {
+ factory.create(1l);
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateBooleanFromFloatValue() {
+ factory.create(1.0f);
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateBooleanFromDoubleValue() {
+ factory.create(1.0d);
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateBooleanFromBigDecimal() {
+ factory.create(1.0d);
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateBooleanFromDate() {
+ factory.create(new Date());
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateBooleanFromCalendar() {
+ factory.create(Calendar.getInstance());
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateBooleanFromName() {
+ factory.create(context.mock(Name.class));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateBooleanFromPath() {
+ factory.create(context.mock(Path.class));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateBooleanFromReference() {
+ factory.create(context.mock(Reference.class));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateBooleanFromUri() throws Exception {
+ factory.create(new URI("http://www.jboss.org"));
+ }
+
+ @Test
+ public void shouldCreateBooleanFromByteArrayContainingUtf8EncodingOfTrueOrFalseStringRegardlessOfCase() throws Exception {
+ assertThat(factory.create("true".getBytes("UTF-8")), is(true));
+ assertThat(factory.create("false".getBytes("UTF-8")), is(false));
+ assertThat(factory.create("TRUE".getBytes("UTF-8")), is(true));
+ assertThat(factory.create("FALSE".getBytes("UTF-8")), is(false));
+ assertThat(factory.create("something else".getBytes("UTF-8")), is(false));
+ }
+
+ @Test
+ public void shouldCreateBooleanFromInputStreamContainingUtf8EncodingOfTrueOrFalseStringRegardlessOfCase() throws Exception {
+ assertThat(factory.create(new ByteArrayInputStream("true".getBytes("UTF-8"))), is(true));
+ assertThat(factory.create(new ByteArrayInputStream("false".getBytes("UTF-8"))), is(false));
+ assertThat(factory.create(new ByteArrayInputStream("TRUE".getBytes("UTF-8"))), is(true));
+ assertThat(factory.create(new ByteArrayInputStream("FALSE".getBytes("UTF-8"))), is(false));
+ assertThat(factory.create(new ByteArrayInputStream("something else".getBytes("UTF-8"))), is(false));
+ }
+
+ @Test
+ public void shouldCreateBooleanFromReaderContainingTrueOrFalseStringRegardlessOfCase() throws Exception {
+ assertThat(factory.create(new StringReader("true")), is(true));
+ assertThat(factory.create(new StringReader("false")), is(false));
+ assertThat(factory.create(new StringReader("TRUE")), is(true));
+ assertThat(factory.create(new StringReader("FALSE")), is(false));
+ assertThat(factory.create(new StringReader("something else")), is(false));
+ }
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BooleanValueFactoryTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DecimalValueFactoryTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DecimalValueFactoryTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DecimalValueFactoryTest.java 2008-05-23 20:44:56 UTC (rev 190)
@@ -0,0 +1,173 @@
+/*
+ * 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 java.util.Date;
+import org.jboss.dna.common.text.TextEncoder;
+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 DecimalValueFactoryTest {
+
+ private DecimalValueFactory 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 DecimalValueFactory(encoder, stringFactory);
+ context = new Mockery();
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateDecimalFromBooleanValue() {
+ factory.create(true);
+ }
+
+ @Test
+ public void shouldCreateDecimalFromString() {
+ assertThat(factory.create("1"), is(BigDecimal.valueOf(1)));
+ assertThat(factory.create("-1.0"), is(BigDecimal.valueOf(-1.0d)));
+ assertThat(factory.create("100.000101"), is(BigDecimal.valueOf(100.000101d)));
+ }
+
+ @Test
+ public void shouldCreateDecimalFromStringRegardlessOfLeadingAndTrailingWhitespace() {
+ assertThat(factory.create(" 1 "), is(BigDecimal.valueOf(1)));
+ assertThat(factory.create(" -1.0 "), is(BigDecimal.valueOf(-1.0d)));
+ assertThat(factory.create(" 100.000101 "), is(BigDecimal.valueOf(100.000101d)));
+ }
+
+ @Test
+ public void shouldCreateDecimalFromIntegerValue() {
+ assertThat(factory.create(1), is(BigDecimal.valueOf(1)));
+ }
+
+ @Test
+ public void shouldCreateDecimalFromLongValue() {
+ assertThat(factory.create(1l), is(BigDecimal.valueOf(1l)));
+ }
+
+ @Test
+ public void shouldCreateDecimalFromFloatValue() {
+ assertThat(factory.create(1.0f), is(BigDecimal.valueOf(1.0f)));
+ }
+
+ @Test
+ public void shouldCreateDecimalFromDoubleValue() {
+ assertThat(factory.create(1.0d), is(BigDecimal.valueOf(1.0d)));
+ }
+
+ @Test
+ public void shouldCreateDecimalFromBigDecimal() {
+ BigDecimal value = new BigDecimal(100);
+ assertThat(factory.create(value), is(value));
+ }
+
+ @Test
+ public void shouldCreateDecimalFromDate() {
+ Date value = new Date();
+ assertThat(factory.create(value), is(BigDecimal.valueOf(value.getTime())));
+ }
+
+ @Test
+ public void shouldCreateDecimalFromCalendar() {
+ Calendar value = Calendar.getInstance();
+ assertThat(factory.create(value), is(BigDecimal.valueOf(value.getTimeInMillis())));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateDecimalFromName() {
+ factory.create(context.mock(Name.class));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateDecimalFromPath() {
+ factory.create(context.mock(Path.class));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateDecimalFromReference() {
+ factory.create(context.mock(Reference.class));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateDecimalFromUri() throws Exception {
+ factory.create(new URI("http://www.jboss.org"));
+ }
+
+ @Test
+ public void shouldCreateDecimalFromByteArrayContainingUtf8EncodingOfStringWithDecimal() throws Exception {
+ assertThat(factory.create("1".getBytes("UTF-8")), is(BigDecimal.valueOf(1l)));
+ assertThat(factory.create("-1.0".getBytes("UTF-8")), is(BigDecimal.valueOf(-1.d)));
+ assertThat(factory.create("100.000101".getBytes("UTF-8")), is(BigDecimal.valueOf(100.000101d)));
+ }
+
+ @Test
+ public void shouldCreateDecimalFromInputStreamContainingUtf8EncodingOfStringWithDecimal() throws Exception {
+ assertThat(factory.create(new ByteArrayInputStream("1".getBytes("UTF-8"))), is(BigDecimal.valueOf(1l)));
+ assertThat(factory.create(new ByteArrayInputStream("-1.0".getBytes("UTF-8"))), is(BigDecimal.valueOf(-1.d)));
+ assertThat(factory.create(new ByteArrayInputStream("100.000101".getBytes("UTF-8"))), is(BigDecimal.valueOf(100.000101d)));
+ }
+
+ @Test
+ public void shouldCreateDecimalFromReaderContainingStringWithDecimal() throws Exception {
+ assertThat(factory.create(new StringReader("1")), is(BigDecimal.valueOf(1l)));
+ assertThat(factory.create(new StringReader("-1.0")), is(BigDecimal.valueOf(-1.d)));
+ assertThat(factory.create(new StringReader("100.000101")), is(BigDecimal.valueOf(100.000101d)));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateDecimalFromByteArrayContainingUtf8EncodingOfStringWithContentsOtherThanDecimal() throws Exception {
+ factory.create("something".getBytes("UTF-8"));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateDecimalFromInputStreamContainingUtf8EncodingOfStringWithContentsOtherThanDecimal() throws Exception {
+ factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateDecimalFromReaderContainingStringWithContentsOtherThanDecimal() throws Exception {
+ factory.create(new StringReader("something"));
+ }
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DecimalValueFactoryTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java 2008-05-23 20:44:56 UTC (rev 190)
@@ -0,0 +1,175 @@
+/*
+ * 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.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import org.jboss.dna.common.text.TextEncoder;
+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 DoubleValueFactoryTest {
+
+ private DoubleValueFactory 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 DoubleValueFactory(encoder, stringFactory);
+ context = new Mockery();
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateDoubleFromBooleanValue() {
+ factory.create(true);
+ }
+
+ @Test
+ public void shouldCreateDoubleFromString() {
+ assertThat(factory.create("1"), is(Double.valueOf(1)));
+ assertThat(factory.create("-1.0"), is(Double.valueOf(-1.0d)));
+ assertThat(factory.create("100.000101"), is(Double.valueOf(100.000101d)));
+ }
+
+ @Test
+ public void shouldCreateDoubleFromStringRegardlessOfLeadingAndTrailingWhitespace() {
+ assertThat(factory.create(" 1 "), is(Double.valueOf(1)));
+ assertThat(factory.create(" -1.0 "), is(Double.valueOf(-1.0d)));
+ assertThat(factory.create(" 100.000101 "), is(Double.valueOf(100.000101d)));
+ }
+
+ @Test
+ public void shouldNotCreateDoubleFromIntegerValue() {
+ assertThat(factory.create(1), is(1.0d));
+ }
+
+ @Test
+ public void shouldNotCreateDoubleFromLongValue() {
+ assertThat(factory.create(1l), is(1.0d));
+ }
+
+ @Test
+ public void shouldNotCreateDoubleFromFloatValue() {
+ assertThat(factory.create(1.0f), is(1.0d));
+ }
+
+ @Test
+ public void shouldNotCreateDoubleFromDoubleValue() {
+ assertThat(factory.create(1.0d), is(1.0d));
+ }
+
+ @Test
+ public void shouldCreateDoubleFromBigDecimal() {
+ BigDecimal value = new BigDecimal(100);
+ assertThat(factory.create(value), is(value.doubleValue()));
+ }
+
+ @Test
+ public void shouldCreateDoubleFromDate() {
+ Date value = new Date();
+ assertThat(factory.create(value), is(Double.valueOf(value.getTime())));
+ }
+
+ @Test
+ public void shouldCreateDoubleFromCalendar() {
+ Calendar value = Calendar.getInstance();
+ assertThat(factory.create(value), is(Double.valueOf(value.getTimeInMillis())));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateDoubleFromName() {
+ factory.create(context.mock(Name.class));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateDoubleFromPath() {
+ factory.create(context.mock(Path.class));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateDoubleFromReference() {
+ factory.create(context.mock(Reference.class));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateDoubleFromUri() throws Exception {
+ factory.create(new URI("http://www.jboss.org"));
+ }
+
+ @Test
+ public void shouldCreateDoubleFromByteArrayContainingUtf8EncodingOfStringWithDouble() throws Exception {
+ assertThat(factory.create("0.1".getBytes("UTF-8")), is(0.1d));
+ assertThat(factory.create("1".getBytes("UTF-8")), is(1.0d));
+ assertThat(factory.create("-1.03".getBytes("UTF-8")), is(-1.03));
+ assertThat(factory.create("1003044".getBytes("UTF-8")), is(1003044.d));
+ }
+
+ @Test
+ public void shouldCreateDoubleFromInputStreamContainingUtf8EncodingOfStringWithDouble() throws Exception {
+ assertThat(factory.create(new ByteArrayInputStream("0.1".getBytes("UTF-8"))), is(0.1d));
+ assertThat(factory.create(new ByteArrayInputStream("1".getBytes("UTF-8"))), is(1.0d));
+ assertThat(factory.create(new ByteArrayInputStream("-1.03".getBytes("UTF-8"))), is(-1.03));
+ assertThat(factory.create(new ByteArrayInputStream("1003044".getBytes("UTF-8"))), is(1003044.d));
+ }
+
+ @Test
+ public void shouldCreateDoubleFromReaderContainingStringWithDouble() throws Exception {
+ assertThat(factory.create(new ByteArrayInputStream("0.1".getBytes("UTF-8"))), is(0.1d));
+ assertThat(factory.create(new ByteArrayInputStream("1".getBytes("UTF-8"))), is(1.0d));
+ assertThat(factory.create(new ByteArrayInputStream("-1.03".getBytes("UTF-8"))), is(-1.03));
+ assertThat(factory.create(new ByteArrayInputStream("1003044".getBytes("UTF-8"))), is(1003044.d));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateDoubleFromByteArrayContainingUtf8EncodingOfStringWithContentsOtherThanDouble() throws Exception {
+ factory.create("something".getBytes("UTF-8"));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateDoubleFromInputStreamContainingUtf8EncodingOfStringWithContentsOtherThanDouble() throws Exception {
+ factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotCreateDoubleFromReaderContainingStringWithContentsOtherThanDouble() throws Exception {
+ factory.create(new ByteArrayInputStream("something".getBytes("UTF-8")));
+ }
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 11 months
DNA SVN: r189 - branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-23 15:01:39 -0400 (Fri, 23 May 2008)
New Revision: 189
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java
Log:
Corrected import.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java 2008-05-23 18:26:11 UTC (rev 188)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java 2008-05-23 19:01:39 UTC (rev 189)
@@ -27,7 +27,6 @@
import java.util.Comparator;
import net.jcip.annotations.Immutable;
import org.jboss.dna.spi.SpiI18n;
-import com.sun.tools.javac.tree.Tree.Binary;
/**
* @author Randall Hauch
15 years, 11 months
DNA SVN: r188 - in branches/federation: sequencers/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3 and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-23 14:26:11 -0400 (Fri, 23 May 2008)
New Revision: 188
Modified:
branches/federation/pom.xml
branches/federation/sequencers/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java
Log:
Merged changes from trunk to federation branch: svn merge -r 173:187 https://svn.jboss.org/repos/dna/trunk .
Modified: branches/federation/pom.xml
===================================================================
--- branches/federation/pom.xml 2008-05-23 16:53:59 UTC (rev 187)
+++ branches/federation/pom.xml 2008-05-23 18:26:11 UTC (rev 188)
@@ -12,6 +12,48 @@
<scm>
<connection>scm:svn:https://svn.jboss.org/repos/dna/trunk</connection>
</scm>
+ <developers>
+ <developer>
+ <name>Randall Hauch</name>
+ <id>randall</id>
+ <email>rhauch(a)redhat.com</email>
+ <organization>Red Hat</organization>
+ <roles>
+ <role>Project Lead</role>
+ <role>Developer</role>
+ </roles>
+ <timezone>-6</timezone>
+ </developer>
+ <developer>
+ <name>John Verhaeg</name>
+ <id>johnny</id>
+ <email>jverhaeg(a)redhat.com</email>
+ <organization>Red Hat</organization>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ <timezone>-6</timezone>
+ </developer>
+ <developer>
+ <name>Dan Florian</name>
+ <id>dan</id>
+ <email>dflorian(a)redhat.com</email>
+ <organization>Red Hat</organization>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ <timezone>-6</timezone>
+ </developer>
+ <developer>
+ <name>Stefano Maestri</name>
+ <id>stefano</id>
+ <email>stefano.maestri(a)javalinux.it</email>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ <timezone>+1</timezone>
+ </developer>
+ </developers>
<modules>
<module>dna-common</module>
<module>dna-spi</module>
@@ -25,6 +67,7 @@
<properties>
<dna-version>0.2-SNAPSHOT</dna-version>
</properties>
+
<profiles>
<profile>
<id>release</id>
@@ -81,23 +124,23 @@
</execution>
</executions>
<configuration>
- <finalName>
- jboss-dna-${project.version}
- </finalName>
- <descriptors>
- <descriptor>
- build/assembly/examples.xml
- </descriptor>
- <descriptor>
- build/assembly/javadoc.xml
- </descriptor>
- <descriptor>
- build/assembly/dist.xml
- </descriptor>
- <descriptor>
- build/assembly/src.xml
- </descriptor>
- </descriptors>
+ <finalName>
+ jboss-dna-${project.version}
+ </finalName>
+ <descriptors>
+ <descriptor>
+ build/assembly/examples.xml
+ </descriptor>
+ <descriptor>
+ build/assembly/javadoc.xml
+ </descriptor>
+ <descriptor>
+ build/assembly/dist.xml
+ </descriptor>
+ <descriptor>
+ build/assembly/src.xml
+ </descriptor>
+ </descriptors>
</configuration>
</plugin>
</plugins>
@@ -366,12 +409,24 @@
</plugin>
</plugins>
</reporting>
- <distributionManagement>
- <repository>
- <!-- Copy the distribution jar file to a local checkout of the maven repository
- - This variable can be set in $MAVEN_HOME/conf/settings.xml -->
- <id>repository.jboss.org</id>
- <url>file://${jboss.repository.root}</url>
- </repository>
- </distributionManagement>
-</project>
\ No newline at end of file
+
+ <repositories>
+ <repository>
+ <id>jboss</id>
+ <url>http://repository.jboss.com/maven2/</url>
+ </repository>
+
+ <repository>
+ <id>jboss-snapshot</id>
+ <url>http://snapshots.jboss.org/maven2</url>
+ </repository>
+ </repositories>
+ <distributionManagement>
+ <repository>
+ <!-- Copy the distribution jar file to a local checkout of the maven repository
+ - This variable can be set in $MAVEN_HOME/conf/settings.xml -->
+ <id>repository.jboss.org</id>
+ <url>file://${jboss.repository.root}</url>
+ </repository>
+ </distributionManagement>
+</project>
Modified: branches/federation/sequencers/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java
===================================================================
--- branches/federation/sequencers/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java 2008-05-23 16:53:59 UTC (rev 187)
+++ branches/federation/sequencers/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java 2008-05-23 18:26:11 UTC (rev 188)
@@ -34,8 +34,6 @@
* <ul>
* <li><strong>mp3:metadata</strong> node of type <code>mp3:metadata</code>
* <ul>
- * <li><strong>jcr:mimeType</strong> - optional string property for the mime type of the image</li>
- * <li><strong>jcr:encoding</strong> - optional string property for the encoding of the image</li>
* <li><strong>mp3:title</strong> - optional string property for the name of the audio file or recording</li>
* <li><strong>mp3:author</strong> - optional string property for the author of the recording</li>
* <li><strong>mp3:album</strong> - optional string property for the name of the album</li>
@@ -67,9 +65,7 @@
if (metadata != null) {
// Place the image metadata into the output map ...
output.setProperty(METADATA_NODE, MP3_PRIMARY_TYPE, "mp3:metadata");
- // output.psetProperty(METADATA_NODE, IMAGE_MIXINS, "");
output.setProperty(METADATA_NODE, MP3_TITLE, metadata.getTitle());
- // output.setProperty(METADATA_NODE, IMAGE_ENCODING, "");
output.setProperty(METADATA_NODE, MP3_AUTHOR, metadata.getAuthor());
output.setProperty(METADATA_NODE, MP3_ALBUM, metadata.getAlbum());
output.setProperty(METADATA_NODE, MP3_YEAR, metadata.getYear());
15 years, 11 months
DNA SVN: r187 - trunk.
by dna-commits@lists.jboss.org
Author: maeste
Date: 2008-05-23 12:53:59 -0400 (Fri, 23 May 2008)
New Revision: 187
Modified:
trunk/pom.xml
Log:
fixed my timezone
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2008-05-23 16:13:59 UTC (rev 186)
+++ trunk/pom.xml 2008-05-23 16:53:59 UTC (rev 187)
@@ -51,7 +51,7 @@
<roles>
<role>Developer</role>
</roles>
- <timezone>-6</timezone>
+ <timezone>+1</timezone>
</developer>
</developers>
<modules>
@@ -429,4 +429,4 @@
<url>file://${jboss.repository.root}</url>
</repository>
</distributionManagement>
-</project>
\ No newline at end of file
+</project>
15 years, 11 months
DNA SVN: r186 - branches/federation.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-23 12:13:59 -0400 (Fri, 23 May 2008)
New Revision: 186
Modified:
branches/federation/pom.xml
Log:
No longer excluding the test classes that begin with 'Abstract...Test', since there are some test cases for abstract classes that are not abstract test cases.
Modified: branches/federation/pom.xml
===================================================================
--- branches/federation/pom.xml 2008-05-23 16:12:06 UTC (rev 185)
+++ branches/federation/pom.xml 2008-05-23 16:13:59 UTC (rev 186)
@@ -163,10 +163,10 @@
<include>**/*TestCase.java</include>
<include>**/*Test.java</include>
</includes>
- <excludes>
+ <!--excludes>
<exclude>**/Abstract*TestCase.java</exclude>
<exclude>**/Abstract*Test.java</exclude>
- </excludes>
+ </excludes-->
</configuration>
</plugin>
<!--
15 years, 11 months