Skip to content
Permalink
Browse files

Merge pull request #94 from futures/NextSourceCleanup

More source code cleanup
  • Loading branch information...
ajs6f committed Jul 4, 2013
2 parents 6ddee90 + 41429f1 commit 885c7fe721f408f4055cff8974ea361c6cffcde5
Showing with 521 additions and 527 deletions.
  1. +2 −2 fcrepo-generator-dc/src/main/java/org/fcrepo/generator/dublincore/DCGenerator.java
  2. +6 −8 fcrepo-generator-dc/src/main/java/org/fcrepo/generator/dublincore/JcrPropertiesGenerator.java
  3. +2 −2 fcrepo-generator-dc/src/main/java/org/fcrepo/generator/dublincore/WellKnownDatastreamGenerator.java
  4. +4 −5 fcrepo-generator-dc/src/main/java/org/fcrepo/generator/dublincore/WorstCaseGenerator.java
  5. +13 −13 fcrepo-generator-dc/src/test/java/org/fcrepo/generator/DublinCoreGeneratorTest.java
  6. +4 −6 fcrepo-generator-dc/src/test/java/org/fcrepo/generator/dublincore/JcrPropertiesGeneratorTest.java
  7. +10 −10 ...-generator-dc/src/test/java/org/fcrepo/generator/dublincore/WellKnownDatastreamGeneratorTest.java
  8. +3 −3 fcrepo-generator-dc/src/test/java/org/fcrepo/generator/dublincore/WorstCaseGeneratorTest.java
  9. +12 −18 fcrepo-http-api/src/test/java/org/fcrepo/api/FedoraContentTest.java
  10. +4 −10 fcrepo-http-api/src/test/java/org/fcrepo/api/FedoraDatastreamsTest.java
  11. +0 −6 fcrepo-http-api/src/test/java/org/fcrepo/api/FedoraFieldSearchTest.java
  12. +1 −7 fcrepo-http-api/src/test/java/org/fcrepo/api/FedoraFixityTest.java
  13. +46 −46 fcrepo-http-api/src/test/java/org/fcrepo/api/FedoraNodesTest.java
  14. +2 −8 fcrepo-http-api/src/test/java/org/fcrepo/api/FedoraRepositoryNamespacesTest.java
  15. +0 −6 fcrepo-http-api/src/test/java/org/fcrepo/api/FedoraSitemapTest.java
  16. +14 −20 fcrepo-http-api/src/test/java/org/fcrepo/api/FedoraUnnamedObjectsTest.java
  17. +6 −4 fcrepo-http-api/src/test/java/org/fcrepo/api/repository/FedoraRepositoriesPropertiesTest.java
  18. +12 −13 fcrepo-http-api/src/test/java/org/fcrepo/url/HttpApiResourcesTest.java
  19. +13 −12 fcrepo-http-commons/src/test/java/org/fcrepo/api/rdf/HttpGraphSubjectsTest.java
  20. +8 −7 fcrepo-http-commons/src/test/java/org/fcrepo/api/rdf/HttpTripleUtilTest.java
  21. +13 −10 fcrepo-http-commons/src/test/java/org/fcrepo/responses/BaseHtmlProviderTest.java
  22. +2 −2 fcrepo-http-commons/src/test/java/org/fcrepo/responses/GraphStreamingOutputTest.java
  23. +5 −5 fcrepo-http-commons/src/test/java/org/fcrepo/responses/RdfProviderTest.java
  24. +4 −5 fcrepo-http-commons/src/test/java/org/fcrepo/responses/RdfSerializationUtilsTest.java
  25. +54 −53 fcrepo-http-commons/src/test/java/org/fcrepo/responses/ViewHelpersTest.java
  26. +4 −4 fcrepo-http-commons/src/test/java/org/fcrepo/session/SessionProviderTest.java
  27. +29 −25 fcrepo-http-commons/src/test/java/org/fcrepo/test/util/TestHelpers.java
  28. +24 −25 fcrepo-kernel/src/test/java/org/fcrepo/DatastreamTest.java
  29. +86 −64 fcrepo-kernel/src/test/java/org/fcrepo/FedoraResourceTest.java
  30. +18 −12 fcrepo-kernel/src/test/java/org/fcrepo/TransactionTest.java
  31. +10 −8 fcrepo-kernel/src/test/java/org/fcrepo/TxAwareSessionTest.java
  32. +12 −11 fcrepo-metrics/src/main/java/org/fcrepo/metrics/MetricsConfig.java
  33. +11 −6 fcrepo-metrics/src/main/java/org/fcrepo/metrics/RegistryService.java
  34. +15 −13 fcrepo-metrics/src/main/java/org/fcrepo/metrics/ReporterFactory.java
  35. +5 −5 fcrepo-storage-policy/src/main/java/org/fcrepo/binary/MimeTypePolicy.java
  36. +8 −7 fcrepo-storage-policy/src/main/java/org/fcrepo/binary/PolicyDecisionPoint.java
  37. +26 −30 fcrepo-storage-policy/src/test/java/org/fcrepo/binary/MimeTypePolicyTest.java
  38. +25 −29 fcrepo-storage-policy/src/test/java/org/fcrepo/binary/PolicyDecisionPointTest.java
  39. +8 −7 pom.xml
