Skip to content

Commit

Permalink
Handling invalid namespace creation error
Browse files Browse the repository at this point in the history
  • Loading branch information
escowles committed May 20, 2014
1 parent b53b4dd commit 60dfd64
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Expand Up @@ -21,6 +21,7 @@
import static javax.ws.rs.core.MediaType.TEXT_HTML;
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
import static javax.ws.rs.core.Response.status;
import static org.apache.http.HttpStatus.SC_BAD_REQUEST;
import static org.apache.http.HttpStatus.SC_NO_CONTENT;
import static org.apache.jena.riot.WebContent.contentTypeSPARQLUpdate;
import static org.fcrepo.http.commons.domain.RDFMediaType.N3;
Expand Down Expand Up @@ -52,6 +53,7 @@

import com.codahale.metrics.annotation.Timed;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.shared.JenaException;

/**
* The purpose of this class is to allow clients to manipulate the JCR
Expand Down Expand Up @@ -90,6 +92,8 @@ public Response updateNamespaces(final InputStream requestBodyStream)
parseExecute(IOUtils.toString(requestBodyStream), dataset);
session.save();
return status(SC_NO_CONTENT).build();
} catch ( JenaException ex ) {
return status(SC_BAD_REQUEST).entity(ex.getMessage()).build();
} finally {
session.logout();
}
Expand Down
Expand Up @@ -75,6 +75,16 @@ public void testCreate() throws Exception {
createPlainLiteral("abc").asNode()));
}

@Test
public void testCreateInvalid() throws Exception {
final HttpPost post = new HttpPost(serverAddress + "fcr:namespaces");
final BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(new ByteArrayInputStream("invalid namespace declaration".getBytes()));
post.setEntity(entity);
assertEquals(400, getStatus(post));

}

@Test
public void testUpdatePrefix() throws Exception {
HttpPost post = new HttpPost(serverAddress + "fcr:namespaces");
Expand Down

0 comments on commit 60dfd64

Please sign in to comment.