diff --git a/jaggr/jaggr-utils/pom.xml b/jaggr/jaggr-utils/pom.xml new file mode 100644 index 0000000..4287100 --- /dev/null +++ b/jaggr/jaggr-utils/pom.xml @@ -0,0 +1,84 @@ + + + + jaggr-parent + com.caffinc + 0.2.2 + + 4.0.0 + + jaggr-utils + jaggr Utils + Utilities for jaggr + https://github.com/caffinc/jaggr + + + + Caffinc + admin@caffinc.com + Caffinc + http://www.caffinc.com + + + + + + MIT License + http://www.opensource.org/licenses/mit-license.php + repo + + + + + https://github.com/caffinc/jaggr + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + + + + + + + com.google.code.gson + gson + ${gson-version} + + + \ No newline at end of file diff --git a/jaggr/src/main/java/com/caffinc/jaggr/core/utils/JsonFileReader.java b/jaggr/jaggr-utils/src/main/java/com/caffinc/jaggr/utils/JsonFileReader.java similarity index 98% rename from jaggr/src/main/java/com/caffinc/jaggr/core/utils/JsonFileReader.java rename to jaggr/jaggr-utils/src/main/java/com/caffinc/jaggr/utils/JsonFileReader.java index fc5ac22..76e75af 100644 --- a/jaggr/src/main/java/com/caffinc/jaggr/core/utils/JsonFileReader.java +++ b/jaggr/jaggr-utils/src/main/java/com/caffinc/jaggr/utils/JsonFileReader.java @@ -1,4 +1,4 @@ -package com.caffinc.jaggr.core.utils; +package com.caffinc.jaggr.utils; import com.google.gson.Gson; diff --git a/jaggr/jaggr-utils/src/test/java/com/caffinc/jaggr/utils/JsonFileReaderTest.java b/jaggr/jaggr-utils/src/test/java/com/caffinc/jaggr/utils/JsonFileReaderTest.java new file mode 100644 index 0000000..acba751 --- /dev/null +++ b/jaggr/jaggr-utils/src/test/java/com/caffinc/jaggr/utils/JsonFileReaderTest.java @@ -0,0 +1,76 @@ +package com.caffinc.jaggr.utils; + +import com.google.gson.Gson; +import org.junit.Assert; +import org.junit.Test; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.*; + +/** + * Tests the JsonFileReader utility + * + * @author Sriram + * @since 11/27/2016 + */ +public class JsonFileReaderTest { + private static final String TEMP_DIR = System.getProperty("java.io.tmpdir"); + private static final Random RANDOM = new Random(); + private static final Gson GSON = new Gson(); + + @Test + public void testGetFileLines() throws Exception { + Path tempFilePath = Paths.get(TEMP_DIR, "jsontest" + RANDOM.nextInt() + ".json"); + try { + List lines; + try (BufferedWriter br = new BufferedWriter(new FileWriter(tempFilePath.toFile())) + ) { + for (int i = 0; i < 10; i++) + br.write(i + "\n"); + } + lines = JsonFileReader.getFileLines(tempFilePath.toString()); + for (int i = 0; i < 10; i++) { + Assert.assertEquals("Value should match value written to file", String.valueOf(i), lines.get(i)); + } + } finally { + Files.delete(tempFilePath); + } + } + + @Test + public void testReadJsonFromFile() throws Exception { + Path tempFilePath = Paths.get(TEMP_DIR, "jsontest" + RANDOM.nextInt() + ".json"); + try { + List> expectedData = new ArrayList<>(); + try (BufferedWriter br = new BufferedWriter(new FileWriter(tempFilePath.toFile())) + ) { + for (int i = 0; i < 10; i++) { + Map json = new HashMap<>(); + json.put("_id", (double) i); + json.put("val", RANDOM.nextDouble()); + expectedData.add(json); + br.write(GSON.toJson(json) + "\n"); + } + } + List> jsonLines = JsonFileReader.readJsonFromFile(tempFilePath.toString()); + for (int i = 0; i < 10; i++) { + Assert.assertEquals("Value should match value written to file", expectedData.get(i), jsonLines.get(i)); + } + } finally { + Files.delete(tempFilePath); + } + } + + @Test + public void testReadJsonFromResource() throws Exception { + List> result = JsonFileReader.readJsonFromResource("raw.json"); + Assert.assertEquals("There must be ten lines in the file", 10, result.size()); + for (Map obj : result) { + Assert.assertEquals("There must be 9 elements in the object", 9, obj.size()); + } + } +} diff --git a/jaggr/jaggr-utils/src/test/resources/raw.json b/jaggr/jaggr-utils/src/test/resources/raw.json new file mode 100644 index 0000000..14b5999 --- /dev/null +++ b/jaggr/jaggr-utils/src/test/resources/raw.json @@ -0,0 +1,10 @@ +{"index":1,"index_start_at":56,"integer":25,"float":14.0942,"name":"Mitchell","surname":"Archer","fullname":"Dennis Sherrill","email":"rita@bowman.lc","bool":false} +{"index":2,"index_start_at":57,"integer":33,"float":13.9546,"name":"Miriam","surname":"Stanton","fullname":"Meredith Watson","email":"lisa@livingston.es","bool":false} +{"index":3,"index_start_at":58,"integer":27,"float":18.8563,"name":"Leo","surname":"Robinson","fullname":"Brent Albright","email":"richard@richardson.do","bool":false} +{"index":4,"index_start_at":59,"integer":14,"float":14.914,"name":"Dianne","surname":"Middleton","fullname":"Alex Gay","email":"melinda@glover.az","bool":false} +{"index":5,"index_start_at":60,"integer":36,"float":13.7685,"name":"Dan","surname":"Kirk","fullname":"Anna Bradley","email":"alice@christensen.cr","bool":true} +{"index":6,"index_start_at":61,"integer":8,"float":18.4737,"name":"Natalie","surname":"Lassiter","fullname":"Karl Cassidy","email":"jonathan@gray.vu","bool":true} +{"index":7,"index_start_at":62,"integer":24,"float":15.9886,"name":"Eileen","surname":"Bunn","fullname":"Shannon Hendrix","email":"luis@king.cx","bool":true} +{"index":8,"index_start_at":63,"integer":15,"float":14.8193,"name":"Clifford","surname":"Schwartz","fullname":"Sara Gilbert","email":"judith@hunt.et","bool":false} +{"index":9,"index_start_at":64,"integer":33,"float":14.2817,"name":"Florence","surname":"Washington","fullname":"Thomas Casey","email":"vivian@caldwell.hn","bool":false} +{"index":10,"index_start_at":65,"integer":10,"float":17.4529,"name":"Ellen","surname":"Haynes","fullname":"Lee Denton","email":"scott@wrenn.uy","bool":true} diff --git a/jaggr/jaggr/pom.xml b/jaggr/jaggr/pom.xml new file mode 100644 index 0000000..87ec8b4 --- /dev/null +++ b/jaggr/jaggr/pom.xml @@ -0,0 +1,84 @@ + + + + jaggr-parent + com.caffinc + 0.2.2 + + 4.0.0 + + jaggr + jaggr + Simple JSON Aggregator for Java + https://github.com/caffinc/jaggr + + + + Caffinc + admin@caffinc.com + Caffinc + http://www.caffinc.com + + + + + + MIT License + http://www.opensource.org/licenses/mit-license.php + repo + + + + + https://github.com/caffinc/jaggr + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + + + + + + ${project.parent.groupId} + jaggr-utils + ${project.parent.version} + test + + + \ No newline at end of file diff --git a/jaggr/src/main/java/com/caffinc/jaggr/core/Aggregation.java b/jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/Aggregation.java similarity index 100% rename from jaggr/src/main/java/com/caffinc/jaggr/core/Aggregation.java rename to jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/Aggregation.java diff --git a/jaggr/src/main/java/com/caffinc/jaggr/core/AggregationBuilder.java b/jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/AggregationBuilder.java similarity index 100% rename from jaggr/src/main/java/com/caffinc/jaggr/core/AggregationBuilder.java rename to jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/AggregationBuilder.java diff --git a/jaggr/src/main/java/com/caffinc/jaggr/core/entities/Tuple2.java b/jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/entities/Tuple2.java similarity index 100% rename from jaggr/src/main/java/com/caffinc/jaggr/core/entities/Tuple2.java rename to jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/entities/Tuple2.java diff --git a/jaggr/src/main/java/com/caffinc/jaggr/core/operations/AverageOperation.java b/jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/operations/AverageOperation.java similarity index 100% rename from jaggr/src/main/java/com/caffinc/jaggr/core/operations/AverageOperation.java rename to jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/operations/AverageOperation.java diff --git a/jaggr/src/main/java/com/caffinc/jaggr/core/operations/CollectOperation.java b/jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/operations/CollectOperation.java similarity index 100% rename from jaggr/src/main/java/com/caffinc/jaggr/core/operations/CollectOperation.java rename to jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/operations/CollectOperation.java diff --git a/jaggr/src/main/java/com/caffinc/jaggr/core/operations/CollectSetOperation.java b/jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/operations/CollectSetOperation.java similarity index 100% rename from jaggr/src/main/java/com/caffinc/jaggr/core/operations/CollectSetOperation.java rename to jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/operations/CollectSetOperation.java diff --git a/jaggr/src/main/java/com/caffinc/jaggr/core/operations/CountOperation.java b/jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/operations/CountOperation.java similarity index 100% rename from jaggr/src/main/java/com/caffinc/jaggr/core/operations/CountOperation.java rename to jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/operations/CountOperation.java diff --git a/jaggr/src/main/java/com/caffinc/jaggr/core/operations/MaxOperation.java b/jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/operations/MaxOperation.java similarity index 100% rename from jaggr/src/main/java/com/caffinc/jaggr/core/operations/MaxOperation.java rename to jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/operations/MaxOperation.java diff --git a/jaggr/src/main/java/com/caffinc/jaggr/core/operations/MinOperation.java b/jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/operations/MinOperation.java similarity index 100% rename from jaggr/src/main/java/com/caffinc/jaggr/core/operations/MinOperation.java rename to jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/operations/MinOperation.java diff --git a/jaggr/src/main/java/com/caffinc/jaggr/core/operations/Operation.java b/jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/operations/Operation.java similarity index 100% rename from jaggr/src/main/java/com/caffinc/jaggr/core/operations/Operation.java rename to jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/operations/Operation.java diff --git a/jaggr/src/main/java/com/caffinc/jaggr/core/operations/SumOperation.java b/jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/operations/SumOperation.java similarity index 100% rename from jaggr/src/main/java/com/caffinc/jaggr/core/operations/SumOperation.java rename to jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/operations/SumOperation.java diff --git a/jaggr/src/main/java/com/caffinc/jaggr/core/utils/FieldValueExtractor.java b/jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/utils/FieldValueExtractor.java similarity index 100% rename from jaggr/src/main/java/com/caffinc/jaggr/core/utils/FieldValueExtractor.java rename to jaggr/jaggr/src/main/java/com/caffinc/jaggr/core/utils/FieldValueExtractor.java diff --git a/jaggr/src/test/java/com/caffinc/jaggr/core/AggregationBuilderTest.java b/jaggr/jaggr/src/test/java/com/caffinc/jaggr/core/AggregationBuilderTest.java similarity index 99% rename from jaggr/src/test/java/com/caffinc/jaggr/core/AggregationBuilderTest.java rename to jaggr/jaggr/src/test/java/com/caffinc/jaggr/core/AggregationBuilderTest.java index 42d8052..df3781e 100644 --- a/jaggr/src/test/java/com/caffinc/jaggr/core/AggregationBuilderTest.java +++ b/jaggr/jaggr/src/test/java/com/caffinc/jaggr/core/AggregationBuilderTest.java @@ -2,7 +2,7 @@ import com.caffinc.jaggr.core.operations.*; import com.caffinc.jaggr.core.utils.FieldValueExtractor; -import com.caffinc.jaggr.core.utils.JsonFileReader; +import com.caffinc.jaggr.utils.JsonFileReader; import com.google.gson.Gson; import org.junit.BeforeClass; import org.junit.Test; diff --git a/jaggr/src/test/java/com/caffinc/jaggr/core/utils/FieldValueExtractorTest.java b/jaggr/jaggr/src/test/java/com/caffinc/jaggr/core/utils/FieldValueExtractorTest.java similarity index 100% rename from jaggr/src/test/java/com/caffinc/jaggr/core/utils/FieldValueExtractorTest.java rename to jaggr/jaggr/src/test/java/com/caffinc/jaggr/core/utils/FieldValueExtractorTest.java diff --git a/jaggr/src/test/resources/avgResult.json b/jaggr/jaggr/src/test/resources/avgResult.json similarity index 100% rename from jaggr/src/test/resources/avgResult.json rename to jaggr/jaggr/src/test/resources/avgResult.json diff --git a/jaggr/src/test/resources/collectResult.json b/jaggr/jaggr/src/test/resources/collectResult.json similarity index 100% rename from jaggr/src/test/resources/collectResult.json rename to jaggr/jaggr/src/test/resources/collectResult.json diff --git a/jaggr/src/test/resources/collectSetResult.json b/jaggr/jaggr/src/test/resources/collectSetResult.json similarity index 100% rename from jaggr/src/test/resources/collectSetResult.json rename to jaggr/jaggr/src/test/resources/collectSetResult.json diff --git a/jaggr/src/test/resources/collectStringsResult.json b/jaggr/jaggr/src/test/resources/collectStringsResult.json similarity index 100% rename from jaggr/src/test/resources/collectStringsResult.json rename to jaggr/jaggr/src/test/resources/collectStringsResult.json diff --git a/jaggr/src/test/resources/countResult.json b/jaggr/jaggr/src/test/resources/countResult.json similarity index 100% rename from jaggr/src/test/resources/countResult.json rename to jaggr/jaggr/src/test/resources/countResult.json diff --git a/jaggr/src/test/resources/grouplessResult.json b/jaggr/jaggr/src/test/resources/grouplessResult.json similarity index 100% rename from jaggr/src/test/resources/grouplessResult.json rename to jaggr/jaggr/src/test/resources/grouplessResult.json diff --git a/jaggr/src/test/resources/maxResult.json b/jaggr/jaggr/src/test/resources/maxResult.json similarity index 100% rename from jaggr/src/test/resources/maxResult.json rename to jaggr/jaggr/src/test/resources/maxResult.json diff --git a/jaggr/src/test/resources/minResult.json b/jaggr/jaggr/src/test/resources/minResult.json similarity index 100% rename from jaggr/src/test/resources/minResult.json rename to jaggr/jaggr/src/test/resources/minResult.json diff --git a/jaggr/src/test/resources/multiResult.json b/jaggr/jaggr/src/test/resources/multiResult.json similarity index 100% rename from jaggr/src/test/resources/multiResult.json rename to jaggr/jaggr/src/test/resources/multiResult.json diff --git a/jaggr/src/test/resources/raw.json b/jaggr/jaggr/src/test/resources/raw.json similarity index 100% rename from jaggr/src/test/resources/raw.json rename to jaggr/jaggr/src/test/resources/raw.json diff --git a/jaggr/src/test/resources/sumResult.json b/jaggr/jaggr/src/test/resources/sumResult.json similarity index 100% rename from jaggr/src/test/resources/sumResult.json rename to jaggr/jaggr/src/test/resources/sumResult.json diff --git a/jaggr/pom.xml b/jaggr/pom.xml index 2f258fd..109c0c0 100644 --- a/jaggr/pom.xml +++ b/jaggr/pom.xml @@ -5,9 +5,14 @@ 4.0.0 com.caffinc - jaggr - 0.2 - jaggr + jaggr-parent + pom + 0.2.2 + + jaggr-utils + jaggr + + jaggr Parent Simple JSON Aggregator for Java https://github.com/caffinc/jaggr @@ -32,56 +37,13 @@ https://github.com/caffinc/jaggr - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.3 - - 1.7 - 1.7 - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadocs - - jar - - - - - - 4.12 2.6.2 UTF-8 - - - com.google.code.gson - gson - ${gson-version} - + junit junit