Skip to content

Commit

Permalink
Changed FedoraFixity to use injected Session
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed May 8, 2013
1 parent 3101b9f commit 2302412
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 75 deletions.
84 changes: 48 additions & 36 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraFixity.java
@@ -1,3 +1,4 @@

package org.fcrepo.api;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
Expand All @@ -21,62 +22,73 @@
import org.fcrepo.jaxb.responses.management.DatastreamFixity;
import org.fcrepo.services.DatastreamService;
import org.fcrepo.services.LowLevelStorageService;
import org.fcrepo.session.InjectedSession;
import org.fcrepo.utils.FixityResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.codahale.metrics.annotation.Timed;

@Component
@Scope("prototype")
@Path("/rest/{path: .*}/fcr:fixity")
public class FedoraFixity extends AbstractResource {

@Autowired
private DatastreamService datastreamService;
@InjectedSession
private Session session;

@Autowired
private DatastreamService datastreamService;

@Autowired
private LowLevelStorageService llStoreService;

@Autowired
private LowLevelStorageService llStoreService;
@GET
@Timed
@Produces({TEXT_XML, APPLICATION_JSON})
public DatastreamFixity getDatastreamFixity(@PathParam("path")
final List<PathSegment> pathList) throws RepositoryException {

@GET
@Timed
@Produces({TEXT_XML, APPLICATION_JSON})
public DatastreamFixity getDatastreamFixity(@PathParam("path")
List<PathSegment> pathList) throws RepositoryException {
final Session session = getAuthenticatedSession();

final Session session = getAuthenticatedSession();
try {
final String path = toPath(pathList);

try {
final String path = toPath(pathList);
final Datastream ds =
datastreamService.getDatastream(session, path);

final Datastream ds = datastreamService.getDatastream(session, path);
final DatastreamFixity dsf = new DatastreamFixity();
dsf.path = path;
dsf.timestamp = new Date();

final DatastreamFixity dsf = new DatastreamFixity();
dsf.path = path;
dsf.timestamp = new Date();
final Collection<FixityResult> blobs =
llStoreService.runFixityAndFixProblems(ds);
dsf.statuses = new ArrayList<FixityResult>(blobs);
return dsf;
} finally {
session.logout();
}
}

final Collection<FixityResult> blobs =
llStoreService.runFixityAndFixProblems(ds);
dsf.statuses = new ArrayList<FixityResult>(blobs);
return dsf;
} finally {
session.logout();
}
}
public DatastreamService getDatastreamService() {
return datastreamService;
}

public DatastreamService getDatastreamService() {
return datastreamService;
}
public void setDatastreamService(final DatastreamService datastreamService) {
this.datastreamService = datastreamService;
}

public void setDatastreamService(final DatastreamService datastreamService) {
this.datastreamService = datastreamService;
}
public LowLevelStorageService getLlStoreService() {
return llStoreService;
}

public LowLevelStorageService getLlStoreService() {
return llStoreService;
}
public void setLlStoreService(final LowLevelStorageService llStoreService) {
this.llStoreService = llStoreService;
}

public void setLlStoreService(final LowLevelStorageService llStoreService) {
this.llStoreService = llStoreService;
}
public void setSession(final Session session) {
this.session = session;
}

}
81 changes: 42 additions & 39 deletions fcrepo-http-api/src/test/java/org/fcrepo/api/FedoraFixityTest.java
@@ -1,3 +1,4 @@

package org.fcrepo.api;

import static org.fcrepo.test.util.PathSegmentImpl.createPathList;
Expand Down Expand Up @@ -27,56 +28,58 @@
import org.modeshape.jcr.api.Repository;

public class FedoraFixityTest {
FedoraFixity testObj;

DatastreamService mockDatastreams;

LowLevelStorageService mockLow;

Repository mockRepo;
FedoraFixity testObj;

Session mockSession;
DatastreamService mockDatastreams;

SecurityContext mockSecurityContext;
LowLevelStorageService mockLow;

HttpServletRequest mockServletRequest;
Repository mockRepo;

Principal mockPrincipal;
Session mockSession;

String mockUser = "testuser";
SecurityContext mockSecurityContext;

@Before
public void setUp() throws LoginException, RepositoryException {
mockDatastreams = mock(DatastreamService.class);
mockLow = mock(LowLevelStorageService.class);
HttpServletRequest mockServletRequest;

testObj = new FedoraFixity();
testObj.setDatastreamService(mockDatastreams);
testObj.setLlStoreService(mockLow);
Principal mockPrincipal;

testObj.setUriInfo(TestHelpers.getUriInfoImpl());
String mockUser = "testuser";

@Before
public void setUp() throws LoginException, RepositoryException {
mockDatastreams = mock(DatastreamService.class);
mockLow = mock(LowLevelStorageService.class);
testObj = new FedoraFixity();
testObj.setDatastreamService(mockDatastreams);
testObj.setLlStoreService(mockLow);
testObj.setUriInfo(TestHelpers.getUriInfoImpl());
mockSession = TestHelpers.mockSession(testObj);
testObj.setSession(mockSession);
}

mockSession = TestHelpers.mockSession(testObj);
}
@After
public void tearDown() {

@After
public void tearDown() {
}

}
@Test
public void testGetDatastreamFixity() throws RepositoryException,
IOException {
final String pid = "FedoraDatastreamsTest1";
final String path = "/objects/" + pid + "/testDS";
final String dsId = "testDS";
final Datastream mockDs = TestHelpers.mockDatastream(pid, dsId, null);
Node mockNode = mock(Node.class);
when(mockNode.getSession()).thenReturn(mockSession);
when(mockDs.getNode()).thenReturn(mockNode);
when(mockDatastreams.getDatastream(mockSession, path)).thenReturn(mockDs);
final DatastreamFixity actual = testObj.getDatastreamFixity(createPathList("objects", pid, "testDS"));
assertNotNull(actual);
verify(mockLow).runFixityAndFixProblems(mockDs);
}
@Test
public void testGetDatastreamFixity() throws RepositoryException,
IOException {
final String pid = "FedoraDatastreamsTest1";
final String path = "/objects/" + pid + "/testDS";
final String dsId = "testDS";
final Datastream mockDs = TestHelpers.mockDatastream(pid, dsId, null);
final Node mockNode = mock(Node.class);
when(mockNode.getSession()).thenReturn(mockSession);
when(mockDs.getNode()).thenReturn(mockNode);
when(mockDatastreams.getDatastream(mockSession, path)).thenReturn(
mockDs);
final DatastreamFixity actual =
testObj.getDatastreamFixity(createPathList("objects", pid,
"testDS"));
assertNotNull(actual);
verify(mockLow).runFixityAndFixProblems(mockDs);
}
}

0 comments on commit 2302412

Please sign in to comment.