Java Code Examples for com.bazaarvoice.jolt.JsonUtils#classpathToObject()

The following examples show how to use com.bazaarvoice.jolt.JsonUtils#classpathToObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JoltUtilsTest.java    From jolt with Apache License 2.0 6 votes vote down vote up
@DataProvider
public Iterator<Object[]> storeTestCases() {

    String testFixture = "/json/utils/joltUtils-store-remove-compact.json";
    @SuppressWarnings("unchecked")
    List<Map<String, Object>> tests = (List<Map<String, Object>>) JsonUtils.classpathToObject( testFixture );

    List<Object[]> testCases = new LinkedList<>();

    for(Map<String, Object> testCase: tests) {
        testCases.add(new Object[] {
                testCase.get("description"),
                testCase.get("source"),
                ((List)testCase.get("path")).toArray(),
                testCase.get("value"),
                testCase.get("output")
        });
    }

    return testCases.iterator();
}
 
Example 2
Source File: JoltUtilsRemoveTest.java    From jolt with Apache License 2.0 6 votes vote down vote up
@Test
public void runFixtureTests() {

    String testFixture = "/json/utils/joltUtils-removeRecursive.json";
    @SuppressWarnings("unchecked")
    List<Map<String, Object>> tests = (List<Map<String, Object>>) JsonUtils.classpathToObject( testFixture );

    for ( Map<String,Object> testUnit : tests ) {

        Object data = testUnit.get( "input" );
        String toRemove = (String) testUnit.get( "remove" );
        Object expected = testUnit.get( "expected" );

        JoltUtils.removeRecursive( data, toRemove );

        Diffy.Result result = diffy.diff( expected, data );
        if (!result.isEmpty()) {
            Assert.fail( "Failed.\nhere is a diff:\nexpected: " + JsonUtils.toJsonString(result.expected) + "\n  actual: " + JsonUtils.toJsonString(result.actual));
        }
    }
}
 
Example 3
Source File: DeepCopyTest.java    From jolt with Apache License 2.0 6 votes vote down vote up
@Test
public void deepCopyTest() throws Exception {

    Object input = JsonUtils.classpathToObject( "/json/deepcopy/original.json" );

    Map<String, Object> fiddle = (Map<String, Object>) DeepCopy.simpleDeepCopy( input );

    JoltTestUtil.runDiffy( "Verify that the DeepCopy did in fact make a copy.", input, fiddle );

    // The test is to make a deep copy, then manipulate the copy, and verify that the original did not change  ;)
    // copy and fiddle
    List array = (List) fiddle.get( "array" );
    array.add( "c" );
    array.set( 1, 3 );
    Map<String,Object> subMap = (Map<String,Object>) fiddle.get( "map" );
    subMap.put("c", "c");
    subMap.put("b", 3 );

    // Verify that the input to the copy was unmodified
    Object unmodified = JsonUtils.classpathToObject( "/json/deepcopy/original.json" );
    JoltTestUtil.runDiffy( "Verify that the deepcopy was actually deep / input is unmodified", unmodified, input );

    // Verify we made the modifications we wanted to.
    Object expectedModified = JsonUtils.classpathToObject( "/json/deepcopy/modifed.json" );
    JoltTestUtil.runDiffy( "Verify fiddled post deepcopy object looks correct / was modifed.", expectedModified, fiddle );
}
 
Example 4
Source File: ChainrSpecFormatTest.java    From jolt with Apache License 2.0 5 votes vote down vote up
@DataProvider
public Object[][] badFormatSpecs() throws IOException {
    return new Object[][] {
            {JsonUtils.classpathToObject( "/json/chainr/specformat/bad_spec_arrayClassName.json" )},
            {JsonUtils.classpathToObject( "/json/chainr/specformat/bad_spec_ClassName.json" )},
            {JsonUtils.classpathToObject( "/json/chainr/specformat/bad_spec_NonTransformClass.json" )},
            {JsonUtils.classpathToObject( "/json/chainr/specformat/bad_spec_empty.json" )}
    };
}
 
Example 5
Source File: ChainrIncrementTest.java    From jolt with Apache License 2.0 5 votes vote down vote up
@DataProvider
public Object[][] fromToTests() {

    Object chainrSpec = JsonUtils.classpathToObject( "/json/chainr/increments/spec.json" );

    return new Object[][] {
        {chainrSpec, 0, 1},
        {chainrSpec, 0, 3},
        {chainrSpec, 1, 3},
        {chainrSpec, 1, 4}
    };
}
 