@@ -21,13 +21,13 @@
import javax.jcr.Node;

/**
* Interface for retrieving a Dublin Core XML output
* from a node
* Interface for retrieving a Dublin Core XML output from a node
*/
public interface DCGenerator {

/**
* Get the Dublin Core content as an InputStream
*
* @param node node to retrieve a Dublin Core serialization for
* @return
*/
@@ -16,12 +16,11 @@

package org.fcrepo.generator.dublincore;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
@@ -31,12 +30,12 @@
import org.slf4j.Logger;

/**
* Derive a Dublin Core document from the JCR properties within
* the DC namespace.
* Derive a Dublin Core document from the JCR properties within the DC
* namespace.
*/
public class JcrPropertiesGenerator implements DCGenerator {

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

public static final String[] SALIENT_DC_PROPERTY_NAMESPACES =
@@ -73,10 +72,9 @@ public InputStream getStream(final Node node) {

str.append("</oai_dc:dc>");

return new ByteArrayInputStream(str.toString().getBytes(
StandardCharsets.UTF_8));
return new ByteArrayInputStream(str.toString().getBytes(UTF_8));
} catch (final RepositoryException e) {
logger.error("Repository exception: {}", e);
LOGGER.error("Repository exception: {}", e);
return null;
}
}
@@ -34,7 +34,7 @@
*/
public class WellKnownDatastreamGenerator implements DCGenerator {

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

private String wellKnownDsid;
@@ -46,7 +46,7 @@ public InputStream getStream(final Node node) {
return getContentInputStream(node);
} catch (final RepositoryException e) {

logger.warn("logged exception", e);
LOGGER.warn("logged exception", e);

return null;
}
@@ -16,12 +16,11 @@

package org.fcrepo.generator.dublincore;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import javax.jcr.Node;

import org.slf4j.Logger;
@@ -31,14 +30,14 @@
*/
public class WorstCaseGenerator implements DCGenerator {

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

@Override
public InputStream getStream(final Node node) {
logger.debug("Writing an empty oai dc document");
LOGGER.debug("Writing an empty oai dc document");
final String str =
"<oai_dc:dc xmlns:oai_dc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\" />";

return new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8));
return new ByteArrayInputStream(str.getBytes(UTF_8));
}
}
@@ -16,15 +16,16 @@

package org.fcrepo.generator;

import static java.util.Arrays.asList;
import static org.fcrepo.test.util.PathSegmentImpl.createPathList;
import static org.fcrepo.test.util.TestHelpers.mockSession;
import static org.fcrepo.test.util.TestHelpers.setField;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.InputStream;
import java.util.Arrays;

import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
@@ -33,7 +34,6 @@
import org.fcrepo.FedoraResource;
import org.fcrepo.generator.dublincore.DCGenerator;
import org.fcrepo.services.NodeService;
import org.fcrepo.test.util.TestHelpers;
import org.junit.Before;
import org.junit.Test;

@@ -51,19 +51,19 @@
public void setUp() throws RepositoryException, NoSuchFieldException {
mockNodeService = mock(NodeService.class);
testObj = new DublinCoreGenerator();
TestHelpers.setField(testObj, "nodeService", mockNodeService);
setField(testObj, "nodeService", mockNodeService);

mockSession = TestHelpers.mockSession(testObj);
TestHelpers.setField(testObj, "session", mockSession);
mockSession = mockSession(testObj);
setField(testObj, "session", mockSession);
mockGenerator = mock(DCGenerator.class);
testObj.dcgenerators = Arrays.asList(mockGenerator);
testObj.dcgenerators = asList(mockGenerator);
}

