Skip to content

Commit

Permalink
Cleaning Java compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Dec 1, 2013
1 parent dd2d0ee commit 6401269
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 73 deletions.
Expand Up @@ -27,8 +27,6 @@
import static org.fcrepo.http.commons.domain.RDFMediaType.RDF_JSON;
import static org.fcrepo.http.commons.domain.RDFMediaType.RDF_XML;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE;
import static org.slf4j.LoggerFactory.getLogger;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -56,7 +54,6 @@
import org.fcrepo.kernel.rdf.GraphSubjects;
import org.fcrepo.kernel.rdf.JcrRdfTools;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

Expand All @@ -69,8 +66,6 @@
@Path("/fcr:workspaces")
public class FedoraRepositoryWorkspaces extends AbstractResource {

private static final Logger logger = getLogger(FedoraRepositoryWorkspaces.class);

@InjectedSession
protected Session session;

Expand Down
Expand Up @@ -94,10 +94,10 @@ public void testGetDatastreamVersionNotFound() throws Exception {

@Test
public void oldVersionContentIsStillAccessible() throws Exception {
String objName = "fvt3";
String dsName = "ds";
String firstVersionText = "foo";
String secondVersionText = "bar";
final String objName = "fvt3";
final String dsName = "ds";
final String firstVersionText = "foo";
final String secondVersionText = "bar";

final HttpPost createObjectMethod =
postObjMethod(objName);
Expand Down Expand Up @@ -136,9 +136,9 @@ public void oldVersionContentIsStillAccessible() throws Exception {
assertTrue("Didn't find a version triple!",
results.contains(Node.ANY, subject.asNode(), HAS_VERSION.asNode(), Node.ANY));

Iterator<Quad> versionIt = results.find(Node.ANY, subject.asNode(), HAS_VERSION.asNode(), Node.ANY);
String currentVersionUri = versionIt.next().getObject().getURI();
String firstVersionUri = versionIt.next().getObject().getURI();
final Iterator<Quad> versionIt = results.find(Node.ANY, subject.asNode(), HAS_VERSION.asNode(), Node.ANY);
versionIt.next().getObject().getURI();
final String firstVersionUri = versionIt.next().getObject().getURI();

final HttpGet retrieveFirstVersion = new HttpGet(firstVersionUri + "/fcr:content");
assertEquals("First version wasn't preserved as expected!",
Expand Down
Expand Up @@ -18,17 +18,15 @@
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.impl.client.HttpClientBuilder;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import static java.lang.Integer.MAX_VALUE;
import static java.lang.Integer.parseInt;
import static java.lang.System.getProperty;

Expand All @@ -47,22 +45,19 @@ public void setLogger() {

protected static final String HOSTNAME = "localhost";

protected static final String serverAddress = "http://" + HOSTNAME + ":" +
SERVER_PORT;

protected final PoolingClientConnectionManager connectionManager =
new PoolingClientConnectionManager();
protected static final String serverAddress = "http://" + HOSTNAME + ":"
+ SERVER_PORT;

protected static HttpClient client;

public AbstractResourceIT() {
connectionManager.setMaxTotal(Integer.MAX_VALUE);
connectionManager.setDefaultMaxPerRoute(5);
connectionManager.closeIdleConnections(3, TimeUnit.SECONDS);
client = new DefaultHttpClient(connectionManager);
final HttpClientBuilder b =
HttpClientBuilder.create().setMaxConnPerRoute(MAX_VALUE)
.setMaxConnTotal(MAX_VALUE);
client = b.build();
}

protected int getStatus(HttpUriRequest method)
protected int getStatus(final HttpUriRequest method)
throws ClientProtocolException, IOException {
logger.debug("Executing: " + method.getMethod() + " to " +
method.getURI());
Expand Down
Expand Up @@ -15,9 +15,7 @@
*/
package org.fcrepo.transform.http;

import org.apache.commons.io.IOUtils;
import org.fcrepo.http.commons.test.util.TestHelpers;
import org.fcrepo.transform.sparql.JQLResultSet;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
Expand All @@ -41,7 +39,6 @@

import static org.fcrepo.http.commons.test.util.TestHelpers.getUriInfoImpl;
import static org.fcrepo.http.commons.test.util.TestHelpers.mockSession;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;
Expand Down
Expand Up @@ -16,14 +16,13 @@

package org.fcrepo.webhooks;

import static java.lang.Integer.MAX_VALUE;
import static javax.ws.rs.core.Response.created;
import static javax.ws.rs.core.Response.noContent;
import static javax.ws.rs.core.Response.ok;

import java.io.IOException;
import java.io.StringWriter;
import java.util.concurrent.TimeUnit;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.jcr.Node;
Expand All @@ -41,8 +40,7 @@
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.impl.client.HttpClientBuilder;
import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.jms.legacy.LegacyMethod;
import org.fcrepo.kernel.observer.FedoraEvent;
Expand Down Expand Up @@ -83,9 +81,6 @@ public class FedoraWebhooks extends AbstractResource {
private static final Logger LOGGER = LoggerFactory
.getLogger(FedoraWebhooks.class);

protected static final PoolingClientConnectionManager connectionManager =
new PoolingClientConnectionManager();

protected static HttpClient client;

@InjectedSession
Expand All @@ -97,10 +92,10 @@ public class FedoraWebhooks extends AbstractResource {
private Session readOnlySession;

static {
connectionManager.setMaxTotal(Integer.MAX_VALUE);
connectionManager.setDefaultMaxPerRoute(5);
connectionManager.closeIdleConnections(3, TimeUnit.SECONDS);
client = new DefaultHttpClient(connectionManager);
final HttpClientBuilder b =
HttpClientBuilder.create().setMaxConnPerRoute(MAX_VALUE)
.setMaxConnTotal(MAX_VALUE);
client = b.build();
}

/**
Expand Down
Expand Up @@ -16,17 +16,15 @@

package org.fcrepo.integration.webhooks;

import static java.lang.Integer.MAX_VALUE;
import static java.lang.Integer.parseInt;
import static java.lang.System.getProperty;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.impl.client.HttpClientBuilder;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
Expand All @@ -51,16 +49,13 @@ public void setLogger() {
protected static final String serverAddress = "http://" + HOSTNAME + ":" +
SERVER_PORT;

protected final PoolingClientConnectionManager connectionManager =
new PoolingClientConnectionManager();

protected static HttpClient client;

public AbstractResourceIT() {
connectionManager.setMaxTotal(Integer.MAX_VALUE);
connectionManager.setDefaultMaxPerRoute(5);
connectionManager.closeIdleConnections(3, TimeUnit.SECONDS);
client = new DefaultHttpClient(connectionManager);
final HttpClientBuilder b =
HttpClientBuilder.create().setMaxConnPerRoute(MAX_VALUE)
.setMaxConnTotal(MAX_VALUE);
client = b.build();
}

protected int getStatus(final HttpUriRequest method)
Expand Down
Expand Up @@ -51,23 +51,23 @@ public void setUp() throws Exception {
mockSession = TestHelpers.mockSession(testObj);
mockRoot = mock(Node.class);
when(mockSession.getRootNode()).thenReturn(mockRoot);
Repository mockRepo = mock(Repository.class);
final Repository mockRepo = mock(Repository.class);
when(mockSession.getRepository()).thenReturn(mockRepo);
when(mockRepo.login()).thenReturn(mockSession);
Workspace mockWS = mock(Workspace.class);
NodeTypeManager mockNT = mock(NodeTypeManager.class);
final Workspace mockWS = mock(Workspace.class);
final NodeTypeManager mockNT = mock(NodeTypeManager.class);
when(mockWS.getNodeTypeManager()).thenReturn(mockNT);
when(mockSession.getWorkspace()).thenReturn(mockWS);
TestHelpers.setField(testObj, "session", mockSession);
TestHelpers.setField(testObj, "readOnlySession", mockSession);
SessionFactory mockSessions = mock(SessionFactory.class);
final SessionFactory mockSessions = mock(SessionFactory.class);
when(mockSessions.getInternalSession()).thenReturn(mockSession);
TestHelpers.setField(testObj, "sessions", mockSessions);
}

@Test
public void testInitialize() throws Exception {
EventBus mockBus = mock(EventBus.class);
final EventBus mockBus = mock(EventBus.class);
TestHelpers.setField(testObj, "eventBus", mockBus);
testObj.initialize();
verify(mockBus).register(testObj);
Expand All @@ -76,16 +76,16 @@ public void testInitialize() throws Exception {
@Test
public void testShowWebhooks() throws Exception {

NodeIterator mockNodes = mock(NodeIterator.class);
final NodeIterator mockNodes = mock(NodeIterator.class);

Node mockHook = mock(Node.class);
Property mockProp = mock(Property.class);
final Node mockHook = mock(Node.class);
final Property mockProp = mock(Property.class);
when(mockHook.getProperty(FedoraWebhooks.WEBHOOK_CALLBACK_PROPERTY))
.thenReturn(mockProp);

when(mockNodes.hasNext()).thenReturn(true, false);
when(mockNodes.nextNode()).thenReturn(mockHook).thenThrow(
IndexOutOfBoundsException.class);
new IndexOutOfBoundsException());
when(mockRoot.getNodes(FedoraWebhooks.WEBHOOK_SEARCH)).thenReturn(
mockNodes);

Expand All @@ -94,11 +94,11 @@ public void testShowWebhooks() throws Exception {

@Test
public void testRegisterWebhook() throws Exception {
String mockPath = "/webhook:foo";
Node mockNode = mock(Node.class);
NodeType mockType = mock(NodeType.class);
final String mockPath = "/webhook:foo";
final Node mockNode = mock(Node.class);
final NodeType mockType = mock(NodeType.class);
when(mockType.getName()).thenReturn(FedoraWebhooks.WEBHOOK_JCR_TYPE);
NodeType[] mockTypes = new NodeType[] {mockType};
final NodeType[] mockTypes = new NodeType[] {mockType};
when(mockNode.getMixinNodeTypes()).thenReturn(mockTypes);
when(mockSession.getNode(mockPath)).thenReturn(mockNode);
when(mockRoot.getNode(mockPath.substring(1))).thenReturn(mockNode);
Expand All @@ -109,21 +109,21 @@ public void testRegisterWebhook() throws Exception {
@SuppressWarnings("unchecked")
@Test
public void testOnEvent() throws Exception {
FedoraEvent mockEvent = mock(FedoraEvent.class);
String mockPath = "/mock/path/to/node";
final FedoraEvent mockEvent = mock(FedoraEvent.class);
final String mockPath = "/mock/path/to/node";
when(mockEvent.getPath()).thenReturn(mockPath);
Node mockNode = mock(Node.class);
NodeType mockType = mock(NodeType.class);
final Node mockNode = mock(Node.class);
final NodeType mockType = mock(NodeType.class);
when(mockType.getName()).thenReturn(FedoraWebhooks.WEBHOOK_JCR_TYPE);
NodeType[] mockTypes = new NodeType[] {mockType};
final NodeType[] mockTypes = new NodeType[] {mockType};
when(mockNode.getMixinNodeTypes()).thenReturn(mockTypes);
when(mockSession.getNode(mockPath)).thenReturn(mockNode);
when(mockRoot.getNode(mockPath.substring(1))).thenReturn(mockNode);
when(mockNode.getSession()).thenReturn(mockSession);
NodeIterator mockNodes = mock(NodeIterator.class);
final NodeIterator mockNodes = mock(NodeIterator.class);
// let's say we have one webhook node
Node mockHook = mock(Node.class);
Property mockProp = mock(Property.class);
final Node mockHook = mock(Node.class);
final Property mockProp = mock(Property.class);
when(mockHook.getProperty(FedoraWebhooks.WEBHOOK_CALLBACK_PROPERTY))
.thenReturn(mockProp);
when(mockProp.getString()).thenReturn(
Expand All @@ -139,7 +139,7 @@ public void testOnEvent() throws Exception {
@Test
public void testSessions() throws NoSuchFieldException {

EventBus mockBus = mock(EventBus.class);
final EventBus mockBus = mock(EventBus.class);
TestHelpers.setField(testObj, "eventBus", mockBus);

testObj.logoutSession();
Expand Down

0 comments on commit 6401269

Please sign in to comment.