Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix/Reduce compiler warnings
  • Loading branch information
ajs6f authored and Andrew Woods committed Oct 23, 2014
1 parent 671b991 commit 762f049
Show file tree
Hide file tree
Showing 68 changed files with 440 additions and 549 deletions.
Expand Up @@ -223,7 +223,7 @@ public Response createOrReplaceObjectRdf(
@QueryParam("checksum") final String checksum,
@HeaderParam("Content-Disposition") final ContentDisposition contentDisposition,
@HeaderParam("If-Match") final String ifMatch)
throws InvalidChecksumException, IOException, MalformedRdfException {
throws InvalidChecksumException, MalformedRdfException {

final FedoraResource resource;
final Response.ResponseBuilder response;
Expand Down Expand Up @@ -437,6 +437,7 @@ && isRdfContentType(contentTypeString)) {

}

@Override
protected void addResourceHttpHeaders(final FedoraResource resource) {
servletResponse.addHeader("Link", "<" + LDP_NAMESPACE + "Resource>;rel=\"type\"");

Expand Down
Expand Up @@ -26,7 +26,6 @@
import java.security.Principal;

import javax.inject.Inject;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.POST;
Expand Down Expand Up @@ -65,7 +64,7 @@ public class FedoraTransactions extends FedoraBaseResource {
*
* @param externalPath
* @return 201 with the transaction id and expiration date
* @throws RepositoryException
* @throws URISyntaxException
*/
@POST
public Response createTransaction(@PathParam("path") final String externalPath,
Expand Down Expand Up @@ -100,7 +99,6 @@ public Response createTransaction(@PathParam("path") final String externalPath,
*
* @param externalPath
* @return 204
* @throws RepositoryException
*/
@POST
@Path("fcr:commit")
Expand All @@ -115,7 +113,7 @@ public Response commit(@PathParam("path") final String externalPath) {
*/
@POST
@Path("fcr:rollback")
public Response rollback(@PathParam("path") final String externalPath) throws RepositoryException {
public Response rollback(@PathParam("path") final String externalPath) {

return finalizeTransaction(externalPath, false);
}
Expand Down
Expand Up @@ -15,15 +15,21 @@
*/
package org.fcrepo.http.api;

import com.google.common.annotations.VisibleForTesting;
import org.fcrepo.http.commons.responses.HtmlTemplate;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.exception.RepositoryVersionRuntimeException;
import org.fcrepo.kernel.impl.rdf.impl.VersionsRdfContext;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;
import static javax.ws.rs.core.MediaType.APPLICATION_XHTML_XML;
import static javax.ws.rs.core.MediaType.APPLICATION_XML;
import static javax.ws.rs.core.MediaType.TEXT_HTML;
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
import static javax.ws.rs.core.Response.created;
import static javax.ws.rs.core.Response.noContent;
import static org.apache.commons.lang.StringUtils.isBlank;
import static org.fcrepo.http.commons.domain.RDFMediaType.JSON_LD;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3_ALT2;
import static org.fcrepo.http.commons.domain.RDFMediaType.NTRIPLES;
import static org.fcrepo.http.commons.domain.RDFMediaType.RDF_XML;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE_X;
import static org.slf4j.LoggerFactory.getLogger;

import javax.inject.Inject;
import javax.jcr.RepositoryException;
Expand All @@ -41,23 +47,17 @@
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.net.URISyntaxException;

import static javax.ws.rs.core.MediaType.APPLICATION_XHTML_XML;
import static javax.ws.rs.core.MediaType.APPLICATION_XML;
import static javax.ws.rs.core.MediaType.TEXT_HTML;
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
import static javax.ws.rs.core.Response.created;
import static javax.ws.rs.core.Response.noContent;
import static org.apache.commons.lang.StringUtils.isBlank;
import static org.fcrepo.http.commons.domain.RDFMediaType.JSON_LD;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3_ALT2;
import static org.fcrepo.http.commons.domain.RDFMediaType.NTRIPLES;
import static org.fcrepo.http.commons.domain.RDFMediaType.RDF_XML;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE_X;
import static org.slf4j.LoggerFactory.getLogger;
import org.fcrepo.http.commons.responses.HtmlTemplate;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.exception.RepositoryVersionRuntimeException;
import org.fcrepo.kernel.impl.rdf.impl.VersionsRdfContext;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;

import com.google.common.annotations.VisibleForTesting;

/**
* @author cabeer
Expand Down Expand Up @@ -102,10 +102,9 @@ public FedoraVersioning(final String externalPath) {
/**
* Enable versioning
* @return
* @throws java.net.URISyntaxException
*/
@PUT
public Response enableVersioning() throws URISyntaxException {
public Response enableVersioning() {
resource().enableVersioning();

try {
Expand Down
Expand Up @@ -131,14 +131,13 @@ public Response removeVersion() throws RepositoryException {
* constructed manually):
* /versionable-node/fcr:versions/label/path/to/any/copied/unversionable/nodes
* @return the version of the object as RDF in the requested format
* @throws RepositoryException
*/
@GET
@Produces({TURTLE + ";qs=10", JSON_LD + ";qs=8",
N3, N3_ALT2, RDF_XML, NTRIPLES, APPLICATION_XML, TEXT_PLAIN, TURTLE_X,
TEXT_HTML, APPLICATION_XHTML_XML, "*/*"})
public Response getVersion(@HeaderParam("Prefer") final Prefer prefer,
@HeaderParam("Range") final String rangeValue) throws RepositoryException, IOException {
@HeaderParam("Range") final String rangeValue) throws IOException {
LOGGER.trace("Getting version profile for: {} at version: {}", path,
label);
checkCacheControlHeaders(request, servletResponse, resource(), session);
Expand Down
Expand Up @@ -27,15 +27,11 @@
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE_X;


import javax.inject.Inject;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;

import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.http.commons.responses.HtmlTemplate;
Expand All @@ -58,14 +54,13 @@ public class FedoraRepositoryNodeTypes extends AbstractResource {
/**
* Retrieve all node types as RDF
* @return All node types as RDF
* @throws RepositoryException
*/
@GET
@Produces({TURTLE, N3, N3_ALT2, RDF_XML, NTRIPLES, APPLICATION_XML, TEXT_PLAIN, TURTLE_X,
TEXT_HTML, APPLICATION_XHTML_XML, JSON_LD})
@Timed
@HtmlTemplate("jcr:nodetypes")
public RdfStream getNodeTypes(@Context final UriInfo uriInfo) throws RepositoryException {
public RdfStream getNodeTypes() {
return nodeService.getNodeTypes(session).session(session);
}

Expand Down
Expand Up @@ -90,9 +90,9 @@
*/
public class FedoraLdpTest {

private String path = "/some/path";
private String binaryPath = "/some/binary/path";
private String binaryDescriptionPath = "/some/other/path";
private final String path = "/some/path";
private final String binaryPath = "/some/binary/path";
private final String binaryDescriptionPath = "/some/other/path";
private FedoraLdp testObj;

@Mock
Expand Down Expand Up @@ -129,7 +129,7 @@ public class FedoraLdpTest {
private FedoraHttpConfiguration mockHttpConfiguration;

@Before
public void setUp() throws Exception {
public void setUp() {
initMocks(this);
testObj = spy(new FedoraLdp(path));

Expand Down Expand Up @@ -174,7 +174,7 @@ private FedoraResource setResource(final Class<? extends FedoraResource> klass)
when(mockResource.getEtagValue()).thenReturn("");
when(mockResource.getTriples(eq(idTranslator), any(Class.class))).thenAnswer(new Answer<RdfStream>() {
@Override
public RdfStream answer(final InvocationOnMock invocationOnMock) throws Throwable {
public RdfStream answer(final InvocationOnMock invocationOnMock) {
return new RdfStream(Triple.create(createURI(invocationOnMock.getMock().toString()),
createURI("called"),
createURI(invocationOnMock.getArguments()[1].toString())
Expand Down Expand Up @@ -687,12 +687,13 @@ public void testCreateNewBinary() throws Exception {

when(mockBinaryService.findOrCreateBinary(mockSession, "/b")).thenReturn(mockBinary);

final InputStream content = toInputStream("x");
final Response actual = testObj.createObject(null, null, null, APPLICATION_OCTET_STREAM_TYPE, "b",
content);
try (final InputStream content = toInputStream("x")) {
final Response actual = testObj.createObject(null, null, null, APPLICATION_OCTET_STREAM_TYPE, "b",
content);

assertEquals(CREATED.getStatusCode(), actual.getStatus());
verify(mockBinary).setContent(content, APPLICATION_OCTET_STREAM, null, "", null);
assertEquals(CREATED.getStatusCode(), actual.getStatus());
verify(mockBinary).setContent(content, APPLICATION_OCTET_STREAM, null, "", null);
}
}

@Test(expected = ClientErrorException.class)
Expand Down
Expand Up @@ -23,24 +23,23 @@
import static org.mockito.MockitoAnnotations.initMocks;
import static org.springframework.test.util.ReflectionTestUtils.setField;

import javax.jcr.RepositoryException;
import java.net.URISyntaxException;
import java.security.Principal;

import javax.jcr.Session;
import javax.jcr.Workspace;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Response;

import org.fcrepo.kernel.Transaction;
import org.fcrepo.kernel.impl.TxAwareSession;
import org.fcrepo.kernel.TxSession;
import org.fcrepo.kernel.impl.TxAwareSession;
import org.fcrepo.kernel.services.TransactionService;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;

import java.net.URISyntaxException;
import java.security.Principal;

/**
* <p>FedoraTransactionsTest class.</p>
*
Expand Down Expand Up @@ -87,7 +86,7 @@ public void setUp() {
}

@Test
public void shouldStartANewTransaction() throws RepositoryException, URISyntaxException {
public void shouldStartANewTransaction() throws URISyntaxException {
setField(testObj, "session", regularSession);
when(mockTxService.beginTransaction(regularSession, USER_NAME)).thenReturn(mockTx);
when(mockRequest.getUserPrincipal()).thenReturn(mockPrincipal);
Expand All @@ -97,52 +96,47 @@ public void shouldStartANewTransaction() throws RepositoryException, URISyntaxEx
}

@Test
public void shouldUpdateExpiryOnExistingTransaction()
throws RepositoryException, URISyntaxException {
public void shouldUpdateExpiryOnExistingTransaction() throws URISyntaxException {
when(mockTxService.getTransaction(Mockito.any(TxSession.class))).thenReturn(mockTx);
testObj.createTransaction(null, mockRequest);
verify(mockTx).updateExpiryDate();
}

@Test
public void shouldCommitATransaction() throws RepositoryException {
public void shouldCommitATransaction() {
testObj.commit(null);
verify(mockTxService).commit("123");
}

@Test
public void shouldErrorIfTheContextSessionIsNotATransaction()
throws RepositoryException {
public void shouldErrorIfTheContextSessionIsNotATransaction() {
setField(testObj, "session", regularSession);
final Response commit = testObj.commit(null);
assertEquals(400, commit.getStatus());
}

@Test
public void shouldErrorIfCommitIsNotCalledAtTheRepoRoot()
throws RepositoryException {
public void shouldErrorIfCommitIsNotCalledAtTheRepoRoot() {
setField(testObj, "session", regularSession);
final Response commit = testObj.commit("a");
assertEquals(400, commit.getStatus());
}

@Test
public void shouldRollBackATransaction() throws RepositoryException {
public void shouldRollBackATransaction() {
testObj.commit(null);
verify(mockTxService).commit("123");
}

@Test
public void shouldErrorIfTheContextSessionIsNotATransactionAtRollback()
throws RepositoryException {
public void shouldErrorIfTheContextSessionIsNotATransactionAtRollback() {
setField(testObj, "session", regularSession);
final Response commit = testObj.rollback(null);
assertEquals(400, commit.getStatus());
}

@Test
public void shouldErrorIfRollbackIsNotCalledAtTheRepoRoot()
throws RepositoryException {
public void shouldErrorIfRollbackIsNotCalledAtTheRepoRoot() {
setField(testObj, "session", regularSession);
final Response commit = testObj.rollback("a");
assertEquals(400, commit.getStatus());
Expand Down

0 comments on commit 762f049

Please sign in to comment.