public StringResource(final InputStream source) { this(new InputStreamResource(source)); }
@Before public void init() { this.resource = new InputStreamResource( CsvReaderTest.class.getResourceAsStream("data.csv")); this.wrongResource = new InputStreamResource( CsvReaderTest.class.getResourceAsStream("wrongData.csv")); // Create the schema with 3 converters in order. this.schema = new CsvSchema(CONVERTER1, CONVERTER2, CONVERTER3); }
@Test public void testConfigurationDataKeySet() throws IOException { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); try (InputStream base = loader.getResourceAsStream(BASE_CONFIGURATION); InputStream override = loader.getResourceAsStream(OVERRIDE_CONFIGURATION)) { final Configuration configuration = new MergedConfiguration( new InputStreamResource(base), new InputStreamResource(override)); final Set<String> compareTo = new HashSet<>(); compareTo.add("feature"); Assert.assertEquals(configuration.configurationDataKeySet(), compareTo); } }
@Test public void testConfigurationDataKeySet() throws IOException { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); try (InputStream stream = loader.getResourceAsStream(CONFIGURATION)) { final StandardConfiguration configuration = new StandardConfiguration( new InputStreamResource(stream)); final Set<String> compareTo = new HashSet<>(); compareTo.add("feature"); Assert.assertEquals(configuration.configurationDataKeySet(), compareTo); } }
@Test public void testReadingPoint() { final GeoJsonReader reader = new GeoJsonReader(new InputStreamResource( GeoJsonReaderTest.class.getResourceAsStream("geojson-point.json"))); reader.forEachRemaining(located -> logger.info(located.toString())); } }
@Test public void testReadingMulti() { final GeoJsonReader reader = new GeoJsonReader(new InputStreamResource( GeoJsonReaderTest.class.getResourceAsStream("geojson-sample.json"))); reader.forEachRemaining(located -> logger.info(located.toString())); }
@Test public void testRead() { AbstractResource resource = new InputStreamResource( CsvReaderTest.class.getResourceAsStream("data.csv")); resource.lines().forEach(line -> logger.info(line)); resource = new InputStreamResource(CsvReaderTest.class.getResourceAsStream("data.csv")); Assert.assertEquals(3, Iterables.size(resource.lines())); }
@Before public void prepare() { final Resource resource = new InputStreamResource(() -> ConfiguredTaggableFilterTest.class .getResourceAsStream("test-filtering.json")); final Configuration configuration = new StandardConfiguration(resource); this.filter = new ConfiguredTaggableFilter(configuration); }
@Test public void testCreation() { final StringResource resource = new StringResource(new InputStreamResource( GeoJsonAtlasBuilderTest.class.getResourceAsStream("overpass-turbo.geojson"))); final Atlas created = new GeoJsonAtlasBuilder().create(resource); System.out.println(created); Assert.assertEquals(50, Iterables.size(created.edges())); } }
@Test public void testReplacement() { final Resource josmOsmFile = new InputStreamResource( () -> OsmFileParserTest.class.getResourceAsStream("josmOsmFile.osm")); final Resource osmFile = new InputStreamResource( () -> OsmFileParserTest.class.getResourceAsStream("osmFile.osm")); final StringResource result = new StringResource(); new OsmFileParser().update(josmOsmFile, result); Assert.assertEquals(osmFile.all(), result.all()); } }
@Test(expected = CoreException.class) public void testGridIndexReconstructionWithMissingCountryCode() { final CountryBoundaryMap map = CountryBoundaryMap.fromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("HTI_DOM_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(map.hasGridIndex()); final Set<String> countries = new HashSet<>( Arrays.asList("HTI", "DOM", /* Not there on purpose */"CIV")); // This is expected to throw a CoreException listing the missing country, versus a NPE. map.initializeGridIndex(countries); }
@Test public void testInputStreamResource() { // input stream resources require name to be set explicitly Assert.assertTrue(PREDICATE.test(new InputStreamResource(new StringInputStream("foo bar")) .withName("/some/path/XYZ_11-1095-641.atlas.gz"))); Assert.assertFalse( PREDICATE.test(new InputStreamResource(new StringInputStream("foo bar")))); }
@Test public void splitTest() { final InputStream input = new StringInputStream("line1: blah\nline2: haha"); final SplittableInputStream split = new SplittableInputStream(input); final InputStream in2 = split.split(); logger.info("{}", Iterables.asList(new InputStreamResource(split).lines())); logger.info("{}", Iterables.asList(new InputStreamResource(in2).lines())); Streams.close(split); } }
@Test public void testReadingPolygon() { final GeoJsonReader reader = new GeoJsonReader(new InputStreamResource( GeoJsonReaderTest.class.getResourceAsStream("geojson-polygon.json"))); Assert.assertTrue(reader.hasNext()); final PropertiesLocated located = reader.next(); final Polygon polygon = (Polygon) located.getItem(); Assert.assertEquals(4, polygon.segments().size()); Assert.assertTrue(polygon.finalHeading().isPresent()); Assert.assertTrue(polygon.isApproximatelyNSided(4, Angle.NONE)); }
@Test public void testBigNodeWithNoRestrictions() { final Atlas atlas = new TextAtlasBuilder().read(new InputStreamResource( () -> ComplexTurnRestrictionTest.class.getResourceAsStream("bigNode.txt.gz")) .withDecompressor(Decompressor.GZIP).withName("bigNode.txt.gz")); final List<BigNode> bigNodes = Iterables.asList(new BigNodeFinder().find(atlas)); final Optional<BigNode> possibleBigNode = bigNodes.stream() .filter(bigNode -> bigNode.getOsmIdentifier() == 3717537957L).findAny(); Assert.assertTrue(possibleBigNode.isPresent()); final BigNode bigNode = possibleBigNode.get(); Assert.assertTrue(!bigNode.allPaths().isEmpty()); Assert.assertTrue(bigNode.turnRestrictions().isEmpty()); }
@Test public void testWithinBoundingBoxButNotWithinBoundary() { final CountryBoundaryMap map = CountryBoundaryMap.fromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("DMA_boundary.txt"))); final Location location = Location.forWkt("POINT (-61.6678538 15.2957509)"); final CountryCodeProperties countryCodeProperties = map.getCountryCodeISO3(location); Assert.assertTrue(countryCodeProperties.usingNearestNeighbor()); }
@Test public void testNestedSingleRelations() { final RawAtlasGenerator rawAtlasGenerator = new RawAtlasGenerator( new InputStreamResource(() -> RawAtlasGeneratorTest.class .getResourceAsStream("nestedSingleRelations.osm.pbf"))); final Atlas atlas = rawAtlasGenerator.build(); // Verify Atlas Entities assertBasicRawAtlasPrinciples(atlas); Assert.assertEquals(5, atlas.numberOfPoints()); Assert.assertEquals(1, atlas.numberOfLines()); Assert.assertEquals(2, atlas.numberOfRelations()); }
@Test public void testDefaultOsmosisRelationConfiguration() { final Resource relationResource = new InputStreamResource( getClass().getClassLoader().getResourceAsStream( "org/openstreetmap/atlas/geography/atlas/pbf/osm-pbf-relation.json")); final Configuration relationConfiguration = new StandardConfiguration(relationResource); final ConfiguredTaggableFilter relationFilter = new ConfiguredTaggableFilter( relationConfiguration); final Taggable nonBoundaryRelationTags = Taggable.with("type", "restriction"); final Taggable boundaryRelationTags = Taggable.with("boundary", "administrative"); Assert.assertTrue(relationFilter.test(nonBoundaryRelationTags)); Assert.assertFalse(relationFilter.test(boundaryRelationTags)); }
@Test public void testAntiMeridian() { final CountryBoundaryMap map = CountryBoundaryMap.fromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("HTI_DOM_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(map.hasGridIndex()); final LineString lineString = (LineString) TestUtility .createJtsGeometryFromWKT("LINESTRING ( -179 18.84927, 179 18.84927 )"); // HTI is the closest to the line Assert.assertEquals("HTI", map.getCountryCodeISO3(lineString).getIso3CountryCode()); }
@Test public void testMalformedPolyLine() { // Based on a prior version of https://www.openstreetmap.org/way/621043891 final Atlas slicedRawAtlas = this.setup.getMalformedPolyLineAtlas(); final CountryBoundaryMap boundaryMap = CountryBoundaryMap .fromPlainText(new InputStreamResource(() -> WaySectionProcessorTest.class .getResourceAsStream("malformedPolyLineBoundaryMap.txt"))); final Atlas finalAtlas = new WaySectionProcessor(slicedRawAtlas, AtlasLoadingOption.createOptionWithAllEnabled(boundaryMap)).run(); Assert.assertEquals("Six edges, each having a reverse counterpart", 12, finalAtlas.numberOfEdges()); Assert.assertEquals("Four nodes", 4, finalAtlas.numberOfNodes()); }