@Override protected void mapFeatures(final File file, final HashMap map) { try (BufferedReader reader = new BufferedReader(new FileReader(file.getPath()))) { String line; // Read each line (flag) from the log file while ((line = reader.readLine()) != null) { // Parse the json final JsonObject source = getGson().fromJson(line, JsonObject.class); // Get the check name final String checkName = source.get(PROPERTIES).getAsJsonObject().get(GENERATOR) .getAsString(); // Add the check name as a key if (!map.containsKey(checkName)) { map.put(checkName, new HashMap<>()); } // Add the geoJSON as a value ((HashMap<String, HashMap>) map).get(checkName).put( source.get(PROPERTIES).getAsJsonObject().get(ID).getAsString(), source); } } catch (final IOException exc) { exc.printStackTrace(); } }
@BeforeClass public static void copyLogFiles() throws IOException { Files.copy(Paths.get( AtlasChecksGeoJSONDiffSubCommandTest.class.getResource("geo_11.geojson").getPath()), Paths.get(SOURCE_DIRECTORY.getPath() + "/geo_11.geojson")); Files.copy(Paths.get( AtlasChecksGeoJSONDiffSubCommandTest.class.getResource("geo_12.geojson").getPath()), Paths.get(SOURCE_DIRECTORY.getPath() + "/geo_12.geojson")); Files.copy(Paths.get( AtlasChecksGeoJSONDiffSubCommandTest.class.getResource("geo_21.geojson").getPath()), Paths.get(TARGET_DIRECTORY.getPath() + "/geo_21.geojson")); Files.copy(Paths.get( AtlasChecksGeoJSONDiffSubCommandTest.class.getResource("geo_22.geojson").getPath()), Paths.get(TARGET_DIRECTORY.getPath() + "/geo_22.geojson")); }
@BeforeClass public static void copyLogFiles() throws IOException { Files.copy( Paths.get( AtlasChecksLogDiffSubCommandTest.class.getResource("geo_11.log").getPath()), Paths.get(SOURCE_DIRECTORY.getPath() + "/geo_11.log")); Files.copy( Paths.get( AtlasChecksLogDiffSubCommandTest.class.getResource("geo_12.log").getPath()), Paths.get(SOURCE_DIRECTORY.getPath() + "/geo_12.log")); Files.copy( Paths.get( AtlasChecksLogDiffSubCommandTest.class.getResource("geo_21.log").getPath()), Paths.get(TARGET_DIRECTORY.getPath() + "/geo_21.log")); Files.copy( Paths.get( AtlasChecksLogDiffSubCommandTest.class.getResource("geo_22.log").getPath()), Paths.get(TARGET_DIRECTORY.getPath() + "/geo_22.log")); }
try (BufferedReader reader = new BufferedReader(new FileReader(logFile.getPath())))
@Override protected int onRun(final CommandMap command) { final File inputFolder = (File) command.get(INPUT_FOLDER); final String atlasName = inputFolder.getName(); final File outputFolder = (File) command.get(OUTPUT_FOLDER); initialize(command); if (inputFolder != null) { this.logger.info("Loading Atlas from {}", inputFolder); final Atlas atlas = loadAtlas(command); processAtlas(atlasName, atlas, outputFolder.getPath()); } return 0; }
@Test public void testJoinedOutput() { final File temp = File.temporary(); // Run AtlasFindByAtlasIdentifierSubCommand final String[] args = { "find-atlas-id", String.format("-input=%1$s", SHARD_PATH.getPath()), "-id=546649246000001,575954012000000", String.format("-joinedOutput=%1$s", temp.getPath()) }; new AtlasReader(args).runWithoutQuitting(args); Assert.assertTrue(temp.length() > 0); temp.delete(); } }
@Test public void testConsoleOutput() { // Redirect System.out to capture AtlasFindByFeatureIdentifierLocatorSubCommand output final PrintStream originalOut = System.out; final CaptureOutputStream captureStream = new CaptureOutputStream(originalOut); System.setOut(captureStream); try { // Run AtlasFindByAtlasIdentifierSubCommand final String[] args = { "find-atlas-id", String.format("-input=%1$s", SHARD_PATH.getPath()), "-id=546649246000001,575954012000000" }; new AtlasReader(args).runWithoutQuitting(args); } finally { // Reset System.out System.setOut(originalOut); } Arrays.stream(captureStream.getLog().split("\n")).forEach(line -> Assert .assertTrue(line.contains("DNK_2.atlas") || line.contains("DNK_3.atlas"))); }
@BeforeClass public static void createBinaryAtlases() { final List<String> shardList = Arrays.asList(TXT_PATH + "/DNK_1.txt", TXT_PATH + "/DNK_2.txt", TXT_PATH + "/DNK_3.txt"); shardList.forEach(shard -> new TextAtlasBuilder().read(new File(shard)) .save(new File(SHARD_PATH.getPath() + shard.replace("txt", "atlas")))); }
@BeforeClass public static void createBinaryAtlases() { final List<String> shardList = Arrays.asList(TXT_PATH + "/DNK_1.txt", TXT_PATH + "/DNK_2.txt", TXT_PATH + "/DNK_3.txt"); shardList.forEach(shard -> new TextAtlasBuilder().read(new File(shard)) .save(new File(SHARD_PATH.getPath() + shard.replace("txt", "atlas")))); }
@Test public void fileCreationFromFileTest() { final File temp = File.temporaryFolder(); // Run AtlasJoinerSubCommand final String[] args = { "log-diff", String.format("-source=%s", GEO_11), String.format("-target=%s", GEO_21), String.format("-output=%s", temp.getPath()) }; new AtlasChecksCommand(args).runWithoutQuitting(args); final List<File> outputFiles = temp.listFilesRecursively(); Assert.assertTrue(outputFiles.stream() .anyMatch(file -> file.getName().matches("additions-\\d+-1.log"))); Assert.assertTrue(outputFiles.stream() .anyMatch(file -> file.getName().matches("changes-\\d+-1.log"))); Assert.assertTrue(outputFiles.stream() .anyMatch(file -> file.getName().matches("subtractions-\\d+-1.log"))); temp.deleteRecursively(); }
@Test public void fileCreationFromFileTest() { final File temp = File.temporaryFolder(); // Run AtlasJoinerSubCommand final String[] args = { "geojson-diff", String.format("-source=%s", GEO_11), String.format("-target=%s", GEO_21), String.format("-output=%s", temp.getPath()) }; new AtlasChecksCommand(args).runWithoutQuitting(args); final List<File> outputFiles = temp.listFilesRecursively(); Assert.assertTrue(outputFiles.stream() .anyMatch(file -> file.getName().matches("additions-\\d+-1.geojson"))); Assert.assertTrue(outputFiles.stream() .anyMatch(file -> file.getName().matches("changes-\\d+-1.geojson"))); Assert.assertTrue(outputFiles.stream() .anyMatch(file -> file.getName().matches("subtractions-\\d+-1.geojson"))); temp.deleteRecursively(); }
@Test public void fileCreationFromDirectoryTest() { final File temp = File.temporaryFolder(); // Run AtlasJoinerSubCommand final String[] args = { "geojson-diff", String.format("-source=%s", SOURCE_DIRECTORY), String.format("-target=%s", TARGET_DIRECTORY), String.format("-output=%s", temp.getPath()) }; new AtlasChecksCommand(args).runWithoutQuitting(args); final List<File> outputFiles = temp.listFilesRecursively(); Assert.assertTrue(outputFiles.stream() .anyMatch(file -> file.getName().matches("additions-\\d+-1.geojson"))); Assert.assertTrue(outputFiles.stream() .anyMatch(file -> file.getName().matches("changes-\\d+-2.geojson"))); Assert.assertTrue(outputFiles.stream() .anyMatch(file -> file.getName().matches("subtractions-\\d+-3.geojson"))); temp.deleteRecursively(); } }
@Test public void fileCreationFromDirectoryTest() { final File temp = File.temporaryFolder(); // Run AtlasJoinerSubCommand final String[] args = { "log-diff", String.format("-source=%s", SOURCE_DIRECTORY), String.format("-target=%s", TARGET_DIRECTORY), String.format("-output=%s", temp.getPath()) }; new AtlasChecksCommand(args).runWithoutQuitting(args); final List<File> outputFiles = temp.listFilesRecursively(); Assert.assertTrue(outputFiles.stream() .anyMatch(file -> file.getName().matches("additions-\\d+-1.log"))); Assert.assertTrue(outputFiles.stream() .anyMatch(file -> file.getName().matches("changes-\\d+-2.log"))); Assert.assertTrue(outputFiles.stream() .anyMatch(file -> file.getName().matches("subtractions-\\d+-3.log"))); temp.deleteRecursively(); } }
@Test public void testJoinedOutput() { final File temp = File.temporary(); // Run AtlasJoinerSubCommand final String[] args = { "join", String.format("-input=%1$s", SHARD_PATH), String.format("-output=%1$s", temp.getPath()) }; new AtlasReader(args).runWithoutQuitting(args); Assert.assertTrue(temp.length() > 0); temp.delete(); } }