Skip to content

Commit

Permalink
Fixed the NullPointerError and enabled all the existing test cases in
Browse files Browse the repository at this point in the history
FedoraNodesTest.java and FedoraContentTest.java for transparent
hierarchy support.
  • Loading branch information
lsitu authored and Andrew Woods committed May 19, 2014
1 parent 43b7a0c commit f3ba1eb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
Expand Up @@ -44,6 +44,7 @@
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.ValueFactory;
import javax.jcr.Workspace;
import javax.jcr.nodetype.NodeType;
import javax.jcr.version.VersionManager;
Expand All @@ -61,7 +62,7 @@
import org.fcrepo.kernel.services.NodeService;
import org.fcrepo.kernel.services.VersionService;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mock;

public class FedoraContentTest {
Expand Down Expand Up @@ -124,7 +125,7 @@ public void setUp() throws Exception {
when(mockDatastream.getContentNode()).thenReturn(mockContentNode);
}

@Ignore
@Test
public void testPutContent() throws RepositoryException, InvalidChecksumException, URISyntaxException, ParseException {
final String pid = "FedoraDatastreamsTest1";
final String dsId = "testDS";
Expand All @@ -139,6 +140,8 @@ public void testPutContent() throws RepositoryException, InvalidChecksumExceptio
eq(dsPath), anyString(), eq("xyz"), any(InputStream.class), eq((URI)null)))
.thenReturn(mockDatastream);
when(mockDatastreams.exists(mockSession, dsPath)).thenReturn(true);
final ValueFactory mockFactory = mock(ValueFactory.class);
when(mockSession.getValueFactory()).thenReturn(mockFactory);
final Response actual =
testObj.modifyContent(createPathList(pid, dsId), null, "inline; filename=\"xyz\"", null,
dsContentStream, null, mockResponse);
Expand All @@ -149,13 +152,15 @@ public void testPutContent() throws RepositoryException, InvalidChecksumExceptio
}

@SuppressWarnings("unused")
@Ignore
@Test
public void testCreateContent() throws RepositoryException, IOException,
InvalidChecksumException, URISyntaxException, ParseException {
final String pid = "FedoraDatastreamsTest1";
final String dsId = "xyz";
final String dsContent = "asdf";
final String dsPath = "/" + pid + "/" + dsId;
final ValueFactory mockFactory = mock(ValueFactory.class);
when(mockSession.getValueFactory()).thenReturn(mockFactory);
final InputStream dsContentStream = IOUtils.toInputStream(dsContent);
when(mockNode.isNew()).thenReturn(true);
when(mockNode.getNode(JCR_CONTENT)).thenReturn(mockContentNode);
Expand All @@ -175,12 +180,14 @@ public void testCreateContent() throws RepositoryException, IOException,
verify(mockSession).save();
}

@Ignore
@Test
public void testCreateContentAtMintedPath() throws RepositoryException, InvalidChecksumException,
URISyntaxException, ParseException {
final String pid = "FedoraDatastreamsTest1";
final String dsContent = "asdf";
final String dsPath = "/" + pid;
final ValueFactory mockFactory = mock(ValueFactory.class);
when(mockSession.getValueFactory()).thenReturn(mockFactory);
final InputStream dsContentStream = IOUtils.toInputStream(dsContent);
when(mockNodeService.exists(mockSession, dsPath)).thenReturn(true);
when(mockMinter.mintPid()).thenReturn("xyz");
Expand All @@ -207,13 +214,15 @@ public void testCreateContentAtMintedPath() throws RepositoryException, InvalidC
}


@Ignore
@Test
public void testCreateContentWithSlug() throws RepositoryException, InvalidChecksumException,
URISyntaxException, ParseException {
final String pid = "FedoraDatastreamsTest1";
final String dsid = "slug";
final String dsContent = "asdf";
final String dsPath = "/" + pid;
final ValueFactory mockFactory = mock(ValueFactory.class);
when(mockSession.getValueFactory()).thenReturn(mockFactory);
final InputStream dsContentStream = IOUtils.toInputStream(dsContent);
when(mockNodeService.exists(mockSession, dsPath)).thenReturn(true);
setField(testObj, "pidMinter", mockMinter);
Expand All @@ -237,13 +246,15 @@ public void testCreateContentWithSlug() throws RepositoryException, InvalidCheck
verify(mockSession).save();
}

@Ignore
@Test
public void testModifyContent() throws RepositoryException, InvalidChecksumException, URISyntaxException, ParseException {
final String pid = "FedoraDatastreamsTest1";
final String dsId = "testDS";
final String dsContent = "asdf";
final String dsPath = "/" + pid + "/" + dsId;
final URI checksum = new URI("urn:sha1:some-checksum");
final ValueFactory mockFactory = mock(ValueFactory.class);
when(mockSession.getValueFactory()).thenReturn(mockFactory);
final InputStream dsContentStream = IOUtils.toInputStream(dsContent);
when(mockNode.isNew()).thenReturn(false);
final Datastream mockDs = mockDatastream(pid, dsId, dsContent);
Expand All @@ -268,12 +279,14 @@ public void testModifyContent() throws RepositoryException, InvalidChecksumExcep
verify(mockSession).save();
}

