@Override public void run() { Map<String, String> options = Maps.newHashMap(); options.put("path", "a/b/c"); pattern.construct(options); } });
@Override public DatasetRepository getFromOptions(Map<String, String> options) { DatasetRepository repo = repos.get(options.get("id")); if (repo == null) { repo = mock(org.kitesdk.data.spi.DatasetRepository.class); when(repo.getUri()).thenReturn( URI.create("repo:" + mockPattern.construct(options))); repos.put(options.get("id"), repo); } return repo; } }
@Test public void testPathVariablesAfterGlob() throws URISyntaxException { URIPattern pattern = new URIPattern("file:/*path/:ns/:ds"); String uri = "file:/a/b/c/namespace/dataset"; Assert.assertTrue(pattern.matches(uri)); Map<String, String> actual = pattern.getMatch(uri); expected.put("uri:scheme", "file"); expected.put("ns", "namespace"); expected.put("ds", "dataset"); expected.put("path", "a/b/c"); Assert.assertEquals(expected, actual); URI constructed = pattern.construct(expected); Assert.assertEquals(URI.create(uri), constructed); }
@Test public void testOpaquePathVariablesAfterGlob() throws URISyntaxException { URIPattern pattern = new URIPattern("file:*path/:ns/:ds"); String uri = "file:a/b/c/namespace/dataset"; Assert.assertTrue(pattern.matches(uri)); Map<String, String> actual = pattern.getMatch(uri); expected.put("uri:scheme", "file"); expected.put("ns", "namespace"); expected.put("ds", "dataset"); expected.put("path", "a/b/c"); Assert.assertEquals(expected, actual); URI constructed = pattern.construct(expected); Assert.assertEquals(URI.create(uri), constructed); }
@Test public void testPathVariablesBeforeAndAfterGlob() throws URISyntaxException { URIPattern pattern = new URIPattern("file:/:ns/*path/:ds"); String uri = "file:/namespace/a/b/c/dataset"; Assert.assertTrue(pattern.matches(uri)); Map<String, String> actual = pattern.getMatch(uri); expected.put("uri:scheme", "file"); expected.put("ns", "namespace"); expected.put("ds", "dataset"); expected.put("path", "a/b/c"); Assert.assertEquals(expected, actual); URI constructed = pattern.construct(expected); Assert.assertEquals(URI.create(uri), constructed); }
@Test public void testOpaquePathVariablesBeforeAndAfterGlob() throws URISyntaxException { URIPattern pattern = new URIPattern("file::ns/*path/:ds"); String uri = "file:namespace/a/b/c/dataset"; Assert.assertTrue(pattern.matches(uri)); Map<String, String> actual = pattern.getMatch(uri); expected.put("uri:scheme", "file"); expected.put("ns", "namespace"); expected.put("ds", "dataset"); expected.put("path", "a/b/c"); Assert.assertEquals(expected, actual); URI constructed = pattern.construct(expected); Assert.assertEquals(URI.create(uri), constructed); }
@Test public void testOverrideQueryArgs() throws URISyntaxException { URIPattern pattern = new URIPattern("scheme:/*path?custom-option=true&use-ssl=false"); String uri = "scheme:/path/to/data.avro?use-ssl=true"; Assert.assertTrue(pattern.matches(uri)); Map<String, String> actual = pattern.getMatch(uri); expected.put("uri:scheme", "scheme"); expected.put("path", "path/to/data.avro"); expected.put("custom-option", "true"); expected.put("use-ssl", "true"); Assert.assertEquals(expected, actual); URI constructed = pattern.construct(expected); Assert.assertEquals(URI.create(uri), constructed); }
@Test public void testPathVariablesWithGlob() throws URISyntaxException { URIPattern pattern = new URIPattern("mysql:/:db/:table/*the-rest"); String uri = "mysql:/myDB/myTable/a/b/c"; Assert.assertTrue(pattern.matches(uri)); Map<String, String> actual = pattern.getMatch(uri); expected.put("uri:scheme", "mysql"); expected.put("db", "myDB"); expected.put("table", "myTable"); expected.put("the-rest", "a/b/c"); Assert.assertEquals(expected, actual); URI constructed = pattern.construct(expected); Assert.assertEquals(URI.create(uri), constructed); }
@Test public void testOpaqueOverrideQueryArgs() throws URISyntaxException { URIPattern pattern = new URIPattern("scheme:*path?custom-option=true&use-ssl=false"); String uri = "scheme:path/to/data.avro?use-ssl=true"; Assert.assertTrue(pattern.matches(uri)); Map<String, String> actual = pattern.getMatch(uri); expected.put("uri:scheme", "scheme"); expected.put("path", "path/to/data.avro"); expected.put("custom-option", "true"); expected.put("use-ssl", "true"); Assert.assertEquals(expected, actual); URI constructed = pattern.construct(expected); Assert.assertEquals(URI.create(uri), constructed); }
@Test public void testPathVariables() throws URISyntaxException { URIPattern pattern = new URIPattern("mysql:/:db/:table"); String uri = "mysql:/myDB/myTable"; Assert.assertTrue(pattern.matches(uri)); Map<String, String> actual = pattern.getMatch(uri); expected.put("uri:scheme", "mysql"); expected.put("db", "myDB"); expected.put("table", "myTable"); Assert.assertEquals(expected, actual); URI constructed = pattern.construct(expected); Assert.assertEquals(URI.create(uri), constructed); }
@Test public void testIgnoreTrailingSlash() throws URISyntaxException { URIPattern pattern = new URIPattern("mysql:/:db/:table"); String uri = "mysql:/myDB/myTable/"; Assert.assertTrue(pattern.matches(uri)); Map<String, String> actual = pattern.getMatch(uri); expected.put("uri:scheme", "mysql"); expected.put("db", "myDB"); expected.put("table", "myTable"); Assert.assertEquals(expected, actual); URI constructed = pattern.construct(expected); Assert.assertEquals(URI.create("mysql:/myDB/myTable"), constructed); }
@Test public void testSubURI() throws URISyntaxException { URIPattern pattern = new URIPattern("scheme:*sub-uri"); String uri = "scheme:other-scheme:/path/to/data.avro"; Assert.assertTrue(pattern.matches(uri)); Map<String, String> actual = pattern.getMatch(uri); expected.put("uri:scheme", "scheme"); expected.put("sub-uri", "other-scheme:/path/to/data.avro"); Assert.assertEquals(expected, actual); URI constructed = pattern.construct(expected); Assert.assertEquals(URI.create(uri), constructed); }
@Test public void testPathGlob() throws URISyntaxException { URIPattern pattern = new URIPattern("file:///*path"); String uri = "file:/path/to/data.avro"; Assert.assertTrue(pattern.matches(uri)); Map<String, String> actual = pattern.getMatch(uri); expected.put("uri:scheme", "file"); expected.put("path", "path/to/data.avro"); Assert.assertEquals(expected, actual); URI constructed = pattern.construct(expected); Assert.assertEquals(URI.create(uri), constructed); }
@Test public void testOpaqueQueryEncoding() throws URISyntaxException { URIPattern pattern = new URIPattern("file:path"); URI original = URI.create("file:path?f1=a,b,a%2Cb"); Map<String, String> match = pattern.getMatch(original); Assert.assertNotNull(match); Assert.assertEquals("a,b,a%2Cb", match.get("f1")); URI constructed = pattern.construct(match); Assert.assertEquals(original, constructed); }
@Test public void testPathEncoding() throws URISyntaxException { URIPattern pattern = new URIPattern("file:/*path"); URI original = URI.create("file:/a%2Fb/c"); Map<String, String> match = pattern.getMatch(original); Assert.assertNotNull(match); Assert.assertEquals("a%2Fb/c", match.get("path")); URI constructed = pattern.construct(match); Assert.assertEquals(original, constructed); }
@Test public void testQueryEncoding() throws URISyntaxException { URIPattern pattern = new URIPattern("file:/path"); URI original = URI.create("file:/path?f1=a,b,a%2Cb"); Map<String, String> match = pattern.getMatch(original); Assert.assertNotNull(match); Assert.assertEquals("a,b,a%2Cb", match.get("f1")); URI constructed = pattern.construct(match); Assert.assertEquals(original, constructed); }
@Test public void testOpaquePathEncoding() throws URISyntaxException { URIPattern pattern = new URIPattern("file:*path"); URI original = URI.create("file:a%2Fb/c"); Map<String, String> match = pattern.getMatch(original); Assert.assertNotNull(match); Assert.assertEquals("a%2Fb/c", match.get("path")); URI constructed = pattern.construct(match); Assert.assertEquals(original, constructed); }
@Test public void testStaticMatch() throws URISyntaxException { URIPattern pattern = new URIPattern("scheme:static"); String uri = "scheme:static"; Assert.assertTrue(pattern.matches(uri)); Map<String, String> actual = pattern.getMatch(uri); expected.put("uri:scheme", "scheme"); Assert.assertEquals(expected, actual); URI constructed = pattern.construct(expected); Assert.assertEquals(URI.create(uri), constructed); }
@Test public void testStaticPathMixed() throws URISyntaxException { URIPattern pattern = new URIPattern("mysql:/db/:db/table/:table"); String uri = "mysql:/db/myDB/table/myTable"; Assert.assertTrue(pattern.matches(uri)); Map<String, String> actual = pattern.getMatch(uri); expected.put("uri:scheme", "mysql"); expected.put("db", "myDB"); expected.put("table", "myTable"); Assert.assertEquals(expected, actual); Assert.assertNull(pattern.getMatch("mysql:/myDB/myTable")); URI constructed = pattern.construct(expected); Assert.assertEquals(URI.create(uri), constructed); }
@Test public void testStaticPathEnd() throws URISyntaxException { URIPattern pattern = new URIPattern("mysql:/:db/:table/wtf"); String uri = "mysql:/myDB/myTable/wtf"; Assert.assertTrue(pattern.matches(uri)); Map<String, String> actual = pattern.getMatch(uri); expected.put("uri:scheme", "mysql"); expected.put("db", "myDB"); expected.put("table", "myTable"); Assert.assertEquals(expected, actual); Assert.assertNull(pattern.getMatch("mysql:/myDB/myTable")); URI constructed = pattern.construct(expected); Assert.assertEquals(URI.create(uri), constructed); }