Skip to content

Commit

Permalink
Merge pull request #4 from caffinc/development
Browse files Browse the repository at this point in the history
Splitting jaggr into main and util projects
  • Loading branch information
SriramKeerthi authored Nov 27, 2016
2 parents b62789c + a08013f commit 3338400
Show file tree
Hide file tree
Showing 31 changed files with 265 additions and 49 deletions.
84 changes: 84 additions & 0 deletions jaggr/jaggr-utils/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>jaggr-parent</artifactId>
<groupId>com.caffinc</groupId>
<version>0.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>jaggr-utils</artifactId>
<name>jaggr Utils</name>
<description>Utilities for jaggr</description>
<url>https://github.com/caffinc/jaggr</url>

<developers>
<developer>
<name>Caffinc</name>
<email>admin@caffinc.com</email>
<organization>Caffinc</organization>
<organizationUrl>http://www.caffinc.com</organizationUrl>
</developer>
</developers>

<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>

<scm>
<url>https://github.com/caffinc/jaggr</url>
</scm>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson-version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.caffinc.jaggr.core.utils;
package com.caffinc.jaggr.utils;

import com.google.gson.Gson;

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> 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<Map<String, Object>> expectedData = new ArrayList<>();
try (BufferedWriter br = new BufferedWriter(new FileWriter(tempFilePath.toFile()))
) {
for (int i = 0; i < 10; i++) {
Map<String, Object> json = new HashMap<>();
json.put("_id", (double) i);
json.put("val", RANDOM.nextDouble());
expectedData.add(json);
br.write(GSON.toJson(json) + "\n");
}
}
List<Map<String, Object>> 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<Map<String, Object>> result = JsonFileReader.readJsonFromResource("raw.json");
Assert.assertEquals("There must be ten lines in the file", 10, result.size());
for (Map<String, Object> obj : result) {
Assert.assertEquals("There must be 9 elements in the object", 9, obj.size());
}
}
}
10 changes: 10 additions & 0 deletions jaggr/jaggr-utils/src/test/resources/raw.json
Original file line number Diff line number Diff line change
@@ -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}
84 changes: 84 additions & 0 deletions jaggr/jaggr/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>jaggr-parent</artifactId>
<groupId>com.caffinc</groupId>
<version>0.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>jaggr</artifactId>
<name>jaggr</name>
<description>Simple JSON Aggregator for Java</description>
<url>https://github.com/caffinc/jaggr</url>

<developers>
<developer>
<name>Caffinc</name>
<email>admin@caffinc.com</email>
<organization>Caffinc</organization>
<organizationUrl>http://www.caffinc.com</organizationUrl>
</developer>
</developers>

<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>

<scm>
<url>https://github.com/caffinc/jaggr</url>
</scm>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>jaggr-utils</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
56 changes: 9 additions & 47 deletions jaggr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.caffinc</groupId>
<artifactId>jaggr</artifactId>
<version>0.2</version>
<name>jaggr</name>
<artifactId>jaggr-parent</artifactId>
<packaging>pom</packaging>
<version>0.2.2</version>
<modules>
<module>jaggr-utils</module>
<module>jaggr</module>
</modules>
<name>jaggr Parent</name>
<description>Simple JSON Aggregator for Java</description>
<url>https://github.com/caffinc/jaggr</url>

Expand All @@ -32,56 +37,13 @@
<url>https://github.com/caffinc/jaggr</url>
</scm>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<junit-version>4.12</junit-version>
<gson-version>2.6.2</gson-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson-version}</version>
</dependency>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down

0 comments on commit 3338400

Please sign in to comment.