Skip to content

Commit

Permalink
Pull FedoraContent @context parameters to the class level
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Sep 22, 2014
1 parent 1e52ef3 commit a8dd0b4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
Expand Up @@ -44,6 +44,7 @@
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.UriInfo;

import org.fcrepo.http.commons.api.rdf.HttpIdentifierTranslator;
import org.fcrepo.http.commons.domain.ContentLocation;
Expand Down Expand Up @@ -74,6 +75,10 @@ public class FedoraContent extends ContentExposingResource {
@InjectedSession
protected Session session;

@Context protected Request request;
@Context protected HttpServletResponse servletResponse;
@Context protected UriInfo uriInfo;

private static final Logger LOGGER = getLogger(FedoraContent.class);

/**
Expand All @@ -85,14 +90,12 @@ public class FedoraContent extends ContentExposingResource {
*/
@POST
@Timed
public Response create(@PathParam("path")
final List<PathSegment> pathList,
@HeaderParam("Slug") final String slug,
@HeaderParam("Content-Disposition") final String contentDisposition,
@QueryParam("checksum") final String checksum,
@HeaderParam("Content-Type") final MediaType requestContentType,
@ContentLocation final InputStream requestBodyStream,
@Context final HttpServletResponse servletResponse)
public Response create(@PathParam("path") final List<PathSegment> pathList,
@HeaderParam("Slug") final String slug,
@HeaderParam("Content-Disposition") final String contentDisposition,
@QueryParam("checksum") final String checksum,
@HeaderParam("Content-Type") final MediaType requestContentType,
@ContentLocation final InputStream requestBodyStream)
throws InvalidChecksumException, ParseException {
final MediaType contentType = getSimpleContentType(requestContentType);

Expand Down Expand Up @@ -183,9 +186,7 @@ public Response modifyContent(@PathParam("path") final List<PathSegment> pathLis
@QueryParam("checksum") final String checksum,
@HeaderParam("Content-Disposition") final String contentDisposition,
@HeaderParam("Content-Type") final MediaType requestContentType,
@ContentLocation final InputStream requestBodyStream,
@Context final Request request,
@Context final HttpServletResponse servletResponse)
@ContentLocation final InputStream requestBodyStream)
throws InvalidChecksumException, ParseException {

try {
Expand Down Expand Up @@ -253,9 +254,7 @@ public Response modifyContent(@PathParam("path") final List<PathSegment> pathLis
@GET
@Timed
public Response getContent(@PathParam("path") final List<PathSegment> pathList,
@HeaderParam("Range") final String rangeValue,
@Context final Request request,
@Context final HttpServletResponse servletResponse)
@HeaderParam("Range") final String rangeValue)
throws IOException {
try {
final String path = toPath(pathList);
Expand Down
Expand Up @@ -103,6 +103,9 @@ public class FedoraContentTest {
@Mock
private PidMinter mockMinter;

@Mock
private Request mockRequest;

@Mock
private HttpServletResponse mockResponse;

Expand All @@ -116,9 +119,12 @@ public class FedoraContentTest {
public void setUp() throws Exception {
initMocks(this);
testObj = new FedoraContent();

setField(testObj, "request", mockRequest);
setField(testObj, "servletResponse", mockResponse);
setField(testObj, "uriInfo", getUriInfoImpl());
setField(testObj, "datastreamService", mockDatastreams);
setField(testObj, "nodeService", mockNodeService);
setField(testObj, "uriInfo", getUriInfoImpl());
setField(testObj, "versionService", mockVersions);
mockSession = mockSession(testObj);
setField(testObj, "session", mockSession);
Expand Down Expand Up @@ -151,7 +157,7 @@ public void testPutContent()
when(mockDatastreams.exists(mockSession, dsPath)).thenReturn(true);
final Response actual =
testObj.modifyContent(createPathList(pid, dsId), null, "inline; filename=\"xyz\"", null,
dsContentStream, null, mockResponse);
dsContentStream);
assertEquals(CREATED.getStatusCode(), actual.getStatus());
verify(mockBinary).setContent(dsContentStream, "application/octet-stream", null, "xyz", null);
verify(mockSession).save();
Expand All @@ -175,7 +181,7 @@ public void testCreateContent() throws RepositoryException, IOException,
when(mockDatastreams.exists(mockSession, dsPath)).thenReturn(true);
final Response actual =
testObj.create(createPathList(pid, dsId), null, null, null, TEXT_PLAIN_TYPE,
dsContentStream, mockResponse);
dsContentStream);
assertEquals(CREATED.getStatusCode(), actual.getStatus());
verify(mockBinary).setContent(dsContentStream, "text/plain", null, null, null);
verify(mockSession).save();
Expand Down Expand Up @@ -206,7 +212,7 @@ public void testCreateContentAtMintedPath() throws RepositoryException, InvalidC

final Response actual =
testObj.create(createPathList(pid), null, null, null, TEXT_PLAIN_TYPE,
dsContentStream, mockResponse);
dsContentStream);
assertEquals(CREATED.getStatusCode(), actual.getStatus());
verify(mockBinary).setContent(dsContentStream, "text/plain", null, null, null);
verify(mockSession).save();
Expand Down Expand Up @@ -236,7 +242,7 @@ public void testCreateContentWithSlug() throws RepositoryException, InvalidCheck
when(mockResource.hasContent()).thenReturn(false);
final Response actual =
testObj.create(createPathList(pid), dsid, null, null, TEXT_PLAIN_TYPE,
dsContentStream, mockResponse);
dsContentStream);
assertEquals(CREATED.getStatusCode(), actual.getStatus());
verify(mockBinary).setContent(dsContentStream, "text/plain", null, null, null);
verify(mockSession).save();
Expand All @@ -261,14 +267,13 @@ public void testModifyContent()
when(mockDs.getBinary()).thenReturn(mockBinary);
when(mockBinary.getPath()).thenReturn(dsPath + "/jcr:content");

final Request mockRequest = mock(Request.class);
when(
mockRequest.evaluatePreconditions(any(Date.class),
any(EntityTag.class))).thenReturn(null);
when(mockDatastreams.exists(mockSession, dsPath)).thenReturn(true);
final Response actual =
testObj.modifyContent(createPathList(pid, dsId), "urn:sha1:some-checksum", null, null,
dsContentStream, mockRequest, mockResponse);
dsContentStream);
assertEquals(NO_CONTENT.getStatusCode(), actual.getStatus());
verify(mockBinary).setContent(dsContentStream, "application/octet-stream", checksum, null, null);
verify(mockSession).save();
Expand All @@ -287,9 +292,8 @@ public void testGetContent() throws RepositoryException, IOException {
when(mockDs.getNode()).thenReturn(mockNode);
when(mockNode.getPath()).thenReturn(path);
when(mockDs.getBinary().getDescription()).thenReturn(mockDs);
final Request mockRequest = mock(Request.class);
final Response actual =
testObj.getContent(createPathList(pid, dsId), null, mockRequest, mockResponse);
testObj.getContent(createPathList(pid, dsId), null);
verify(mockDs.getBinary()).getContent();
verify(mockSession, never()).save();
final String actualContent =
Expand Down

0 comments on commit a8dd0b4

Please sign in to comment.