Skip to content

Commit

Permalink
FCREPO-1868: remove dependency on javax.jcr.Session in kernel-api
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Dec 23, 2015
1 parent 17b1585 commit 8204b18
Show file tree
Hide file tree
Showing 56 changed files with 170 additions and 210 deletions.
Expand Up @@ -91,7 +91,7 @@ public void testEmptyPrincipalProvider() throws RepositoryException {
for (final Privilege p : rootPrivs) {
logger.debug("got priv: " + p.getName());
}
final ContainerService os = new ContainerServiceImpl();
final ContainerService<Session> os = new ContainerServiceImpl();
os.findOrCreate(session, "/myobject");
verify(fad, atLeastOnce()).hasPermission(any(Session.class), any(Path.class), any(String[].class));
}
Expand Down
Expand Up @@ -94,7 +94,7 @@ public void testDelegatedUserAccess() throws RepositoryException {
((Principal) session.getAttribute(FedoraAuthorizationDelegate.FEDORA_USER_PRINCIPAL)).getName());

// try to create an object, this should fail because it is being executed as a non-admin user
final ContainerService os = new ContainerServiceImpl();
final ContainerService<Session> os = new ContainerServiceImpl();
try {
os.findOrCreate(session, "/myobject");
} catch (final RepositoryRuntimeException e) {
Expand Down
Expand Up @@ -91,7 +91,7 @@ public void testEmptyPrincipalProvider() throws RepositoryException {
for (final Privilege p : rootPrivs) {
logger.debug("got priv: " + p.getName());
}
final ContainerService os = new ContainerServiceImpl();
final ContainerService<Session> os = new ContainerServiceImpl();
os.findOrCreate(session, "/myobject");
verify(fad, atLeastOnce()).hasPermission(any(Session.class), any(Path.class), any(String[].class));
}
Expand Down
Expand Up @@ -104,7 +104,7 @@ public void testPermissiveFAD() throws RepositoryException {
for (final Privilege p : rootPrivs) {
logger.debug("got priv: " + p.getName());
}
final ContainerService os = new ContainerServiceImpl();
final ContainerService<Session> os = new ContainerServiceImpl();
os.findOrCreate(session, "/myobject");
verify(fad, atLeastOnce()).hasPermission(any(Session.class), any(Path.class), any(String[].class));
}
Expand All @@ -125,7 +125,7 @@ public void testRestrictiveFAD() throws Throwable {

final ServletCredentials credentials = new ServletCredentials(request);
final Session session = repo.login(credentials);
final ContainerService os = new ContainerServiceImpl();
final ContainerService<Session> os = new ContainerServiceImpl();
try {
os.findOrCreate(session, "/myobject");
} catch (final RepositoryRuntimeException e) {
Expand Down
Expand Up @@ -93,13 +93,13 @@ public abstract class AbstractFedoraFileSystemConnectorIT {
protected Repository repo;

@Inject
protected NodeService nodeService;
protected NodeService<Session> nodeService;

@Inject
protected ContainerService containerService;
protected ContainerService<Session> containerService;

@Inject
protected BinaryService binaryService;
protected BinaryService<Session> binaryService;

/**
* Gets the path (relative to the filesystem federation) of a directory
Expand Down
Expand Up @@ -54,7 +54,7 @@ public class FedoraTransactions extends FedoraBaseResource {
private static final Logger LOGGER = getLogger(FedoraTransactions.class);

@Autowired
private TransactionService txService;
private TransactionService<Session> txService;

@Inject
protected Session session;
Expand All @@ -72,7 +72,7 @@ public Response createTransaction(@PathParam("path") final String externalPath,
@Context final HttpServletRequest req) throws URISyntaxException {

if (session instanceof TxSession) {
final Transaction t = txService.getTransaction(session);
final Transaction<Session> t = txService.getTransaction(session);
LOGGER.debug("renewing transaction {}", t.getId());
t.updateExpiryDate();
return noContent().expires(t.getExpires()).build();
Expand All @@ -88,7 +88,7 @@ public Response createTransaction(@PathParam("path") final String externalPath,
userName = userPrincipal.getName();
}

final Transaction t = txService.beginTransaction(session, userName);
final Transaction<Session> t = txService.beginTransaction(session, userName);
LOGGER.info("Created transaction '{}'", t.getId());

return created(new URI(translator().toDomain("/tx:" + t.getId()).toString())).expires(
Expand Down
Expand Up @@ -35,7 +35,6 @@

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
Expand Down Expand Up @@ -109,10 +108,9 @@ private void postConstruct() {
* Reverts the resource at the given path to the version specified by
* the label.
* @return response
* @throws RepositoryException if repository exception occurred
*/
@PATCH
public Response revertToVersion() throws RepositoryException {
public Response revertToVersion() {
LOGGER.info("Reverting {} to version {}.", path,
label);
versionService.revertToVersion(session, unversionedResourcePath(), label);
Expand All @@ -122,10 +120,9 @@ public Response revertToVersion() throws RepositoryException {
/**
* Removes the version specified by the label.
* @return 204 No Content
* @throws RepositoryException if repository exception occurred
**/
@DELETE
public Response removeVersion() throws RepositoryException {
public Response removeVersion() {
LOGGER.info("Removing {} version {}.", path, label);
versionService.removeVersion(session, unversionedResourcePath(), label);
return noContent().build();
Expand Down
Expand Up @@ -62,7 +62,7 @@ public class FedoraExportTest {
private JcrXmlSerializer mockJcrXmlSerializer;

@Mock
private ContainerService mockContainerService;
private ContainerService<?> mockContainerService;

@Mock
private FedoraResource mockResource;
Expand Down
Expand Up @@ -77,7 +77,6 @@ public void setUp() throws RepositoryException {
}

@Test
@SuppressWarnings("unchecked")
public void testGetDatastreamFixity() {
final RdfStream expected = new RdfStream();

Expand Down
Expand Up @@ -142,13 +142,13 @@ public class FedoraLdpTest {
private IdentifierConverter<Resource, FedoraResource> idTranslator;

@Mock
private NodeService mockNodeService;
private NodeService<Object> mockNodeService;

@Mock
private ContainerService mockContainerService;
private ContainerService<Object> mockContainerService;

@Mock
private BinaryService mockBinaryService;
private BinaryService<Object> mockBinaryService;

@Mock
private FedoraHttpConfiguration mockHttpConfiguration;
Expand Down Expand Up @@ -198,7 +198,6 @@ public void setUp() {
when(mockHeaders.getHeaderString("user-agent")).thenReturn("Test UserAgent");
}

@SuppressWarnings("unchecked")
private FedoraResource setResource(final Class<? extends FedoraResource> klass) throws RepositoryException {
final FedoraResource mockResource = mock(klass);

Expand Down Expand Up @@ -560,7 +559,6 @@ public void testGetWithExternalMessageBinary() throws Exception {
}

@Test
@SuppressWarnings("unchecked")
public void testGetWithBinaryDescription() throws RepositoryException, IOException {

final NonRdfSourceDescription mockResource
Expand Down Expand Up @@ -695,7 +693,6 @@ public void testPatchObject() throws Exception {
}

@Test
@SuppressWarnings("unchecked")
public void testPatchBinaryDescription() throws RepositoryException, MalformedRdfException, IOException {

final NonRdfSourceDescription mockObject = (NonRdfSourceDescription)setResource(NonRdfSourceDescription.class);
Expand Down
Expand Up @@ -74,13 +74,13 @@ public class FedoraNodesTest {
FedoraNodes testObj;

@Mock
private ContainerService mockObjects;
private ContainerService<Object> mockObjects;

@Mock
private NodeService mockNodes;
private NodeService<Object> mockNodes;

@Mock
private VersionService mockVersions;
private VersionService<?> mockVersions;

@Mock
private Node mockNode;
Expand Down Expand Up @@ -122,7 +122,7 @@ public class FedoraNodesTest {
@Mock
private ValueFactory mockValueFactory;

private String path = "/some/path";
private final String path = "/some/path";

@Before
public void setUp() throws Exception {
Expand Down
Expand Up @@ -57,13 +57,13 @@ public class FedoraTransactionsTest {
private Session regularSession;

@Mock
private Transaction mockTx;
private Transaction<Object> mockTx;

@Mock
private HttpServletRequest mockRequest;

@Mock
private TransactionService mockTxService;
private TransactionService<Object> mockTxService;

@Mock
private Principal mockPrincipal;
Expand Down
Expand Up @@ -56,10 +56,10 @@ public class FedoraVersioningTest {
private FedoraVersioning testObj;

@Mock
private NodeService mockNodes;
private NodeService<?> mockNodes;

@Mock
VersionService mockVersions;
VersionService<?> mockVersions;

@Mock
SessionFactory mockSessionFactory;
Expand Down Expand Up @@ -109,11 +109,10 @@ public void setUp() throws Exception {


@Test
@SuppressWarnings("unchecked")
public void testGetVersionList() {
when(mockRequest.selectVariant(POSSIBLE_RDF_VARIANTS)).thenReturn(
mockVariant);
when(mockNodes.find(any(Session.class), anyString())).thenReturn(
when(mockNodes.find(any(), anyString())).thenReturn(
mockResource);
when(mockResource.getTriples(any(IdentifierConverter.class), eq(VersionsRdfContext.class)))
.thenReturn(mockRdfStream);
Expand Down
Expand Up @@ -28,7 +28,6 @@

import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.nodetype.NodeType;
import javax.ws.rs.core.Request;
Expand All @@ -54,18 +53,18 @@ public class FedoraVersionsTest {
private FedoraVersions testObj;

@Mock
private NodeService mockNodes;
private NodeService<?> mockNodes;

@Mock
VersionService mockVersions;
VersionService<Object> mockVersions;

@Mock
private Node mockNode;

@Mock
private NodeType mockNodeType;

private Session mockSession;
private Object mockSession;

@Mock
private FedoraResourceImpl mockResource;
Expand All @@ -76,8 +75,8 @@ public class FedoraVersionsTest {
@Mock
private Variant mockVariant;

private String path = "/some/path";
private String versionLabel = "someLabel";
private final String path = "/some/path";
private final String versionLabel = "someLabel";

@Before
public void setUp() throws Exception {
Expand All @@ -94,33 +93,34 @@ public void setUp() throws Exception {
when(mockNode.getPrimaryNodeType()).thenReturn(mockNodeType);

setField(testObj, "idTranslator",
new HttpResourceConverter(mockSession, UriBuilder.fromUri("http://localhost/fcrepo/{path: .*}")));
new HttpResourceConverter((Session) mockSession, UriBuilder.fromUri(
"http://localhost/fcrepo/{path: .*}")));
}

@Test
public void testRevertToVersion() throws RepositoryException {
public void testRevertToVersion() {
doReturn(path).when(testObj).unversionedResourcePath();
final Response response = testObj.revertToVersion();
verify(mockVersions).revertToVersion(mockSession, path, versionLabel);
assertNotNull(response);
}

@Test (expected = PathNotFoundException.class)
public void testRevertToVersionFailure() throws RepositoryException {
public void testRevertToVersionFailure() {
doThrow(PathNotFoundException.class).when(testObj).unversionedResourcePath();
testObj.revertToVersion();
}

@Test
public void testRemoveVersion() throws RepositoryException {
public void testRemoveVersion() {
doReturn(path).when(testObj).unversionedResourcePath();
final Response response = testObj.removeVersion();
verify(mockVersions).removeVersion(mockSession, path, versionLabel);
assertNotNull(response);
}

@Test (expected = PathNotFoundException.class)
public void testRemoveVersionFailure() throws RepositoryException {
public void testRemoveVersionFailure() {
doThrow(PathNotFoundException.class).when(testObj).unversionedResourcePath();
testObj.removeVersion();
}
Expand Down
Expand Up @@ -45,7 +45,7 @@ public class FedoraRepositoryNodeTypesTest {
private FedoraRepositoryNodeTypes testObj;

@Mock
private NodeService mockNodes;
private NodeService<Object> mockNodes;

@Mock
private InputStream mockInputStream;
Expand Down
Expand Up @@ -18,6 +18,7 @@
import java.util.function.Supplier;

import javax.inject.Inject;
import javax.jcr.Session;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriInfo;
Expand Down Expand Up @@ -64,25 +65,25 @@ public class AbstractResource {
* The JCR node service
*/
@Inject
protected NodeService nodeService;
protected NodeService<Session> nodeService;

/**
* The repository object service
*/
@Inject
protected ContainerService containerService;
protected ContainerService<Session> containerService;

/**
* The bitstream service
*/
@Inject
protected BinaryService binaryService;
protected BinaryService<Session> binaryService;

/**
* The version service
*/
@Inject
protected VersionService versionService;
protected VersionService<Session> versionService;

@Inject
@Optional
Expand Down

0 comments on commit 8204b18

Please sign in to comment.