@Ignore
@Test
public void testGetContent() throws RepositoryException, IOException {
final String pid = "FedoraDatastreamsTest1";
final String dsId = "testDS";
final String path = "/" + pid + "/" + dsId;
final String dsContent = "asdf";
final ValueFactory mockFactory = mock(ValueFactory.class);
when(mockSession.getValueFactory()).thenReturn(mockFactory);
final Datastream mockDs = mockDatastream(pid, dsId, dsContent);
when(mockDatastreams.getDatastream(mockSession, path)).thenReturn(
mockDs);
Expand Down
Expand Up @@ -80,7 +80,6 @@
import org.fcrepo.kernel.services.VersionService;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mock;

Expand Down Expand Up @@ -178,10 +177,12 @@ public void setUp() throws Exception {

}

@Ignore/*(expected = WebApplicationException.class)*/
@Test(expected = WebApplicationException.class)
public void testCreateObjectWithBadPath() throws Exception {
final String path = "/does/not/exist";
final ValueFactory mockFactory = mock(ValueFactory.class);
when(mockNodes.exists(mockSession, path)).thenReturn(false);
when(mockSession.getValueFactory()).thenReturn(mockFactory);
testObj.createObject(createPathList(path), null, null, null, null, null, mockResponse, getUriInfoImpl(), null);
}

Expand Down Expand Up @@ -321,14 +322,15 @@ public void testCreateChildObjectWithSlug() throws Exception {
}


@Ignore
@Test
public void testDeleteObject() throws RepositoryException {
final String pid = "testObject";
final String path = "/" + pid;
when(mockNodes.getObject(isA(Session.class), isA(String.class)))
.thenReturn(mockObject);
when(mockObject.getEtagValue()).thenReturn("");

final ValueFactory mockFactory = mock(ValueFactory.class);
when(mockSession.getValueFactory()).thenReturn(mockFactory);
final Response actual = testObj.deleteObject(createPathList(pid), mockRequest);

assertNotNull(actual);
Expand All @@ -337,7 +339,7 @@ public void testDeleteObject() throws RepositoryException {
verify(mockSession).save();
}

@Ignore
@Test
public void testDescribeObject() throws RepositoryException {
final String pid = "FedoraObjectsRdfTest1";
final String path = "/" + pid;
Expand All @@ -353,6 +355,8 @@ public void testDescribeObject() throws RepositoryException {
mockRdfStream2);
when(mockNodes.getObject(isA(Session.class), isA(String.class)))
.thenReturn(mockObject);
final ValueFactory mockFactory = mock(ValueFactory.class);
when(mockSession.getValueFactory()).thenReturn(mockFactory);
final Request mockRequest = mock(Request.class);
final RdfStream rdfStream =
testObj.describe(createPathList(path), 0, -2, null, mockRequest,
Expand All @@ -364,7 +368,7 @@ public void testDescribeObject() throws RepositoryException {

}

@Ignore
@Test
public void testDescribeObjectNoInlining() throws RepositoryException, ParseException {
final String pid = "FedoraObjectsRdfTest1";
final String path = "/" + pid;
Expand All @@ -380,6 +384,8 @@ public void testDescribeObjectNoInlining() throws RepositoryException, ParseExce
any(HierarchyRdfContextOptions.class))).thenReturn(mockRdfStream2);
when(mockNodes.getObject(isA(Session.class), isA(String.class)))
.thenReturn(mockObject);
final ValueFactory mockFactory = mock(ValueFactory.class);
when(mockSession.getValueFactory()).thenReturn(mockFactory);
final Request mockRequest = mock(Request.class);
final Prefer prefer = new Prefer("return=representation;"
+ "include=\"http://www.w3.org/ns/ldp#PreferEmptyContainer\"");
Expand All @@ -390,7 +396,7 @@ public void testDescribeObjectNoInlining() throws RepositoryException, ParseExce

}

@Ignore
@Test
public void testSparqlUpdate() throws RepositoryException, IOException {
final String pid = "FedoraObjectsRdfTest1";
final String path = "/" + pid;
Expand All @@ -405,6 +411,8 @@ public void testSparqlUpdate() throws RepositoryException, IOException {
when(mockDataset.getNamedModel(PROBLEMS_MODEL_NAME))
.thenReturn(mockModel);
when(mockModel.isEmpty()).thenReturn(true);
final ValueFactory mockFactory = mock(ValueFactory.class);
when(mockSession.getValueFactory()).thenReturn(mockFactory);
testObj.updateSparql(createPathList(pid), getUriInfoImpl(), mockStream, mockRequest, mockResponse);

verify(mockObject).updatePropertiesDataset(any(IdentifierTranslator.class),
Expand All @@ -413,7 +421,7 @@ public void testSparqlUpdate() throws RepositoryException, IOException {
verify(mockSession).logout();
}

@Ignore
@Test
public void testReplaceRdf() throws Exception {
final String pid = "FedoraObjectsRdfTest1";
final String path = "/" + pid;
Expand All @@ -422,7 +430,8 @@ public void testReplaceRdf() throws Exception {
when(mockObject.getNode()).thenReturn(mockNode);
when(mockObject.getEtagValue()).thenReturn("");
when(mockNode.getPath()).thenReturn(path);

final ValueFactory mockFactory = mock(ValueFactory.class);
when(mockSession.getValueFactory()).thenReturn(mockFactory);
final InputStream mockStream =
new ByteArrayInputStream("<a> <b> <c>".getBytes());
when(mockNodes.getObject(mockSession, path)).thenReturn(mockObject);
Expand Down

0 comments on commit f3ba1eb

Please sign in to comment.