Example 6
Source File: ChainrIncrementTest.java    From jolt with Apache License 2.0 5 votes vote down vote up
@DataProvider
public Object[][] toTests() {

    Object chainrSpec = JsonUtils.classpathToObject(  "/json/chainr/increments/spec.json" );

    return new Object[][] {
            {chainrSpec, 1},
            {chainrSpec, 3}
    };
}
 
Example 7
Source File: ChainrIncrementTest.java    From jolt with Apache License 2.0 5 votes vote down vote up
@DataProvider
public Object[][] failTests() {

    Object chainrSpec = JsonUtils.classpathToObject( "/json/chainr/increments/spec.json" );

    return new Object[][] {
            {chainrSpec, 0, 0},
            {chainrSpec, -2, 2},
            {chainrSpec, 0, -2},
            {chainrSpec, 1, 10000}
    };
}
 
Example 8
Source File: ChainrInitializationTest.java    From jolt with Apache License 2.0 4 votes vote down vote up
@DataProvider
public Object[][] badTransforms() {
    return new Object[][] {
        {JsonUtils.classpathToObject(  "/json/chainr/transforms/bad_transform_loadsExplodingTransform.json" )}
    };
}
 
Example 9
Source File: ChainrInitializationTest.java    From jolt with Apache License 2.0 4 votes vote down vote up
@DataProvider
public Object[][] passingTestCases() {
    return new Object[][] {
        {new Object(), JsonUtils.classpathToObject( "/json/chainr/transforms/loadsGoodTransform.json" )}
    };
}
 
Example 10
Source File: ChainrInitializationTest.java    From jolt with Apache License 2.0 4 votes vote down vote up
@Test( expectedExceptions = IllegalArgumentException.class )
public void chainrBuilderFailsOnNullLoader() {

    Object validSpec = JsonUtils.classpathToObject( "/json/chainr/transforms/loadsGoodTransform.json" );
    new ChainrBuilder( validSpec ).loader( null );
}
 
Example 11
Source File: ChainrSpecLoadingTest.java    From jolt with Apache License 2.0 4 votes vote down vote up
@DataProvider
public Object[][] badFormatSpecs() throws IOException {
    return new Object[][] {
            {JsonUtils.classpathToObject( "/json/chainr/specloading/bad_spec_SpecTransform.json" )}
    };
}
 
Example 12
Source File: ChainrIncrementTest.java    From jolt with Apache License 2.0 3 votes vote down vote up
@Test( dataProvider = "fromToTests")
public void testChainrIncrementsFromTo( Object chainrSpec, int start, int end ) throws IOException {
    Chainr chainr = Chainr.fromSpec( chainrSpec );

    Object expected = JsonUtils.classpathToObject( "/json/chainr/increments/" + start + "-" + end + ".json" );

    Object actual = chainr.transform( start, end, new HashMap() );

    JoltTestUtil.runDiffy( "failed incremental From-To Chainr", expected, actual );
}
 
Example 13
Source File: ChainrIncrementTest.java    From jolt with Apache License 2.0 3 votes vote down vote up
@Test( dataProvider = "toTests")
public void testChainrIncrementsTo( Object chainrSpec, int end  ) throws IOException {

    Chainr chainr = Chainr.fromSpec( chainrSpec );

    Object expected = JsonUtils.classpathToObject( "/json/chainr/increments/0-" + end + ".json" );

    Object actual = chainr.transform( end, new HashMap() );

    JoltTestUtil.runDiffy( "failed incremental To Chainr", expected, actual );
}
 
Example 14
Source File: JoltSample.java    From jolt with Apache License 2.0 3 votes vote down vote up
public static void main(String[] args) {

        List chainrSpecJSON = JsonUtils.classpathToList( "/json/sample/spec.json" );
        Chainr chainr = Chainr.fromSpec( chainrSpecJSON );

        Object inputJSON = JsonUtils.classpathToObject( "/json/sample/input.json" );

        Object transformedOutput = chainr.transform( inputJSON );
        System.out.println( JsonUtils.toJsonString( transformedOutput ) );
    }