/** * Add new mapping * * @param prefix prefix * @param namespace uri * @return operation result */ @POST @Path("/" + PREFIX_PATTERN) public Response addMapping(@PathParam("prefix") String prefix, @QueryParam("uri") @NotNull String namespace) { try { prefixService.add(prefix, namespace); return Response.status(Response.Status.CREATED).build(); } catch (URISyntaxException e) { return Response.status(Response.Status.NOT_ACCEPTABLE).entity(e.getMessage()).build(); } catch (IllegalArgumentException e) { return Response.status(Response.Status.CONFLICT).entity(e.getMessage()).build(); } }
/** * Add new mapping * * @param prefix prefix * @param namespace uri * @return operation result */ @POST @Path("/" + PREFIX_PATTERN) public Response addMapping(@PathParam("prefix") String prefix, @QueryParam("uri") @NotNull String namespace) { try { prefixService.add(prefix, namespace); return Response.status(Response.Status.CREATED).build(); } catch (URISyntaxException e) { return Response.status(Response.Status.NOT_ACCEPTABLE).entity(e.getMessage()).build(); } catch (IllegalArgumentException e) { return Response.status(Response.Status.CONFLICT).entity(e.getMessage()).build(); } }
@Test(expected=IllegalArgumentException.class) public void testDoubleSet() throws IllegalArgumentException, URISyntaxException { String prefix = "bar"; String namespace1 = "http://bar1#"; String namespace2 = "http://bar2#"; Assert.assertNull(prefixService.getNamespace(prefix)); prefixService.add(prefix, namespace1); Assert.assertNotNull(prefixService.getNamespace(prefix)); Assert.assertEquals(namespace1, prefixService.getNamespace(prefix)); Assert.assertEquals(prefix, prefixService.getPrefix(namespace1)); prefixService.add(prefix, namespace2); }
@Test public void testSet() throws IllegalArgumentException, URISyntaxException { String prefix = "foo"; String namespace = "http://foo#"; Assert.assertNull(prefixService.getNamespace(prefix)); prefixService.add(prefix, namespace); Assert.assertNotNull(prefixService.getNamespace(prefix)); Assert.assertEquals(namespace, prefixService.getNamespace(prefix)); Assert.assertEquals(prefix, prefixService.getPrefix(namespace)); }
@Test public void testForceDoubleSet() throws IllegalArgumentException, URISyntaxException { String prefix = "baz"; String namespace1 = "http://baz1#"; String namespace2 = "http://baz2#"; Assert.assertNull(prefixService.getNamespace(prefix)); prefixService.add(prefix, namespace1); Assert.assertNotNull(prefixService.getNamespace(prefix)); Assert.assertEquals(namespace1, prefixService.getNamespace(prefix)); Assert.assertEquals(prefix, prefixService.getPrefix(namespace1)); prefixService.forceAdd(prefix, namespace2); Assert.assertNotNull(prefixService.getNamespace(prefix)); Assert.assertEquals(namespace2, prefixService.getNamespace(prefix)); Assert.assertEquals(prefix, prefixService.getPrefix(namespace2)); }