-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
340 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/test/java/com/github/lusoalex/ChainrTestJsonArray.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.github.lusoalex; | ||
|
||
import com.github.lusoalex.chainr.ChainrBuilder; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.json.JsonArray; | ||
import io.vertx.core.json.JsonObject; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* These tests only aim to validate our entry point to jolt. | ||
* JOLT functions are/should be tested into the core project : https://github.com/bazaarvoice/jolt | ||
*/ | ||
public class ChainrTestJsonArray { | ||
|
||
final static private String RESSOURCE_PATH = "src/test/resources/json/defaultr/json/array/"; | ||
|
||
@Test | ||
public void testTransformWithFullSpecs() throws IOException { | ||
JsonObject jsonTest = Vertx.vertx().fileSystem().readFileBlocking(RESSOURCE_PATH+"simpleTestCaseOne.json").toJsonObject(); | ||
|
||
JsonObject input = jsonTest.getJsonObject("input"); | ||
JsonArray specs = jsonTest.getJsonArray("specs"); | ||
JsonArray expected = jsonTest.getJsonArray("expected"); | ||
|
||
Chainr chainr = new ChainrBuilder(specs).build(); | ||
JsonArray result = chainr.transformToJsonArray(input); | ||
|
||
Assert.assertTrue("Jolt mapping result not as expected.", expected.equals(result)); | ||
} | ||
|
||
@Test | ||
public void splitUsingOnlyFirstSpecs() throws IOException { | ||
JsonObject jsonTest = Vertx.vertx().fileSystem().readFileBlocking(RESSOURCE_PATH+"splitTestCaseOne.json").toJsonObject(); | ||
|
||
JsonObject input = jsonTest.getJsonObject("input"); | ||
JsonArray specs = jsonTest.getJsonArray("specs"); | ||
JsonArray expected = jsonTest.getJsonArray("expected"); | ||
|
||
Chainr chainr = new ChainrBuilder(specs).build(); | ||
JsonArray result = chainr.transformToJsonArray(1,input); | ||
|
||
Assert.assertTrue("Jolt mapping result not as expected.", expected.equals(result)); | ||
} | ||
|
||
@Test | ||
public void splitUsingOnlySecondSpecs() throws IOException { | ||
JsonObject jsonTest = Vertx.vertx().fileSystem().readFileBlocking(RESSOURCE_PATH+"splitTestCaseTwo.json").toJsonObject(); | ||
|
||
JsonObject input = jsonTest.getJsonObject("input"); | ||
JsonArray specs = jsonTest.getJsonArray("specs"); | ||
JsonArray expected = jsonTest.getJsonArray("expected"); | ||
|
||
Chainr chainr = new ChainrBuilder(specs).build(); | ||
JsonArray result = chainr.transformToJsonArray(0,2,input); | ||
|
||
Assert.assertTrue("Jolt mapping result not as expected.", expected.equals(result)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/test/resources/json/defaultr/json/array/simpleTestCaseOne.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{ | ||
"input": { | ||
"content": [ | ||
{ | ||
"name": "Elysee", | ||
"country": "FRANCE", | ||
"address": "Avenue des Champs-Élysées", | ||
"city": "PARIS", | ||
"stores_id": 1, | ||
"zip_code": "75000", | ||
"gps_x": "48.869729", | ||
"gps_y": "2.307784", | ||
"phone_number": "+33 1 00 00 00 00", | ||
"backend_url": "https://north-europe.company.com/" | ||
}, | ||
{ | ||
"name": "Belem", | ||
"country": "PORTUGAL", | ||
"address": "Avenida Brasilia", | ||
"city": "LISBON", | ||
"stores_id": 2, | ||
"zip_code": "75000", | ||
"gps_x": "38.693060", | ||
"gps_y": "-9.218120", | ||
"phone_number": "+351 000 000 000", | ||
"backend_url": "https://south-europe.company.com/" | ||
}, | ||
{ | ||
"name": "Yu garden", | ||
"country": "CHINA", | ||
"address": "huanpu qu", | ||
"city": "Shanghai", | ||
"stores_id": 3, | ||
"zip_code": "XXXX", | ||
"gps_x": "31.227208", | ||
"gps_y": "121.491836", | ||
"phone_number": "+86 000 000 000", | ||
"backend_url": "https://south-asia.company.com/" | ||
} | ||
] | ||
}, | ||
"specs": [ | ||
{ | ||
"operation": "shift", | ||
"spec": { | ||
"content": { | ||
"*": { | ||
"stores_id": "[&1].key", | ||
"backend_url": "[&1].value", | ||
"country": "[&1].country" | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"operation": "remove", | ||
"spec": { | ||
"*": { | ||
"country": "" | ||
} | ||
} | ||
} | ||
] | ||
, | ||
"expected": [ { | ||
"key" : 1, | ||
"value" : "https://north-europe.company.com/" | ||
}, { | ||
"key" : 2, | ||
"value" : "https://south-europe.company.com/" | ||
}, { | ||
"key" : 3, | ||
"value" : "https://south-asia.company.com/" | ||
} ] | ||
} |
78 changes: 78 additions & 0 deletions
78
src/test/resources/json/defaultr/json/array/splitTestCaseOne.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
{ | ||
"input": { | ||
"content": [ | ||
{ | ||
"name": "Elysee", | ||
"country": "FRANCE", | ||
"address": "Avenue des Champs-Élysées", | ||
"city": "PARIS", | ||
"stores_id": 1, | ||
"zip_code": "75000", | ||
"gps_x": "48.869729", | ||
"gps_y": "2.307784", | ||
"phone_number": "+33 1 00 00 00 00", | ||
"backend_url": "https://north-europe.company.com/" | ||
}, | ||
{ | ||
"name": "Belem", | ||
"country": "PORTUGAL", | ||
"address": "Avenida Brasilia", | ||
"city": "LISBON", | ||
"stores_id": 2, | ||
"zip_code": "75000", | ||
"gps_x": "38.693060", | ||
"gps_y": "-9.218120", | ||
"phone_number": "+351 000 000 000", | ||
"backend_url": "https://south-europe.company.com/" | ||
}, | ||
{ | ||
"name": "Yu garden", | ||
"country": "CHINA", | ||
"address": "huanpu qu", | ||
"city": "Shanghai", | ||
"stores_id": 3, | ||
"zip_code": "XXXX", | ||
"gps_x": "31.227208", | ||
"gps_y": "121.491836", | ||
"phone_number": "+86 000 000 000", | ||
"backend_url": "https://south-asia.company.com/" | ||
} | ||
] | ||
}, | ||
"specs": [ | ||
{ | ||
"operation": "shift", | ||
"spec": { | ||
"content": { | ||
"*": { | ||
"stores_id": "[&1].key", | ||
"backend_url": "[&1].value", | ||
"country": "[&1].country" | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"operation": "remove", | ||
"spec": { | ||
"*": { | ||
"country": "" | ||
} | ||
} | ||
} | ||
] | ||
, | ||
"expected": [ { | ||
"country" : "FRANCE", | ||
"key" : 1, | ||
"value" : "https://north-europe.company.com/" | ||
}, { | ||
"country" : "PORTUGAL", | ||
"key" : 2, | ||
"value" : "https://south-europe.company.com/" | ||
}, { | ||
"country" : "CHINA", | ||
"key" : 3, | ||
"value" : "https://south-asia.company.com/" | ||
} ] | ||
} |
Oops, something went wrong.