Skip to content

Commit

Permalink
More unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Oct 25, 2013
1 parent 6dfd2e4 commit a623168
Showing 1 changed file with 40 additions and 4 deletions.
Expand Up @@ -9,13 +9,16 @@
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;

import java.util.concurrent.ExecutionException;

import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.fcrepo.kernel.rdf.GraphSubjects;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;

import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Resource;
Expand Down Expand Up @@ -54,10 +57,20 @@ public class RdfPersisterTest {

private static final Statement mixinStatement = m.asStatement(mixinTriple);

private static final Triple foreignTriple = create(createAnon(),
createAnon(), createAnon());

private static final Statement foreignStatement = m.asStatement(foreignTriple);


@Before
public void setUp() throws RepositoryException {
initMocks(this);

}

@Test
public void testConsumeAsync() throws Exception {
when(mockStream.hasNext()).thenReturn(true, true, false);
when(mockStream.next()).thenReturn(propertyTriple, mixinTriple);
when(
Expand All @@ -66,12 +79,18 @@ public void setUp() throws RepositoryException {
when(
mockGraphSubjects.getNodeFromGraphSubject(mixinStatement
.getSubject())).thenReturn(mockNode);
when(
mockGraphSubjects.getNodeFromGraphSubject(foreignStatement
.getSubject())).thenReturn(mockNode);
when(
mockGraphSubjects.isFedoraGraphSubject(propertyStatement
.getSubject())).thenReturn(true);
when(
mockGraphSubjects.isFedoraGraphSubject(mixinStatement
.getSubject())).thenReturn(true);
when(
mockGraphSubjects.isFedoraGraphSubject(foreignStatement
.getSubject())).thenReturn(false);

testPersister =
new RdfPersister(mockGraphSubjects, mockSession, mockStream) {
Expand All @@ -89,10 +108,6 @@ protected void operateOnMixin(final Resource mixinResource,
}
};

}

@Test
public void testConsumeAsync() throws Exception {
testPersister.consumeAsync();
assertTrue("Didn't successfully operate on a property!",
successfullyOperatedOnAProperty);
Expand All @@ -101,4 +116,25 @@ public void testConsumeAsync() throws Exception {
successfullyOperatedOnAMixin);
}

@Test(expected = ExecutionException.class)
public void testBadStream() throws Exception {
when(mockStream.hasNext()).thenThrow(new RuntimeException("Expected."));
testPersister =
new RdfPersister(mockGraphSubjects, mockSession, mockStream) {

@Override
protected void operateOnProperty(final Statement s,
final Node subjectNode) throws RepositoryException {
}

@Override
protected void operateOnMixin(final Resource mixinResource,
final Node subjectNode) throws RepositoryException {
}
};
// this should blow out when we try to retrieve the result
testPersister.consumeAsync().get();
}


}

0 comments on commit a623168

Please sign in to comment.