Skip to content

Commit

Permalink
Killed use of deprecated StringBufferInputStream for no more warnings…
Browse files Browse the repository at this point in the history
…, yay.
  • Loading branch information
ajs6f committed Mar 22, 2013
1 parent 34bdd77 commit d2f7092
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
19 changes: 7 additions & 12 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraRepository.java
Expand Up @@ -2,18 +2,19 @@
package org.fcrepo.api;

import static com.google.common.collect.ImmutableMap.builder;
import static javax.jcr.Repository.REP_NAME_DESC;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
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_XML;
import static javax.ws.rs.core.Response.ok;
import static org.fcrepo.services.PathService.OBJECT_PATH;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;

import javax.jcr.LoginException;
import javax.jcr.NamespaceRegistry;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.nodetype.NodeType;
Expand All @@ -30,7 +31,6 @@
import org.fcrepo.provider.VelocityViewer;
import org.modeshape.jcr.api.nodetype.NodeTypeManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.ImmutableMap.Builder;

Expand All @@ -43,16 +43,14 @@
@Path("/describe")
public class FedoraRepository extends AbstractResource {

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

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

@GET
@Path("modeshape")
public Response describeModeshape() throws JsonGenerationException,
JsonMappingException, IOException, RepositoryException {
final Session session = repo.login();
logger.debug("Repository name: " +
repo.getDescriptor(Repository.REP_NAME_DESC));
logger.debug("Repository name: " + repo.getDescriptor(REP_NAME_DESC));
final Builder<String, Object> repoproperties = builder();
for (final String key : repo.getDescriptorKeys()) {
if (repo.getDescriptor(key) != null)
Expand Down Expand Up @@ -99,11 +97,9 @@ public DescribeRepository describe() throws LoginException,
return description;
}


@GET
@Produces(TEXT_HTML)
public String describeHtml() throws LoginException,
RepositoryException {
public String describeHtml() throws LoginException, RepositoryException {

Session session = repo.login();
DescribeRepository description = new DescribeRepository();
Expand All @@ -112,8 +108,7 @@ public String describeHtml() throws LoginException,
uriInfo.getBaseUriBuilder().path(OBJECT_PATH + "/123/oai_dc")
.build();
description.repositorySize = getRepositorySize(session);
description.numberOfObjects =
session.getNode("/objects").getNodes().getSize();
description.numberOfObjects = getRepositoryObjectCount(session);
session.logout();
VelocityViewer view = new VelocityViewer();
return view.getRepoInfo(description);
Expand Down
Expand Up @@ -4,6 +4,7 @@
import static org.apache.commons.codec.binary.Hex.encodeHexString;
import static org.fcrepo.utils.FixityResult.FixityState.BAD_CHECKSUM;
import static org.fcrepo.utils.FixityResult.FixityState.BAD_SIZE;
import static org.fcrepo.utils.FixityResult.FixityState.SUCCESS;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;
Expand Down Expand Up @@ -147,6 +148,7 @@ public FixityResult checkFixity(URI checksum, long size,
result.status.add(BAD_CHECKSUM);
if (result.dsSize != result.computedSize)
result.status.add(BAD_SIZE);
if (result.status.isEmpty()) result.status.add(SUCCESS);
logger.debug("Got " + result.toString());
ds.close();
} catch (CloneNotSupportedException e) {
Expand Down
14 changes: 8 additions & 6 deletions fcrepo-kernel/src/test/java/org/fcrepo/TestHelpers.java
@@ -1,17 +1,19 @@
package org.fcrepo;

import static org.mockito.Mockito.*;
import static org.apache.tika.io.IOUtils.toInputStream;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
import static org.modeshape.jcr.api.JcrConstants.JCR_DATA;

import java.io.IOException;
import java.io.StringBufferInputStream;

import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.RepositoryException;

import org.modeshape.jcr.api.Binary;
import org.modeshape.jcr.api.JcrConstants;

public class TestHelpers {
public static NodeIterator mockDatastreamNode(String dsId, String content) throws RepositoryException, IOException {
Expand All @@ -20,11 +22,11 @@ public static NodeIterator mockDatastreamNode(String dsId, String content) throw
Property mockData = mock(Property.class);
Binary mockBinary = mock(Binary.class);
when(mockDsNode.getName()).thenReturn(dsId);
when(mockDsNode.getNode(JcrConstants.JCR_CONTENT)).thenReturn(mockContent);
when(mockContent.getProperty(JcrConstants.JCR_DATA)).thenReturn(mockData);
when(mockDsNode.getNode(JCR_CONTENT)).thenReturn(mockContent);
when(mockContent.getProperty(JCR_DATA)).thenReturn(mockData);
when(mockData.getBinary()).thenReturn(mockBinary);
when(mockBinary.getMimeType()).thenReturn("binary/octet-stream");
when(mockBinary.getStream()).thenReturn(new StringBufferInputStream(content));
when(mockBinary.getStream()).thenReturn(toInputStream(content));
NodeIterator mockIter = mock(NodeIterator.class);
when(mockIter.hasNext()).thenReturn(true, false);
when(mockIter.next()).thenReturn(mockDsNode);
Expand Down

0 comments on commit d2f7092

Please sign in to comment.