public void test_of_classpath() throws Exception { ResourceLocator test = ResourceLocator.of("classpath:com/opengamma/strata/collect/io/TestFile.txt"); assertTrue(test.getLocator().startsWith("classpath")); assertTrue(test.getLocator().endsWith("com/opengamma/strata/collect/io/TestFile.txt")); assertEquals(test.getByteSource().read()[0], 'H'); assertEquals(test.getCharSource().readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertTrue(test.toString().startsWith("classpath")); assertTrue(test.toString().endsWith("com/opengamma/strata/collect/io/TestFile.txt")); }
public void test_ofPath_zipFile() throws Exception { Path path = Paths.get("src/test/resources/com/opengamma/strata/collect/io/TestFile.zip"); ResourceLocator test = ResourceLocator.ofPath(path); assertEquals( test.getLocator().replace('\\', '/'), "file:src/test/resources/com/opengamma/strata/collect/io/TestFile.zip"); byte[] read = test.getByteSource().read(); assertEquals(read[0], 80); // these are the standard header of a zip file assertEquals(read[1], 75); assertEquals(read[2], 3); assertEquals(read[3], 4); assertEquals( test.toString().replace('\\', '/'), "file:src/test/resources/com/opengamma/strata/collect/io/TestFile.zip"); }
public void test_orderedResources() throws Exception { List<ResourceLocator> list = ResourceConfig.orderedResources("TestFile.txt"); assertEquals(list.size(), 1); ResourceLocator test = list.get(0); assertEquals(test.getLocator().startsWith("classpath"), true); assertEquals(test.getLocator().endsWith("com/opengamma/strata/config/base/TestFile.txt"), true); assertEquals(test.getByteSource().read()[0], 'H'); assertEquals(test.getCharSource().readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.toString().startsWith("classpath"), true); assertEquals(test.toString().endsWith("com/opengamma/strata/config/base/TestFile.txt"), true); }
public void test_ofClasspath_withClass_absolute() throws Exception { ResourceLocator test = ResourceLocator.ofClasspath(ResourceLocator.class, "/com/opengamma/strata/collect/io/TestFile.txt"); assertTrue(test.getLocator().startsWith("classpath")); assertTrue(test.getLocator().endsWith("com/opengamma/strata/collect/io/TestFile.txt")); assertEquals(test.getByteSource().read()[0], 'H'); assertEquals(test.getCharSource().readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertTrue(test.toString().startsWith("classpath")); assertTrue(test.toString().endsWith("com/opengamma/strata/collect/io/TestFile.txt")); }
public void test_ofClasspath_withClass_relative() throws Exception { ResourceLocator test = ResourceLocator.ofClasspath(ResourceLocator.class, "TestFile.txt"); assertTrue(test.getLocator().startsWith("classpath")); assertTrue(test.getLocator().endsWith("com/opengamma/strata/collect/io/TestFile.txt")); assertEquals(test.getByteSource().read()[0], 'H'); assertEquals(test.getCharSource().readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertTrue(test.toString().startsWith("classpath")); assertTrue(test.toString().endsWith("com/opengamma/strata/collect/io/TestFile.txt")); }
public void test_ofClasspath_absolute() throws Exception { ResourceLocator test = ResourceLocator.ofClasspath("/com/opengamma/strata/collect/io/TestFile.txt"); assertTrue(test.getLocator().startsWith("classpath")); assertTrue(test.getLocator().endsWith("com/opengamma/strata/collect/io/TestFile.txt")); assertEquals(test.getByteSource().read()[0], 'H'); assertEquals(test.getCharSource().readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertTrue(test.toString().startsWith("classpath")); assertTrue(test.toString().endsWith("com/opengamma/strata/collect/io/TestFile.txt")); }
public void test_ofClasspathUrl() throws Exception { URL url = Resources.getResource("com/opengamma/strata/collect/io/TestFile.txt"); ResourceLocator test = ResourceLocator.ofClasspathUrl(url); assertTrue(test.getLocator().startsWith("classpath")); assertTrue(test.getLocator().endsWith("com/opengamma/strata/collect/io/TestFile.txt")); assertEquals(test.getByteSource().read()[0], 'H'); assertEquals(test.getCharSource().readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertTrue(test.toString().startsWith("classpath")); assertTrue(test.toString().endsWith("com/opengamma/strata/collect/io/TestFile.txt")); }
public void test_ofClasspath_relativeConvertedToAbsolute() throws Exception { ResourceLocator test = ResourceLocator.ofClasspath("com/opengamma/strata/collect/io/TestFile.txt"); assertTrue(test.getLocator().startsWith("classpath")); assertTrue(test.getLocator().endsWith("com/opengamma/strata/collect/io/TestFile.txt")); assertEquals(test.getByteSource().read()[0], 'H'); assertEquals(test.getCharSource().readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertTrue(test.toString().startsWith("classpath")); assertTrue(test.toString().endsWith("com/opengamma/strata/collect/io/TestFile.txt")); }
public void test_ofUrl() throws Exception { File file = new File("src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); URL url = file.toURI().toURL(); ResourceLocator test = ResourceLocator.ofUrl(url); String locator = test.getLocator(); assertTrue(locator.startsWith("url:file:")); assertTrue(locator.endsWith("src/test/resources/com/opengamma/strata/collect/io/TestFile.txt")); assertEquals(test.getByteSource().read()[0], 'H'); assertEquals(test.getCharSource().readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.toString(), locator); }
public void test_ofPath_fileInZipFile() throws Exception { Path zip = Paths.get("src/test/resources/com/opengamma/strata/collect/io/TestFile.zip"); try (FileSystem fs = FileSystems.newFileSystem(zip, null)) { Path path = fs.getPath("TestFile.txt").toAbsolutePath(); ResourceLocator test = ResourceLocator.ofPath(path); String locator = test.getLocator(); assertTrue(locator.startsWith("url:jar:file:")); assertTrue(locator.endsWith("src/test/resources/com/opengamma/strata/collect/io/TestFile.zip!/TestFile.txt")); assertEquals(test.getByteSource().read()[0], 'H'); assertEquals(test.getCharSource().readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.toString(), locator); } }
public void test_ofPath() throws Exception { Path path = Paths.get("src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); ResourceLocator test = ResourceLocator.ofPath(path); assertEquals( test.getLocator().replace('\\', '/'), "file:src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); assertEquals(test.getByteSource().read()[0], 'H'); assertEquals(test.getCharSource().readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertEquals( test.toString().replace('\\', '/'), "file:src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); }
public void test_ofFile() throws Exception { File file = new File("src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); ResourceLocator test = ResourceLocator.ofFile(file); assertEquals(test.getLocator(), "file:src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); assertEquals(test.getByteSource().read()[0], 'H'); assertEquals(test.getCharSource().readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.toString(), "file:src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); }
public void test_of_fileNoPrefix() throws Exception { ResourceLocator test = ResourceLocator.of("src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); assertEquals(test.getLocator(), "file:src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); assertEquals(test.getByteSource().read()[0], 'H'); assertEquals(test.getCharSource().readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.toString(), "file:src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); }
public void test_of_filePrefixed() throws Exception { ResourceLocator test = ResourceLocator.of("file:src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); assertEquals(test.getLocator(), "file:src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); assertEquals(test.getByteSource().read()[0], 'H'); assertEquals(test.getCharSource().readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.getCharSource(StandardCharsets.UTF_8).readLines(), ImmutableList.of("HelloWorld")); assertEquals(test.toString(), "file:src/test/resources/com/opengamma/strata/collect/io/TestFile.txt"); }