Author: rhauch
Date: 2009-03-04 14:11:34 -0500 (Wed, 04 Mar 2009)
New Revision: 753
Added:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSingleValueProperty.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSingleValuePropertyTest.java
Removed:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
Log:
DNA-291 JCR property objects do not have PropertyDefinition
Renamed JcrProperty to JcrSingleValueProperty to more closely match the existing
JcrMultiValueProperty and reduce confusion.
Deleted: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java 2009-03-04 19:08:45 UTC
(rev 752)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java 2009-03-04 19:11:34 UTC
(rev 753)
@@ -1,244 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you 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.
- *
- * JBoss DNA 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.jcr;
-
-import java.io.InputStream;
-import java.util.Calendar;
-import java.util.UUID;
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.ValueFormatException;
-import javax.jcr.nodetype.PropertyDefinition;
-import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.property.Binary;
-import org.jboss.dna.graph.property.Property;
-import org.jboss.dna.graph.property.Reference;
-import org.jboss.dna.graph.property.ValueFactories;
-
-/**
- * @author jverhaeg
- */
-final class JcrProperty extends AbstractJcrProperty {
-
- JcrProperty( Node node,
- ExecutionContext executionContext,
- PropertyDefinition definition,
- Property dnaProperty ) {
- super(node, executionContext, definition, dnaProperty);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getBoolean()
- */
- public boolean getBoolean() throws RepositoryException {
- try {
- return
getExecutionContext().getValueFactories().getBooleanFactory().create(getDnaProperty().getFirstValue());
- } catch (org.jboss.dna.graph.property.ValueFormatException e) {
- throw new ValueFormatException(e.getMessage(), e);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getDate()
- */
- public Calendar getDate() throws RepositoryException {
- try {
- return getExecutionContext().getValueFactories()
- .getDateFactory()
- .create(getDnaProperty().getFirstValue())
- .toCalendar();
- } catch (org.jboss.dna.graph.property.ValueFormatException e) {
- throw new ValueFormatException(e.getMessage(), e);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getDouble()
- */
- public double getDouble() throws RepositoryException {
- try {
- return
getExecutionContext().getValueFactories().getDoubleFactory().create(getDnaProperty().getFirstValue());
- } catch (org.jboss.dna.graph.property.ValueFormatException e) {
- throw new ValueFormatException(e.getMessage(), e);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getLength()
- */
- public long getLength() throws RepositoryException {
- return createValue(getDnaProperty().getFirstValue()).getLength();
- }
-
- /**
- * {@inheritDoc}
- *
- * @throws ValueFormatException always
- * @see javax.jcr.Property#getLengths()
- */
- public long[] getLengths() throws ValueFormatException {
- throw new ValueFormatException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getLong()
- */
- public long getLong() throws RepositoryException {
- try {
- return
getExecutionContext().getValueFactories().getLongFactory().create(getDnaProperty().getFirstValue());
- } catch (org.jboss.dna.graph.property.ValueFormatException e) {
- throw new ValueFormatException(e.getMessage(), e);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getNode()
- */
- public final Node getNode() throws RepositoryException {
- try {
- ValueFactories factories = getExecutionContext().getValueFactories();
- Reference dnaReference =
factories.getReferenceFactory().create(getDnaProperty().getFirstValue());
- UUID uuid = factories.getUuidFactory().create(dnaReference);
- return ((JcrSession)getSession()).getNode(uuid);
- } catch (org.jboss.dna.graph.property.ValueFormatException e) {
- throw new ValueFormatException(e.getMessage(), e);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getStream()
- */
- public InputStream getStream() throws RepositoryException {
- try {
- Binary binary =
getExecutionContext().getValueFactories().getBinaryFactory().create(getDnaProperty().getFirstValue());
- return new SelfClosingInputStream(binary);
- } catch (org.jboss.dna.graph.property.ValueFormatException e) {
- throw new ValueFormatException(e.getMessage(), e);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getString()
- */
- public String getString() throws RepositoryException {
- try {
- return
getExecutionContext().getValueFactories().getStringFactory().create(getDnaProperty().getFirstValue());
- } catch (org.jboss.dna.graph.property.ValueFormatException e) {
- throw new ValueFormatException(e.getMessage(), e);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#getValue()
- */
- public Value getValue() {
- return createValue(getDnaProperty().getFirstValue());
- }
-
- /**
- * {@inheritDoc}
- *
- * @throws ValueFormatException always
- * @see javax.jcr.Property#getValues()
- */
- public Value[] getValues() throws ValueFormatException {
- throw new ValueFormatException();
- }
-
- /*
- * {@inheritDoc}
- *
- * @throws IllegalArgumentException if <code>value</code> is
<code>null</code>.
- * @see javax.jcr.Property#setValue(javax.jcr.Value)
- *
- @SuppressWarnings( "fallthrough" )
- public void setValue( Value value ) throws RepositoryException {
- CheckArg.isNotNull(value, "value");
- // TODOx: Check node type constraint
- try {
- jcrValue = JcrValue.class.cast(value);
- } catch (ClassCastException error) {
- // TODOx: not sure if this is even possible
- ValueFactories valueFactories = getExecutionContext().getValueFactories();
- int type = value.getType();
- switch (type) {
- case PropertyType.BINARY: {
- jcrValue = new JcrValue<InputStream>(valueFactories, type,
value.getStream());
- break;
- }
- case PropertyType.BOOLEAN: {
- jcrValue = new JcrValue<Boolean>(valueFactories, type,
value.getBoolean());
- break;
- }
- case PropertyType.DATE: {
- jcrValue = new JcrValue<Calendar>(valueFactories, type,
value.getDate());
- break;
- }
- case PropertyType.DOUBLE: {
- jcrValue = new JcrValue<Double>(valueFactories, type,
value.getDouble());
- break;
- }
- case PropertyType.LONG: {
- jcrValue = new JcrValue<Long>(valueFactories, type,
value.getLong());
- break;
- }
- case PropertyType.REFERENCE: {
- try {
- jcrValue = new JcrValue<UUID>(valueFactories, type,
UUID.fromString(value.getString()));
- } catch (IllegalArgumentException fallsThroughToString) {
- }
- }
- case PropertyType.NAME:
- case PropertyType.PATH:
- case PropertyType.STRING: {
- jcrValue = new JcrValue<String>(valueFactories, type,
value.getString());
- break;
- }
- default: {
- throw new AssertionError("Unsupported PropertyType: " +
value.getType());
- }
- }
- }
- }
- */
-}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-03-04 19:08:45 UTC
(rev 752)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-03-04 19:11:34 UTC
(rev 753)
@@ -723,7 +723,7 @@
if (referenceable) {
if (uuidProperty == null) uuidProperty =
executionContext.getPropertyFactory().create(JcrLexicon.UUID, uuid);
PropertyDefinition propertyDefinition =
propertyDefinitionsByPropertyName.get(JcrLexicon.UUID);
- properties.add(new JcrProperty(node, executionContext, propertyDefinition,
uuidProperty));
+ properties.add(new JcrSingleValueProperty(node, executionContext,
propertyDefinition, uuidProperty));
}
// Now create the JCR property object wrappers around the other properties ...
@@ -763,7 +763,7 @@
if (isMultiple) {
properties.add(new JcrMultiValueProperty(node, executionContext,
propertyDefinition, dnaProp));
} else {
- properties.add(new JcrProperty(node, executionContext,
propertyDefinition, dnaProp));
+ properties.add(new JcrSingleValueProperty(node, executionContext,
propertyDefinition, dnaProp));
}
}
Copied: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSingleValueProperty.java (from
rev 752, trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java)
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSingleValueProperty.java
(rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSingleValueProperty.java 2009-03-04
19:11:34 UTC (rev 753)
@@ -0,0 +1,244 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ *
+ * JBoss DNA 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.jcr;
+
+import java.io.InputStream;
+import java.util.Calendar;
+import java.util.UUID;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.PropertyDefinition;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.property.Binary;
+import org.jboss.dna.graph.property.Property;
+import org.jboss.dna.graph.property.Reference;
+import org.jboss.dna.graph.property.ValueFactories;
+
+/**
+ * @author jverhaeg
+ */
+final class JcrSingleValueProperty extends AbstractJcrProperty {
+
+ JcrSingleValueProperty( Node node,
+ ExecutionContext executionContext,
+ PropertyDefinition definition,
+ Property dnaProperty ) {
+ super(node, executionContext, definition, dnaProperty);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getBoolean()
+ */
+ public boolean getBoolean() throws RepositoryException {
+ try {
+ return
getExecutionContext().getValueFactories().getBooleanFactory().create(getDnaProperty().getFirstValue());
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getDate()
+ */
+ public Calendar getDate() throws RepositoryException {
+ try {
+ return getExecutionContext().getValueFactories()
+ .getDateFactory()
+ .create(getDnaProperty().getFirstValue())
+ .toCalendar();
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getDouble()
+ */
+ public double getDouble() throws RepositoryException {
+ try {
+ return
getExecutionContext().getValueFactories().getDoubleFactory().create(getDnaProperty().getFirstValue());
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getLength()
+ */
+ public long getLength() throws RepositoryException {
+ return createValue(getDnaProperty().getFirstValue()).getLength();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws ValueFormatException always
+ * @see javax.jcr.Property#getLengths()
+ */
+ public long[] getLengths() throws ValueFormatException {
+ throw new ValueFormatException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getLong()
+ */
+ public long getLong() throws RepositoryException {
+ try {
+ return
getExecutionContext().getValueFactories().getLongFactory().create(getDnaProperty().getFirstValue());
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getNode()
+ */
+ public final Node getNode() throws RepositoryException {
+ try {
+ ValueFactories factories = getExecutionContext().getValueFactories();
+ Reference dnaReference =
factories.getReferenceFactory().create(getDnaProperty().getFirstValue());
+ UUID uuid = factories.getUuidFactory().create(dnaReference);
+ return ((JcrSession)getSession()).getNode(uuid);
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getStream()
+ */
+ public InputStream getStream() throws RepositoryException {
+ try {
+ Binary binary =
getExecutionContext().getValueFactories().getBinaryFactory().create(getDnaProperty().getFirstValue());
+ return new SelfClosingInputStream(binary);
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getString()
+ */
+ public String getString() throws RepositoryException {
+ try {
+ return
getExecutionContext().getValueFactories().getStringFactory().create(getDnaProperty().getFirstValue());
+ } catch (org.jboss.dna.graph.property.ValueFormatException e) {
+ throw new ValueFormatException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getValue()
+ */
+ public Value getValue() {
+ return createValue(getDnaProperty().getFirstValue());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws ValueFormatException always
+ * @see javax.jcr.Property#getValues()
+ */
+ public Value[] getValues() throws ValueFormatException {
+ throw new ValueFormatException();
+ }
+
+ /*
+ * {@inheritDoc}
+ *
+ * @throws IllegalArgumentException if <code>value</code> is
<code>null</code>.
+ * @see javax.jcr.Property#setValue(javax.jcr.Value)
+ *
+ @SuppressWarnings( "fallthrough" )
+ public void setValue( Value value ) throws RepositoryException {
+ CheckArg.isNotNull(value, "value");
+ // TODOx: Check node type constraint
+ try {
+ jcrValue = JcrValue.class.cast(value);
+ } catch (ClassCastException error) {
+ // TODOx: not sure if this is even possible
+ ValueFactories valueFactories = getExecutionContext().getValueFactories();
+ int type = value.getType();
+ switch (type) {
+ case PropertyType.BINARY: {
+ jcrValue = new JcrValue<InputStream>(valueFactories, type,
value.getStream());
+ break;
+ }
+ case PropertyType.BOOLEAN: {
+ jcrValue = new JcrValue<Boolean>(valueFactories, type,
value.getBoolean());
+ break;
+ }
+ case PropertyType.DATE: {
+ jcrValue = new JcrValue<Calendar>(valueFactories, type,
value.getDate());
+ break;
+ }
+ case PropertyType.DOUBLE: {
+ jcrValue = new JcrValue<Double>(valueFactories, type,
value.getDouble());
+ break;
+ }
+ case PropertyType.LONG: {
+ jcrValue = new JcrValue<Long>(valueFactories, type,
value.getLong());
+ break;
+ }
+ case PropertyType.REFERENCE: {
+ try {
+ jcrValue = new JcrValue<UUID>(valueFactories, type,
UUID.fromString(value.getString()));
+ } catch (IllegalArgumentException fallsThroughToString) {
+ }
+ }
+ case PropertyType.NAME:
+ case PropertyType.PATH:
+ case PropertyType.STRING: {
+ jcrValue = new JcrValue<String>(valueFactories, type,
value.getString());
+ break;
+ }
+ default: {
+ throw new AssertionError("Unsupported PropertyType: " +
value.getType());
+ }
+ }
+ }
+ }
+ */
+}
Property changes on:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSingleValueProperty.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java 2009-03-04 19:08:45
UTC (rev 752)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java 2009-03-04 19:11:34
UTC (rev 753)
@@ -1,257 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you 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.
- *
- * JBoss DNA 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.jcr;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsNull.notNullValue;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.stub;
-import java.io.InputStream;
-import java.util.UUID;
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.PropertyType;
-import javax.jcr.Value;
-import javax.jcr.ValueFormatException;
-import javax.jcr.nodetype.PropertyDefinition;
-import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.property.DateTime;
-import org.jboss.dna.graph.property.Name;
-import org.jboss.dna.graph.property.Path;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.MockitoAnnotations;
-import org.mockito.MockitoAnnotations.Mock;
-
-/**
- * @author jverhaeg
- */
-public class JcrPropertyTest {
-
- private Property prop;
- @Mock
- private Node node;
- private ExecutionContext executionContext;
- @Mock
- Name name;
- @Mock
- private PropertyDefinition definition;
- private org.jboss.dna.graph.property.Property dnaProperty;
-
- @Before
- public void before() {
- MockitoAnnotations.initMocks(this);
- executionContext = new ExecutionContext();
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
"text/plain");
- stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
- stub(definition.isMultiple()).toReturn(false);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- }
-
- @Test
- public void shouldProvideBoolean() throws Exception {
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
"true");
- stub(definition.getRequiredType()).toReturn(PropertyType.BOOLEAN);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getBoolean(), is(true));
- assertThat(prop.getType(), is(PropertyType.BOOLEAN));
- }
-
- @Test
- public void shouldIndicateHasSingleValue() throws Exception {
- PropertyDefinition def = prop.getDefinition();
- assertThat(def, notNullValue());
- assertThat(def.isMultiple(), is(false));
- }
-
- @Test
- public void shouldProvideDate() throws Exception {
- DateTime dnaDate =
executionContext.getValueFactories().getDateFactory().create();
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
dnaDate);
- stub(definition.getRequiredType()).toReturn(PropertyType.DATE);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getDate(), is(dnaDate.toCalendar()));
- assertThat(prop.getLong(), is(dnaDate.getMilliseconds()));
- assertThat(prop.getType(), is(PropertyType.DATE));
- assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- }
-
- @Test
- public void shouldProvideNode() throws Exception {
- UUID referencedUuid = UUID.randomUUID();
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
referencedUuid);
- stub(definition.getRequiredType()).toReturn(PropertyType.REFERENCE);
- Node referencedNode = mock(Node.class);
- JcrSession session = mock(JcrSession.class);
- stub(node.getSession()).toReturn(session);
- stub(session.getNode(referencedUuid)).toReturn(referencedNode);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getNode(), is(referencedNode));
- assertThat(prop.getType(), is(PropertyType.REFERENCE));
- assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- }
-
- @Test
- public void shouldProvideDouble() throws Exception {
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
1.0);
- stub(definition.getRequiredType()).toReturn(PropertyType.DOUBLE);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getDouble(), is(1.0));
- assertThat(prop.getType(), is(PropertyType.DOUBLE));
- assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
1.0F);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getDouble(), is(1.0));
- assertThat(prop.getType(), is(PropertyType.DOUBLE));
- assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- }
-
- @Test
- public void shouldProvideLong() throws Exception {
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
1);
- stub(definition.getRequiredType()).toReturn(PropertyType.DOUBLE);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getLong(), is(1L));
- assertThat(prop.getType(), is(PropertyType.DOUBLE));
- assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
-
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
1L);
- stub(definition.getRequiredType()).toReturn(PropertyType.DOUBLE);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getLong(), is(1L));
- assertThat(prop.getString(), is("1"));
- assertThat(prop.getType(), is(PropertyType.DOUBLE));
- assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- }
-
- @Test
- public void shouldProvideStream() throws Exception {
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
new Object());
- stub(definition.getRequiredType()).toReturn(PropertyType.BINARY);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getType(), is(PropertyType.BINARY));
- assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- InputStream stream = prop.getStream();
- try {
- assertThat(stream, notNullValue());
- } finally {
- if (stream != null) {
- stream.close();
- }
- }
- }
-
- @Test
- public void shouldProvideString() throws Exception {
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
"value");
- stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getString(), is("value"));
- assertThat(prop.getType(), is(PropertyType.STRING));
- assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- }
-
- @Test
- public void shouldAllowReferenceValue() throws Exception {
- UUID uuid = UUID.randomUUID();
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
uuid);
- stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getString(), is(uuid.toString()));
- assertThat(prop.getType(), is(PropertyType.STRING));
- assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- }
-
- @Test
- public void shouldAllowNameValue() throws Exception {
- executionContext.getNamespaceRegistry().register("acme",
"http://example.com");
- Name path =
executionContext.getValueFactories().getNameFactory().create("acme:something");
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
path);
- stub(definition.getRequiredType()).toReturn(PropertyType.NAME);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getString(), is("acme:something"));
- assertThat(prop.getType(), is(PropertyType.NAME));
- assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- // Change the namespace registry ...
- executionContext.getNamespaceRegistry().register("acme2",
"http://example.com");
- assertThat(prop.getString(), is("acme2:something"));
- }
-
- @Test
- public void shouldAllowPathValue() throws Exception {
- executionContext.getNamespaceRegistry().register("acme",
"http://example.com");
- Path path =
executionContext.getValueFactories().getPathFactory().create("/a/b/acme:c");
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
(Object)path);
- stub(definition.getRequiredType()).toReturn(PropertyType.PATH);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getString(), is("/a/b/acme:c"));
- assertThat(prop.getType(), is(PropertyType.PATH));
- assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
- // Change the namespace registry ...
- executionContext.getNamespaceRegistry().register("acme2",
"http://example.com");
- assertThat(prop.getString(), is("/a/b/acme2:c"));
- }
-
- @Test
- public void shouldProvideValue() throws Exception {
- Value val = prop.getValue();
- assertThat(val, notNullValue());
- }
-
- @Test( expected = ValueFormatException.class )
- public void shouldNotProvideValues() throws Exception {
- prop.getValues();
- }
-
- @Test
- public void shouldProvideLength() throws Exception {
- String dnaValue =
executionContext.getValueFactories().getStringFactory().create(dnaProperty.getFirstValue());
- assertThat(prop.getLength(), is((long)dnaValue.length()));
-
- dnaValue = "some other value";
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
dnaValue);
- stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getLength(), is((long)dnaValue.length()));
-
- Object obj = new Object();
- long binaryLength =
executionContext.getValueFactories().getBinaryFactory().create(obj).getSize();
- dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
obj);
- stub(definition.getRequiredType()).toReturn(PropertyType.BINARY);
- prop = new JcrProperty(node, executionContext, definition, dnaProperty);
- assertThat(prop.getLength(), is(binaryLength));
- }
-
- @Test( expected = ValueFormatException.class )
- public void shouldNotProvideLengths() throws Exception {
- prop.getLengths();
- }
-
- @Test
- public void shouldProvidePropertyDefinition() throws Exception {
- assertThat(prop.getDefinition(), notNullValue());
- }
-
-}
Copied: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSingleValuePropertyTest.java
(from rev 752, trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java)
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSingleValuePropertyTest.java
(rev 0)
+++
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSingleValuePropertyTest.java 2009-03-04
19:11:34 UTC (rev 753)
@@ -0,0 +1,257 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ *
+ * JBoss DNA 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.jcr;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.stub;
+import java.io.InputStream;
+import java.util.UUID;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.PropertyDefinition;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.property.DateTime;
+import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.Path;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+/**
+ * @author jverhaeg
+ */
+public class JcrSingleValuePropertyTest {
+
+ private Property prop;
+ @Mock
+ private Node node;
+ private ExecutionContext executionContext;
+ @Mock
+ Name name;
+ @Mock
+ private PropertyDefinition definition;
+ private org.jboss.dna.graph.property.Property dnaProperty;
+
+ @Before
+ public void before() {
+ MockitoAnnotations.initMocks(this);
+ executionContext = new ExecutionContext();
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
"text/plain");
+ stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
+ stub(definition.isMultiple()).toReturn(false);
+ prop = new JcrSingleValueProperty(node, executionContext, definition,
dnaProperty);
+ }
+
+ @Test
+ public void shouldProvideBoolean() throws Exception {
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
"true");
+ stub(definition.getRequiredType()).toReturn(PropertyType.BOOLEAN);
+ prop = new JcrSingleValueProperty(node, executionContext, definition,
dnaProperty);
+ assertThat(prop.getBoolean(), is(true));
+ assertThat(prop.getType(), is(PropertyType.BOOLEAN));
+ }
+
+ @Test
+ public void shouldIndicateHasSingleValue() throws Exception {
+ PropertyDefinition def = prop.getDefinition();
+ assertThat(def, notNullValue());
+ assertThat(def.isMultiple(), is(false));
+ }
+
+ @Test
+ public void shouldProvideDate() throws Exception {
+ DateTime dnaDate =
executionContext.getValueFactories().getDateFactory().create();
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
dnaDate);
+ stub(definition.getRequiredType()).toReturn(PropertyType.DATE);
+ prop = new JcrSingleValueProperty(node, executionContext, definition,
dnaProperty);
+ assertThat(prop.getDate(), is(dnaDate.toCalendar()));
+ assertThat(prop.getLong(), is(dnaDate.getMilliseconds()));
+ assertThat(prop.getType(), is(PropertyType.DATE));
+ assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ }
+
+ @Test
+ public void shouldProvideNode() throws Exception {
+ UUID referencedUuid = UUID.randomUUID();
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
referencedUuid);
+ stub(definition.getRequiredType()).toReturn(PropertyType.REFERENCE);
+ Node referencedNode = mock(Node.class);
+ JcrSession session = mock(JcrSession.class);
+ stub(node.getSession()).toReturn(session);
+ stub(session.getNode(referencedUuid)).toReturn(referencedNode);
+ prop = new JcrSingleValueProperty(node, executionContext, definition,
dnaProperty);
+ assertThat(prop.getNode(), is(referencedNode));
+ assertThat(prop.getType(), is(PropertyType.REFERENCE));
+ assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ }
+
+ @Test
+ public void shouldProvideDouble() throws Exception {
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
1.0);
+ stub(definition.getRequiredType()).toReturn(PropertyType.DOUBLE);
+ prop = new JcrSingleValueProperty(node, executionContext, definition,
dnaProperty);
+ assertThat(prop.getDouble(), is(1.0));
+ assertThat(prop.getType(), is(PropertyType.DOUBLE));
+ assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
1.0F);
+ prop = new JcrSingleValueProperty(node, executionContext, definition,
dnaProperty);
+ assertThat(prop.getDouble(), is(1.0));
+ assertThat(prop.getType(), is(PropertyType.DOUBLE));
+ assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ }
+
+ @Test
+ public void shouldProvideLong() throws Exception {
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
1);
+ stub(definition.getRequiredType()).toReturn(PropertyType.DOUBLE);
+ prop = new JcrSingleValueProperty(node, executionContext, definition,
dnaProperty);
+ assertThat(prop.getLong(), is(1L));
+ assertThat(prop.getType(), is(PropertyType.DOUBLE));
+ assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
1L);
+ stub(definition.getRequiredType()).toReturn(PropertyType.DOUBLE);
+ prop = new JcrSingleValueProperty(node, executionContext, definition,
dnaProperty);
+ assertThat(prop.getLong(), is(1L));
+ assertThat(prop.getString(), is("1"));
+ assertThat(prop.getType(), is(PropertyType.DOUBLE));
+ assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ }
+
+ @Test
+ public void shouldProvideStream() throws Exception {
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
new Object());
+ stub(definition.getRequiredType()).toReturn(PropertyType.BINARY);
+ prop = new JcrSingleValueProperty(node, executionContext, definition,
dnaProperty);
+ assertThat(prop.getType(), is(PropertyType.BINARY));
+ assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ InputStream stream = prop.getStream();
+ try {
+ assertThat(stream, notNullValue());
+ } finally {
+ if (stream != null) {
+ stream.close();
+ }
+ }
+ }
+
+ @Test
+ public void shouldProvideString() throws Exception {
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
"value");
+ stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
+ prop = new JcrSingleValueProperty(node, executionContext, definition,
dnaProperty);
+ assertThat(prop.getString(), is("value"));
+ assertThat(prop.getType(), is(PropertyType.STRING));
+ assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ }
+
+ @Test
+ public void shouldAllowReferenceValue() throws Exception {
+ UUID uuid = UUID.randomUUID();
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
uuid);
+ stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
+ prop = new JcrSingleValueProperty(node, executionContext, definition,
dnaProperty);
+ assertThat(prop.getString(), is(uuid.toString()));
+ assertThat(prop.getType(), is(PropertyType.STRING));
+ assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ }
+
+ @Test
+ public void shouldAllowNameValue() throws Exception {
+ executionContext.getNamespaceRegistry().register("acme",
"http://example.com");
+ Name path =
executionContext.getValueFactories().getNameFactory().create("acme:something");
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
path);
+ stub(definition.getRequiredType()).toReturn(PropertyType.NAME);
+ prop = new JcrSingleValueProperty(node, executionContext, definition,
dnaProperty);
+ assertThat(prop.getString(), is("acme:something"));
+ assertThat(prop.getType(), is(PropertyType.NAME));
+ assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ // Change the namespace registry ...
+ executionContext.getNamespaceRegistry().register("acme2",
"http://example.com");
+ assertThat(prop.getString(), is("acme2:something"));
+ }
+
+ @Test
+ public void shouldAllowPathValue() throws Exception {
+ executionContext.getNamespaceRegistry().register("acme",
"http://example.com");
+ Path path =
executionContext.getValueFactories().getPathFactory().create("/a/b/acme:c");
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
(Object)path);
+ stub(definition.getRequiredType()).toReturn(PropertyType.PATH);
+ prop = new JcrSingleValueProperty(node, executionContext, definition,
dnaProperty);
+ assertThat(prop.getString(), is("/a/b/acme:c"));
+ assertThat(prop.getType(), is(PropertyType.PATH));
+ assertThat(prop.getName(),
is(dnaProperty.getName().getString(executionContext.getNamespaceRegistry())));
+ // Change the namespace registry ...
+ executionContext.getNamespaceRegistry().register("acme2",
"http://example.com");
+ assertThat(prop.getString(), is("/a/b/acme2:c"));
+ }
+
+ @Test
+ public void shouldProvideValue() throws Exception {
+ Value val = prop.getValue();
+ assertThat(val, notNullValue());
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideValues() throws Exception {
+ prop.getValues();
+ }
+
+ @Test
+ public void shouldProvideLength() throws Exception {
+ String dnaValue =
executionContext.getValueFactories().getStringFactory().create(dnaProperty.getFirstValue());
+ assertThat(prop.getLength(), is((long)dnaValue.length()));
+
+ dnaValue = "some other value";
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
dnaValue);
+ stub(definition.getRequiredType()).toReturn(PropertyType.STRING);
+ prop = new JcrSingleValueProperty(node, executionContext, definition,
dnaProperty);
+ assertThat(prop.getLength(), is((long)dnaValue.length()));
+
+ Object obj = new Object();
+ long binaryLength =
executionContext.getValueFactories().getBinaryFactory().create(obj).getSize();
+ dnaProperty = executionContext.getPropertyFactory().create(JcrLexicon.MIMETYPE,
obj);
+ stub(definition.getRequiredType()).toReturn(PropertyType.BINARY);
+ prop = new JcrSingleValueProperty(node, executionContext, definition,
dnaProperty);
+ assertThat(prop.getLength(), is(binaryLength));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideLengths() throws Exception {
+ prop.getLengths();
+ }
+
+ @Test
+ public void shouldProvidePropertyDefinition() throws Exception {
+ assertThat(prop.getDefinition(), notNullValue());
+ }
+
+}
Property changes on:
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSingleValuePropertyTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain