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_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_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_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")); }
@Test(dataProvider = "parse") public void parse(String location) { ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party2")).parseTrades(resource); assertEquals(trades.size(), 1); }
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_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_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"); }
public void badSelector() { String location = "classpath:com/opengamma/strata/loader/fpml/ird-ex08-fra.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); FpmlDocumentParser parser = FpmlDocumentParser.of(allParties -> ImmutableList.of("rubbish")); assertThrows( () -> parser.parseTrades(resource), FpmlParseException.class, "Selector returned an ID .*"); }
public void fxSpot() { String location = "classpath:com/opengamma/strata/loader/fpml/fx-ex01-fx-spot.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party1")).parseTrades(resource); assertEquals(trades.size(), 1); Trade trade = trades.get(0); assertEquals(trade.getClass(), FxSingleTrade.class); FxSingleTrade fxTrade = (FxSingleTrade) trade; assertEquals(fxTrade.getInfo().getTradeDate(), Optional.of(date(2001, 10, 23))); FxSingle fx = fxTrade.getProduct(); assertEquals(fx.getBaseCurrencyPayment(), Payment.of(GBP, 10000000, date(2001, 10, 25))); assertEquals(fx.getCounterCurrencyPayment(), Payment.of(USD, -14800000, date(2001, 10, 25))); }
public void fra_interpolated() { String location = "classpath:com/opengamma/strata/loader/fpml/ird-ex08-fra-interpolated.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party1")).parseTrades(resource); assertFra(trades, true); }
public void fra_wrapper1() { String location = "classpath:com/opengamma/strata/loader/fpml/ird-ex08-fra-wrapper1.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party2")).parseTrades(resource); assertFra(trades, false); }
public void fra() { String location = "classpath:com/opengamma/strata/loader/fpml/ird-ex08-fra.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party2")).parseTrades(resource); assertFra(trades, false); }
public void fra_namespace() { String location = "classpath:com/opengamma/strata/loader/fpml/ird-ex08-fra-namespace.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party2")).parseTrades(resource); assertFra(trades, false); }
public void fra_wrapper2() { String location = "classpath:com/opengamma/strata/loader/fpml/ird-ex08-fra-wrapper2.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); List<Trade> trades = FpmlDocumentParser.of(FpmlPartySelector.matching("Party2")).parseTrades(resource); assertFra(trades, false); }
public void notFpml() { String location = "classpath:com/opengamma/strata/loader/fpml/not-fpml.xml"; ByteSource resource = ResourceLocator.of(location).getByteSource(); FpmlDocumentParser parser = FpmlDocumentParser.of(FpmlPartySelector.any()); assertThrows( () -> parser.parseTrades(resource), FpmlParseException.class, "Unable to find FpML root element.*"); }