@Test
public void testGetObjectAsDublinCore() throws RepositoryException {
testObj.dcgenerators = Arrays.asList(mockGenerator);
InputStream mockIS = mock(InputStream.class);
FedoraResource mockResource = mock(FedoraResource.class);
testObj.dcgenerators = asList(mockGenerator);
final InputStream mockIS = mock(InputStream.class);
final FedoraResource mockResource = mock(FedoraResource.class);
when(mockResource.getNode()).thenReturn(mock(Node.class));
when(mockNodeService.getObject(mockSession, "/objects/foo"))
.thenReturn(mockResource);
@@ -74,13 +74,13 @@ public void testGetObjectAsDublinCore() throws RepositoryException {

@Test
public void testNoGenerators() {
testObj.dcgenerators = Arrays.asList(new DCGenerator[0]);
testObj.dcgenerators = asList(new DCGenerator[0]);
try {
testObj.getObjectAsDublinCore(createPathList("objects", "foo"));
fail("Should have failed without a generator configured!");
} catch (PathNotFoundException ex) {
} catch (final PathNotFoundException ex) {
// this is what we expect
} catch (RepositoryException e) {
} catch (final RepositoryException e) {
fail("unexpected RepositoryException: " + e.getMessage());
}
}
@@ -16,6 +16,7 @@

package org.fcrepo.generator.dublincore;

import static org.fcrepo.generator.dublincore.JcrPropertiesGenerator.SALIENT_DC_PROPERTY_NAMESPACES;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
@@ -58,8 +59,7 @@ public void testGetStreamNoProperties() throws Exception {

final PropertyIterator mockIterator = mock(PropertyIterator.class);
when(mockIterator.hasNext()).thenReturn(false);
when(
mockNode.getProperties(JcrPropertiesGenerator.SALIENT_DC_PROPERTY_NAMESPACES))
when(mockNode.getProperties(SALIENT_DC_PROPERTY_NAMESPACES))
.thenReturn(mockIterator);

final InputStream inputStream =
@@ -97,8 +97,7 @@ public void testGetStreamSingleValuedProperties() throws Exception {
when(mockIterator.nextProperty()).thenReturn(mockProperty1,
mockProperty2);

when(
mockNode.getProperties(JcrPropertiesGenerator.SALIENT_DC_PROPERTY_NAMESPACES))
when(mockNode.getProperties(SALIENT_DC_PROPERTY_NAMESPACES))
.thenReturn(mockIterator);

final InputStream inputStream =
@@ -138,8 +137,7 @@ public void testGetStreamMultivaluedProperties() throws Exception {

when(mockIterator.nextProperty()).thenReturn(mockProperty1);

when(
mockNode.getProperties(JcrPropertiesGenerator.SALIENT_DC_PROPERTY_NAMESPACES))
when(mockNode.getProperties(SALIENT_DC_PROPERTY_NAMESPACES))
.thenReturn(mockIterator);

final InputStream inputStream =
@@ -45,20 +45,20 @@ public void setUp() {

@Test
public void testGetStreamAbsent() {
Node mockNode = mock(Node.class);
InputStream actual = testObj.getStream(mockNode);
final Node mockNode = mock(Node.class);
final InputStream actual = testObj.getStream(mockNode);
assertTrue(actual == null);
}

@Test
public void testGetStreamPresent() throws Exception {
String dsid = "foo";
final String dsid = "foo";
testObj.setWellKnownDsid(dsid);
Node mockNode = mock(Node.class);
Node mockDS = mock(Node.class);
Node mockCN = mock(Node.class);
Binary mockB = mock(Binary.class);
Property mockD = mock(Property.class);
final Node mockNode = mock(Node.class);
final Node mockDS = mock(Node.class);
final Node mockCN = mock(Node.class);
final Binary mockB = mock(Binary.class);
final Property mockD = mock(Property.class);
when(mockNode.hasNode(dsid)).thenReturn(true);
when(mockNode.getNode(dsid)).thenReturn(mockDS);
when(mockDS.getNode(JCR_CONTENT)).thenReturn(mockCN);
@@ -71,11 +71,11 @@ public void testGetStreamPresent() throws Exception {
@Test
public void testSetWellKnownDsid() throws Exception {
testObj.setWellKnownDsid("foo");
Field field =
final Field field =
WellKnownDatastreamGenerator.class
.getDeclaredField("wellKnownDsid");
field.setAccessible(true);
String actual = (String) field.get(testObj);
final String actual = (String) field.get(testObj);
assertEquals("foo", actual);
}
}
@@ -44,9 +44,9 @@ public void setUp() throws JAXBException {

@Test
public void testGetStream() throws Exception {
Node mockNode = mock(Node.class);
InputStream out = testObj.getStream(mockNode);
OaiDublinCore actual =
final Node mockNode = mock(Node.class);
final InputStream out = testObj.getStream(mockNode);
final OaiDublinCore actual =
(OaiDublinCore) context.createUnmarshaller().unmarshal(out);
assertTrue(actual != null);
}
@@ -48,7 +48,6 @@
import org.fcrepo.services.DatastreamService;
import org.fcrepo.services.NodeService;
import org.fcrepo.test.util.TestHelpers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.modeshape.jcr.api.JcrConstants;
@@ -76,22 +75,17 @@ public void setUp() throws Exception {
TestHelpers.setField(testObj, "session", mockSession);
}

@After
public void tearDown() {

}

@Test
public void testPutContent() throws RepositoryException, IOException,
InvalidChecksumException, URISyntaxException {
InvalidChecksumException, URISyntaxException {
final String pid = "FedoraDatastreamsTest1";
final String dsId = "testDS";
final String dsContent = "asdf";
final String dsPath = "/" + pid + "/" + dsId;
final InputStream dsContentStream = IOUtils.toInputStream(dsContent);
final Node mockNode = mock(Node.class);
when(mockNode.isNew()).thenReturn(true);
Node mockContentNode = mock(Node.class);
final Node mockContentNode = mock(Node.class);
when(mockNode.getNode(JcrConstants.JCR_CONTENT)).thenReturn(
mockContentNode);
when(mockContentNode.getPath()).thenReturn(dsPath + "/jcr:content");
@@ -112,7 +106,7 @@ public void testPutContent() throws RepositoryException, IOException,

@Test
public void testCreateContent() throws RepositoryException, IOException,
InvalidChecksumException, URISyntaxException {
InvalidChecksumException, URISyntaxException {
final String pid = "FedoraDatastreamsTest1";
final String dsId = "xyz";
final String dsContent = "asdf";
@@ -121,16 +115,15 @@ public void testCreateContent() throws RepositoryException, IOException,
final Node mockNode = mock(Node.class);

when(mockNode.isNew()).thenReturn(true);
Node mockContentNode = mock(Node.class);
final Node mockContentNode = mock(Node.class);
when(mockNode.getNode(JcrConstants.JCR_CONTENT)).thenReturn(
mockContentNode);
when(mockContentNode.getPath()).thenReturn(dsPath + "/jcr:content");
when(mockNodeService.exists(mockSession, dsPath)).thenReturn(false);
when(
mockDatastreams.createDatastreamNode(any(Session.class),
eq(dsPath), anyString(), any(InputStream.class),
eq((URI) null))).thenReturn(
mockNode);
eq((URI) null))).thenReturn(mockNode);
when(mockDatastreams.exists(mockSession, dsPath)).thenReturn(true);
final Response actual =
testObj.create(createPathList(pid, dsId), null,
@@ -143,28 +136,29 @@ public void testCreateContent() throws RepositoryException, IOException,

@Test
public void testCreateContentAtMintedPath() throws RepositoryException,
IOException, InvalidChecksumException, URISyntaxException, NoSuchFieldException {
IOException, InvalidChecksumException, URISyntaxException,
NoSuchFieldException {
final String pid = "FedoraDatastreamsTest1";
final String dsId = "fcr:new";
final String dsContent = "asdf";
final String dsPath = "/" + pid + "/" + dsId;
final InputStream dsContentStream = IOUtils.toInputStream(dsContent);
final Node mockNode = mock(Node.class);

PidMinter mockMinter = mock(PidMinter.class);
final PidMinter mockMinter = mock(PidMinter.class);
when(mockMinter.mintPid()).thenReturn("xyz");
TestHelpers.setField(testObj, "pidMinter", mockMinter);
when(mockNode.isNew()).thenReturn(true);
Node mockContentNode = mock(Node.class);
final Node mockContentNode = mock(Node.class);
when(mockNode.getNode(JcrConstants.JCR_CONTENT)).thenReturn(
mockContentNode);
when(mockContentNode.getPath()).thenReturn(dsPath + "/jcr:content");
when(mockNodeService.exists(mockSession, dsPath)).thenReturn(false);
when(
mockDatastreams.createDatastreamNode(any(Session.class),
eq("/" + pid + "/xyz"), anyString(),
any(InputStream.class), eq((URI) null)
)).thenReturn(mockNode);
any(InputStream.class), eq((URI) null))).thenReturn(
mockNode);
when(mockDatastreams.exists(mockSession, dsPath)).thenReturn(true);
final Response actual =
testObj.create(createPathList(pid, dsId), null,
@@ -177,7 +171,7 @@ public void testCreateContentAtMintedPath() throws RepositoryException,

@Test
public void testModifyContent() throws RepositoryException, IOException,
InvalidChecksumException, URISyntaxException {
InvalidChecksumException, URISyntaxException {
final String pid = "FedoraDatastreamsTest1";
final String dsId = "testDS";
final String dsContent = "asdf";
Oops, something went wrong.

0 comments on commit 885c7fe

Please sign in to comment.
You can’t perform that action at this time.