Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Changed FedoraNamespaces to use injected Session
  • Loading branch information
ajs6f committed May 8, 2013
1 parent 2302412 commit bdb8d36
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
18 changes: 14 additions & 4 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraNamespaces.java
Expand Up @@ -23,6 +23,8 @@
import org.fcrepo.AbstractResource;
import org.fcrepo.jaxb.responses.management.NamespaceListing;
import org.fcrepo.jaxb.responses.management.NamespaceListing.Namespace;
import org.fcrepo.session.InjectedSession;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.codahale.metrics.annotation.Timed;
Expand All @@ -39,9 +41,13 @@
*
*/
@Component
@Scope("prototype")
@Path("/rest/fcr:namespaces")
public class FedoraNamespaces extends AbstractResource {

@InjectedSession
private Session session;

/**
* Creates a new namespace in the JCR for use in identifing objects.
*
Expand All @@ -51,7 +57,7 @@ public class FedoraNamespaces extends AbstractResource {
* @throws RepositoryException
*/
@POST
@Timed
@Timed
@Path("/{prefix}")
public Response registerObjectNamespace(@PathParam("prefix")
final String prefix, final String uri) throws RepositoryException {
Expand All @@ -75,7 +81,7 @@ public Response registerObjectNamespace(@PathParam("prefix")
* @throws RepositoryException
*/
@POST
@Timed
@Timed
@Consumes({TEXT_XML, APPLICATION_JSON})
public Response registerObjectNamespaces(final NamespaceListing nses)
throws RepositoryException {
Expand All @@ -102,7 +108,7 @@ public Response registerObjectNamespaces(final NamespaceListing nses)
*/
@GET
@Path("/{prefix}")
@Timed
@Timed
@Produces(APPLICATION_JSON)
public Namespace retrieveObjectNamespace(@PathParam("prefix")
final String prefix) throws RepositoryException {
Expand All @@ -127,7 +133,7 @@ public Namespace retrieveObjectNamespace(@PathParam("prefix")
* @throws IOException
*/
@GET
@Timed
@Timed
@Produces({TEXT_XML, APPLICATION_JSON})
public NamespaceListing getNamespaces() throws RepositoryException,
IOException {
Expand All @@ -146,4 +152,8 @@ public NamespaceListing getNamespaces() throws RepositoryException,
return new NamespaceListing(b.build());
}

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

}
Expand Up @@ -53,6 +53,7 @@ public void setUp() throws LoginException, RepositoryException,
any(HttpServletRequest.class))).thenReturn(mockSession);
testObj.setSessionFactory(mockSessions);
testObj.setPidMinter(new UUIDPidMinter());
testObj.setSession(mockSession);
}

@After
Expand All @@ -63,7 +64,8 @@ public void tearDown() {
@Test
public void testRegisterObjectNamespace() throws RepositoryException {
final Response actual =
testObj.registerObjectNamespace(TestHelpers.MOCK_PREFIX, TestHelpers.MOCK_URI_STRING);
testObj.registerObjectNamespace(TestHelpers.MOCK_PREFIX,
TestHelpers.MOCK_URI_STRING);
assertNotNull(actual);
assertEquals(Status.CREATED.getStatusCode(), actual.getStatus());
}
Expand All @@ -81,8 +83,10 @@ public void testRegisterObjectNamespaces() throws RepositoryException {

@Test
public void testRetrieveObjectNamespace() throws RepositoryException {
testObj.registerObjectNamespace(TestHelpers.MOCK_PREFIX, TestHelpers.MOCK_URI_STRING);
final Namespace actual = testObj.retrieveObjectNamespace(TestHelpers.MOCK_PREFIX);
testObj.registerObjectNamespace(TestHelpers.MOCK_PREFIX,
TestHelpers.MOCK_URI_STRING);
final Namespace actual =
testObj.retrieveObjectNamespace(TestHelpers.MOCK_PREFIX);
assertNotNull(actual);
assertEquals(actual.uri, mockNs.uri);
}
Expand Down

0 comments on commit bdb8d36

Please sign in to comment.