Skip to content

Commit

Permalink
IT for Namespace, and some debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
barmintor committed Apr 26, 2013
1 parent c883094 commit 8efdd4e
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 7 deletions.
5 changes: 5 additions & 0 deletions fcrepo-http-api/pom.xml
Expand Up @@ -137,6 +137,11 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -38,7 +38,7 @@
*
*/
@Component
@Path("/rest/namespaces")
@Path("/rest/fcr:namespaces")
public class FedoraNamespaces extends AbstractResource {

/**
Expand Down Expand Up @@ -100,7 +100,7 @@ public Response registerObjectNamespaces(final NamespaceListing nses)
@GET
@Path("/{prefix}")
@Produces(APPLICATION_JSON)
public Namespace retrieveObjectNamespace(@PathParam("ns")
public Namespace retrieveObjectNamespace(@PathParam("prefix")
final String prefix) throws RepositoryException {

final Session session = getAuthenticatedSession();
Expand Down
Expand Up @@ -124,9 +124,12 @@ public Response createObject(
}

/**
* Returns an object profile.
* Returns a list of the first-generation
* descendants of an object, filtered by
* an optional mixin parameter
*
* @param pid
* @param pathList
* @param mixin
* @return 200
* @throws RepositoryException
* @throws IOException
Expand Down
@@ -0,0 +1,73 @@

package org.fcrepo.integration.api;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
import org.codehaus.jackson.map.AnnotationIntrospector;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector;
import org.fcrepo.jaxb.responses.management.NamespaceListing;
import org.fcrepo.jaxb.responses.management.NamespaceListing.Namespace;
import org.junit.Test;

public class FedoraNamespacesIT extends AbstractResourceIT {

@Test
public void testGet() throws Exception {

ObjectMapper mapper = new ObjectMapper();
AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
mapper.setAnnotationIntrospector(introspector);

HttpGet get = new HttpGet(serverAddress + "fcr:namespaces");
get.addHeader("Accept", "application/json");
HttpResponse response = execute(get);
int status = response.getStatusLine().getStatusCode();
assertEquals(200, status);

String content = EntityUtils.toString(response.getEntity());
NamespaceListing listing = mapper.readValue(content, NamespaceListing.class);
assertNotNull(listing);

get = new HttpGet(serverAddress + "fcr:namespaces/nt");
response = execute(get);
status = response.getStatusLine().getStatusCode();
assertEquals(200, status);

content = EntityUtils.toString(response.getEntity());
Namespace ns = mapper.readValue(content, Namespace.class);
assertNotNull(ns);

}

@Test
public void testCreate() throws Exception {
String expected = "http://foo.gov/" + new java.util.Date().getTime() + "/";
final HttpPost method = new HttpPost(serverAddress + "fcr:namespaces/foo");

final StringEntity entity = new StringEntity(expected);
method.setEntity(entity);
assertEquals(201, getStatus(method));
final HttpGet get = new HttpGet(method.getURI());
HttpResponse response = execute(get);
int status = response.getStatusLine().getStatusCode();
assertEquals(200, status);

ObjectMapper mapper = new ObjectMapper();
AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
mapper.setAnnotationIntrospector(introspector);
String content = EntityUtils.toString(response.getEntity());
Namespace actual = mapper.readValue(content, Namespace.class);
assertEquals(expected, actual.uri.toString());
}

}
Expand Up @@ -5,13 +5,13 @@
import java.util.Set;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "namespaceRegistry")
public class NamespaceListing {

@XmlElement(name = "namespace")
@XmlElementRef
public Set<Namespace> namespaces;

public NamespaceListing(final Set<Namespace> nses) {
Expand All @@ -21,9 +21,9 @@ public NamespaceListing(final Set<Namespace> nses) {
public NamespaceListing() {
}

@XmlRootElement(name = "namespace")
public static class Namespace {

@XmlAttribute
public String prefix;

@XmlAttribute(name = "URI")
Expand Down

0 comments on commit 8efdd4e

Please sign in to comment.