Commits

Sam Adams committed 9054d71

Handle collection URLs without trailing slash

Comments (0)

Files changed (1)

client-cli/src/test/java/net/chempound/client/cli/ChempoundClientCLIIntegrationTest.java

 
     @BeforeClass
     public static void setUpChempound() throws Exception {
-        final URI baseUri = URI.create("http://localhost:12080/");
+        final URI baseUri = URI.create("http://localhost:12080/repo/");
         workspace = new File("target", UUID.randomUUID().toString());
 
         final ChempoundConfiguration configuration = new DefaultChempoundConfiguration(baseUri, workspace);
         component = injector.getInstance(Component.class);
         component.getServers().add(Protocol.HTTP, 12080)
                 .getContext().getParameters().add("maxThreads", "256");
-        component.getDefaultHost().attach(injector.getInstance(Application.class));
+        component.getDefaultHost().attach("/repo", injector.getInstance(Application.class));
         component.start();
 
         tripleStore = injector.getInstance(TripleStore.class);
 
     @Test
     public void testCreateCollection() throws Exception {
-        client.runMain("-R", "http://localhost:12080/sword/collection/",
+        client.runMain("-R", "http://localhost:12080/repo/sword/collection/",
                 "create-collection", "FooBar");
 
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/FooBar/"), type, Collection));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/FooBar/"), title, createPlainLiteral("FooBar")));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/"), ORE.aggregates, createResource("http://localhost:12080/content/FooBar/")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/FooBar/"), type, Collection));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/FooBar/"), title, createPlainLiteral("FooBar")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/FooBar/")));
     }
 
     @Test
     public void testCreateCollectionWithTitle() throws Exception {
-        client.runMain("-R", "http://localhost:12080/sword/collection/",
+        client.runMain("-R", "http://localhost:12080/repo/sword/collection/",
                 "create-collection", "--slug", "foobar", "FooBar");
 
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/foobar/"), type, Collection));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/foobar/"), title, createPlainLiteral("FooBar")));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/"), ORE.aggregates, createResource("http://localhost:12080/content/foobar/")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/foobar/"), type, Collection));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/foobar/"), title, createPlainLiteral("FooBar")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/foobar/")));
     }
 
     @Test
         FileUtils.forceMkdir(tmpDir);
         FileUtils.writeStringToFile(new File(tmpDir, "wibble.txt"), "wibble");
 
-        client.runMain("-R", "http://localhost:12080/sword/collection/",
+        client.runMain("-R", "http://localhost:12080/repo/sword/collection/",
                 "deposit", "wibble.txt");
 
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/foobar/"), type, Collection));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/foobar/"), title, createPlainLiteral("FooBar")));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/"), ORE.aggregates, createResource("http://localhost:12080/content/foobar/")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/foobar/"), type, Collection));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/foobar/"), title, createPlainLiteral("FooBar")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/foobar/")));
     }
 
     @Test
         FileUtils.forceMkdir(tmpDir);
         FileUtils.writeStringToFile(new File(tmpDir, "wibble.txt"), "wibble");
 
-        client.runMain("-R", "http://localhost:12080/sword/collection/", "--cwd", tmpDir.getAbsolutePath(),
+        client.runMain("-R", "http://localhost:12080/repo/sword/collection/", "--cwd", tmpDir.getAbsolutePath(),
                 "deposit", "-s", "flob", "-t", "##title##", "wibble.txt");
 
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/flob/"), type, Item));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/flob/"), title, createPlainLiteral("##title##")));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/flob/"), ORE.aggregates, createResource("http://localhost:12080/content/flob/wibble.txt")));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/"), ORE.aggregates, createResource("http://localhost:12080/content/flob/")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/flob/"), type, Item));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/flob/"), title, createPlainLiteral("##title##")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/flob/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/flob/wibble.txt")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/flob/")));
 
-        assertEquals("wibble", fetchUrl(URI.create("http://localhost:12080/content/flob/wibble.txt")));
+        assertEquals("wibble", fetchUrl(URI.create("http://localhost:12080/repo/content/flob/wibble.txt")));
     }
 
     @Test
         FileUtils.writeStringToFile(new File(tmpDir, "wibble.txt"), "wibble");
         FileUtils.writeStringToFile(new File(tmpDir, "wobble.txt"), "wobble");
 
-        client.runMain("-R", "http://localhost:12080/sword/collection/", "--cwd", tmpDir.getAbsolutePath(),
+        client.runMain("-R", "http://localhost:12080/repo/sword/collection/", "--cwd", tmpDir.getAbsolutePath(),
                 "deposit", "-s", "test", "wibble.txt", "wobble.txt");
 
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/test/"), ORE.aggregates, createResource("http://localhost:12080/content/test/wibble.txt")));
-        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/test/"), ORE.aggregates, createResource("http://localhost:12080/content/test/wobble.txt")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/test/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/test/wibble.txt")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/test/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/test/wobble.txt")));
 
-        assertEquals("wibble", fetchUrl(URI.create("http://localhost:12080/content/test/wibble.txt")));
-        assertEquals("wobble", fetchUrl(URI.create("http://localhost:12080/content/test/wobble.txt")));
+        assertEquals("wibble", fetchUrl(URI.create("http://localhost:12080/repo/content/test/wibble.txt")));
+        assertEquals("wobble", fetchUrl(URI.create("http://localhost:12080/repo/content/test/wobble.txt")));
     }
 
+    @Test
+    public void testDepositItemToRootCollectionWithoutSlash() throws Exception {
+        FileUtils.forceMkdir(tmpDir);
+        FileUtils.writeStringToFile(new File(tmpDir, "wibble.txt"), "wibble");
+
+        client.runMain("-R", "http://localhost:12080/repo/content", "--cwd", tmpDir.getAbsolutePath(),
+            "deposit", "-s", "abc", "wibble.txt");
+
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/abc/")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/abc/"), type, Item));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/abc/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/abc/wibble.txt")));
+
+        assertEquals("wibble", fetchUrl(URI.create("http://localhost:12080/repo/content/abc/wibble.txt")));
+    }
+
+    @Test
+    public void testDepositItemToChildCollectionWithoutSlash() throws Exception {
+        FileUtils.forceMkdir(tmpDir);
+        FileUtils.writeStringToFile(new File(tmpDir, "wibble.txt"), "wibble");
+
+        client.runMain("-R", "http://localhost:12080/repo/sword/collection/",
+            "create-collection", "--slug", "xyz", "XYZ");
+
+        client = new ChempoundClientCLI();
+
+        client.runMain("-R", "http://localhost:12080/repo/content/xyz", "--cwd", tmpDir.getAbsolutePath(),
+            "deposit", "-s", "xyzzy", "wibble.txt");
+
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/xyz/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/xyz/xyzzy/")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/xyz/xyzzy/"), type, Item));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/repo/content/xyz/xyzzy/"), ORE.aggregates, createResource("http://localhost:12080/repo/content/xyz/xyzzy/wibble.txt")));
+
+        assertEquals("wibble", fetchUrl(URI.create("http://localhost:12080/repo/content/xyz/xyzzy/wibble.txt")));
+    }
+
+
     private static String fetchUrl(final URI uri) throws IOException {
         InputStream in = uri.toURL().openStream();
         try {