Skip to content

Commit

Permalink
DNA-388 AbstractJcrNode.getReferences() is incorrectly implemented
Browse files Browse the repository at this point in the history
The method now throws an UnsupportedOperationException, since the method is not implemented correctly.  Also commented out some unit tests that were testing these methods.

git-svn-id: https://svn.jboss.org/repos/modeshape/trunk@864 76366958-4244-0410-ad5e-bbfabb93f86b
  • Loading branch information
Randall Hauch committed Apr 29, 2009
1 parent 04830db commit 3d69484
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 45 deletions.
2 changes: 2 additions & 0 deletions dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ public PropertyIterator getProperties( String namePattern ) throws RepositoryExc
* @see javax.jcr.Node#getReferences()
*/
public final PropertyIterator getReferences() throws RepositoryException {
if (true) throw new UnsupportedOperationException();
// This implementation is just wrong.
// Iterate through the properties to see which ones have a REFERENCE type ...
Collection<AbstractJcrProperty> properties = cache.findJcrPropertiesFor(nodeUuid);
Collection<AbstractJcrProperty> references = new LinkedList<AbstractJcrProperty>();
Expand Down
86 changes: 41 additions & 45 deletions dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@

import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsSame.sameInstance;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.stub;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import javax.jcr.Item;
import javax.jcr.ItemNotFoundException;
Expand All @@ -39,7 +36,6 @@
import javax.jcr.NodeIterator;
import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.PropertyType;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
Expand Down Expand Up @@ -399,47 +395,47 @@ public void shoudFailToReturnItemFromGetPrimaryItemIfTheNodeHasNoItemMatchingTha
node.getPrimaryItem();
}

@Test
public void shouldReturnEmptyIteratorFromGetReferencesWhenThereAreNoProperties() throws Exception {
// Set up two properties (one containing references, the other not) ...
List<AbstractJcrProperty> props = Arrays.asList(new AbstractJcrProperty[] {});
stub(cache.findJcrPropertiesFor(uuid)).toReturn(props);
// Now call the method ...
PropertyIterator iter = node.getReferences();
assertThat(iter.getSize(), is(0L));
assertThat(iter.hasNext(), is(false));
}

@Test
public void shouldReturnEmptyIteratorFromGetReferencesWhenThereAreNoReferenceProperties() throws Exception {
// Set up two properties (one containing references, the other not) ...
AbstractJcrProperty propertyA = mock(AbstractJcrProperty.class);
AbstractJcrProperty propertyB = mock(AbstractJcrProperty.class);
List<AbstractJcrProperty> props = Arrays.asList(new AbstractJcrProperty[] {propertyA, propertyB});
stub(cache.findJcrPropertiesFor(uuid)).toReturn(props);
stub(propertyA.getType()).toReturn(PropertyType.LONG);
stub(propertyB.getType()).toReturn(PropertyType.BOOLEAN);
// Now call the method ...
PropertyIterator iter = node.getReferences();
assertThat(iter.getSize(), is(0L));
assertThat(iter.hasNext(), is(false));
}

@Test
public void shouldReturnIteratorFromGetReferencesWhenThereIsAtLeastOneReferenceProperty() throws Exception {
// Set up two properties (one containing references, the other not) ...
AbstractJcrProperty propertyA = mock(AbstractJcrProperty.class);
AbstractJcrProperty propertyB = mock(AbstractJcrProperty.class);
List<AbstractJcrProperty> props = Arrays.asList(new AbstractJcrProperty[] {propertyA, propertyB});
stub(cache.findJcrPropertiesFor(uuid)).toReturn(props);
stub(propertyA.getType()).toReturn(PropertyType.LONG);
stub(propertyB.getType()).toReturn(PropertyType.REFERENCE);
// Now call the method ...
PropertyIterator iter = node.getReferences();
assertThat(iter.getSize(), is(1L));
assertThat(iter.next(), is(sameInstance((Object)propertyB)));
assertThat(iter.hasNext(), is(false));
}
// @Test
// public void shouldReturnEmptyIteratorFromGetReferencesWhenThereAreNoProperties() throws Exception {
// // Set up two properties (one containing references, the other not) ...
// List<AbstractJcrProperty> props = Arrays.asList(new AbstractJcrProperty[] {});
// stub(cache.findJcrPropertiesFor(uuid)).toReturn(props);
// // Now call the method ...
// PropertyIterator iter = node.getReferences();
// assertThat(iter.getSize(), is(0L));
// assertThat(iter.hasNext(), is(false));
// }
//
// @Test
// public void shouldReturnEmptyIteratorFromGetReferencesWhenThereAreNoReferenceProperties() throws Exception {
// // Set up two properties (one containing references, the other not) ...
// AbstractJcrProperty propertyA = mock(AbstractJcrProperty.class);
// AbstractJcrProperty propertyB = mock(AbstractJcrProperty.class);
// List<AbstractJcrProperty> props = Arrays.asList(new AbstractJcrProperty[] {propertyA, propertyB});
// stub(cache.findJcrPropertiesFor(uuid)).toReturn(props);
// stub(propertyA.getType()).toReturn(PropertyType.LONG);
// stub(propertyB.getType()).toReturn(PropertyType.BOOLEAN);
// // Now call the method ...
// PropertyIterator iter = node.getReferences();
// assertThat(iter.getSize(), is(0L));
// assertThat(iter.hasNext(), is(false));
// }
//
// @Test
// public void shouldReturnIteratorFromGetReferencesWhenThereIsAtLeastOneReferenceProperty() throws Exception {
// // Set up two properties (one containing references, the other not) ...
// AbstractJcrProperty propertyA = mock(AbstractJcrProperty.class);
// AbstractJcrProperty propertyB = mock(AbstractJcrProperty.class);
// List<AbstractJcrProperty> props = Arrays.asList(new AbstractJcrProperty[] {propertyA, propertyB});
// stub(cache.findJcrPropertiesFor(uuid)).toReturn(props);
// stub(propertyA.getType()).toReturn(PropertyType.LONG);
// stub(propertyB.getType()).toReturn(PropertyType.REFERENCE);
// // Now call the method ...
// PropertyIterator iter = node.getReferences();
// assertThat(iter.getSize(), is(1L));
// assertThat(iter.next(), is(sameInstance((Object)propertyB)));
// assertThat(iter.hasNext(), is(false));
// }

@Test
public void shouldProvideSession() throws Exception {
Expand Down

0 comments on commit 3d69484

Please sign in to comment.