URITools { public URI relativePath(URI base, URI uri) { URI root = base.resolve("/"); if (!root.equals(uri.resolve("/"))) return uri; base = base.normalize(); uri = uri.normalize(); if (base.resolve("#").equals(uri.resolve("#"))) return base.relativize(uri); if (base.isAbsolute()) { base = root.relativize(base).resolve("."); uri = root.relativize(uri); } base = root.resolve(base).resolve("."); uri = root.resolve(uri); URI candidate = base.relativize(uri); URI relation = DOT; while (candidate.getPath().startsWith("/") && !(base.getPath().isEmpty() || base.getPath().equals("/"))) { base = base.resolve("../"); relation = relation.resolve("../"); candidate = base.relativize(uri); } URI resolved = relation.resolve(candidate); return resolved; }  URI relativePath(URI base, URI uri); URI relativeUriForBean(WorkflowBean bean, WorkflowBean relativeToBean); WorkflowBean resolveUri(URI uri, WorkflowBundle wfBundle); URI uriForBean(WorkflowBean bean); String validFilename(String name);  }
@Test public void relativizeNotSameFolder() { URI base = URI.create("workflow/Workflow.rdf"); URI uri = URI.create("profile/Profile/"); assertEquals("../profile/Profile/", uriTools.relativePath(base, uri).toASCIIString()); }
@Test public void relativizeNotSameFolderAbsolute() { URI base = URI.create("/workflow/Workflow.rdf"); URI uri = URI.create("/profile/Profile/"); assertEquals("../profile/Profile/", uriTools.relativePath(base, uri).toASCIIString()); }
@Test public void relativizeNotSameFolderComplete() { URI base = URI.create("http: URI uri = URI.create("http: assertEquals("../profile/Profile/", uriTools.relativePath(base, uri) .toASCIIString()); }
@Test public void relativizeSameFolder() { URI base = URI.create("workflow/Workflow.rdf"); URI uri = URI.create("workflow/Folder/"); assertEquals("Folder/", uriTools.relativePath(base, uri) .toASCIIString()); }
@Test public void relativizeSameFolderAbsoulute() { URI base = URI.create("/workflow/Workflow.rdf"); URI uri = URI.create("/workflow/Folder/"); assertEquals("Folder/", uriTools.relativePath(base, uri) .toASCIIString()); }
@Test public void relativizeSameFolderComplete() { URI base = URI.create("http: URI uri = URI.create("http: assertEquals("Folder/", uriTools.relativePath(base, uri) .toASCIIString()); }
@Test public void relativizeSamePath() { URI base = URI.create("workflow/../workflow URI uri = URI.create("workflow/Workflow.rdf#fish"); assertEquals("#fish", uriTools.relativePath(base, uri).toASCIIString()); }
@Test public void relativizeSamePathAbsolute() { URI base = URI.create("/workflow/../workflow URI uri = URI.create("/workflow/Workflow.rdf#fish"); assertEquals("#fish", uriTools.relativePath(base, uri).toASCIIString()); }
@Test public void relativizeSamePathComplete() { URI base = URI .create("http: URI uri = URI .create("http: assertEquals("#fish", uriTools.relativePath(base, uri).toASCIIString()); }
@Test public void relatizeSame() throws Exception { URI base = URI.create("workflow/HelloWorld.rdf"); URI uri = URI.create("workflow/HelloWorld/"); assertEquals("HelloWorld/", uriTools.relativePath(base, uri).toASCIIString()); }
@Test public void relatizeToFragment() throws Exception { URI base = URI.create("filename.txt"); URI fragment = URI.create("./#sd"); assertEquals(".#sd", uriTools.relativePath(base, fragment) .toASCIIString()); }
@Ignore("Not so critical to fix for now..") @Test public void relatizeToSlash() throws Exception { URI base = URI.create("filename.txt"); URI fragment = URI.create("./"); assertEquals("./", uriTools.relativePath(base, fragment) .toASCIIString()); }
@Test public void workflowIdentifier() { Workflow wf = wfBundle.getMainWorkflow(); String uuidPath = uriTools.relativePath(Workflow.WORKFLOW_ROOT, wf.getIdentifier()).getPath(); assertTrue(uuidPath.endsWith("/")); UUID.fromString(uuidPath.substring(0, uuidPath.length() - 1)); }