Java Code Examples for com.bazaarvoice.jolt.JsonUtils#jsonToMap()
The following examples show how to use
com.bazaarvoice.jolt.JsonUtils#jsonToMap() .
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: SimpleTraversalTest.java From jolt with Apache License 2.0 | 6 votes |
@Test public void testAutoArray() throws IOException { SimpleTraversal<String> traversal = SimpleTraversal.newTraversal( "a.[].b" ); Object expected = JsonUtils.jsonToMap( "{ \"a\" : [ { \"b\" : \"one\" }, { \"b\" : \"two\" } ] }" ); Object actual = new HashMap(); Assert.assertFalse( traversal.get( actual ).isPresent() ); Assert.assertEquals( 0, ((HashMap) actual).size() ); // get didn't add anything // Add two things and validate the Auto Expand array Assert.assertEquals( "one", traversal.set( actual, "one" ).get() ); Assert.assertEquals( "two", traversal.set( actual, "two" ).get() ); JoltTestUtil.runDiffy( expected, actual ); }
Example 2
Source File: SimpleTraversalTest.java From jolt with Apache License 2.0 | 6 votes |
@Test public void testOverwrite() throws IOException { SimpleTraversal<String> traversal = SimpleTraversal.newTraversal( "a.b" ); Object actual = JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : \"tuna\" } }" ); Object expectedOne = JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : \"one\" } }" ); Object expectedTwo = JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : \"two\" } }" ); Assert.assertEquals( "tuna", traversal.get( actual ).get() ); // Set twice and verify that the sets did in fact overwrite Assert.assertEquals( "one", traversal.set( actual, "one" ).get() ); JoltTestUtil.runDiffy( expectedOne, actual ); Assert.assertEquals( "two", traversal.set( actual, "two" ).get() ); JoltTestUtil.runDiffy( expectedTwo, actual ); }
Example 3
Source File: KeyOrderingTest.java From jolt with Apache License 2.0 | 6 votes |
@DataProvider public Object[][] shiftrKeyOrderingTestCases() throws IOException { return new Object[][] { { "Simple * and &", JsonUtils.jsonToMap( "{ \"*\" : { \"a\" : \"b\" }, \"&\" : { \"a\" : \"b\" } }" ), Arrays.asList( "&(0,0)", "*" ) }, { "2* and 2&", JsonUtils.jsonToMap( "{ \"rating-*\" : { \"a\" : \"b\" }, \"rating-range-*\" : { \"a\" : \"b\" }, \"&\" : { \"a\" : \"b\" }, \"tuna-&(0)\" : { \"a\" : \"b\" } }" ), Arrays.asList( "tuna-&(0,0)", "&(0,0)", "rating-range-*", "rating-*" ) }, { "2& alpha-number based fallback", JsonUtils.jsonToMap( "{ \"&\" : { \"a\" : \"b\" }, \"&(0,1)\" : { \"a\" : \"b\" } }" ), Arrays.asList( "&(0,0)", "&(0,1)" ) }, { "2* and 2& alpha fallback", JsonUtils.jsonToMap( "{ \"aaaa-*\" : { \"a\" : \"b\" }, \"bbbb-*\" : { \"a\" : \"b\" }, \"aaaa-&\" : { \"a\" : \"b\" }, \"bbbb-&(0)\" : { \"a\" : \"b\" } }" ), Arrays.asList( "aaaa-&(0,0)", "bbbb-&(0,0)", "aaaa-*", "bbbb-*" ) } }; }
Example 4
Source File: ConfigRepoMigrator.java From gocd with Apache License 2.0 | 5 votes |
private Map<String, Object> getContextMap(int targetVersion) { try { String contextFile = String.format("/config-repo/contexts/%s.json", targetVersion); String contextJSON = IOUtils.toString(this.getClass().getResourceAsStream(contextFile), "UTF-8"); return JsonUtils.jsonToMap(contextJSON); } catch (Exception e) { LOGGER.debug(String.format("No context file present for target version '%s'.", targetVersion)); return null; } }
Example 5
Source File: ConfigRepoDocumentMother.java From gocd with Apache License 2.0 | 5 votes |
private Map<String, Object> getJSONFor(String fileName) { try { String transformJSON = IOUtils.toString(this.getClass().getResourceAsStream(fileName), "UTF-8"); return JsonUtils.jsonToMap(transformJSON); } catch (Exception e) { throw new RuntimeException(e); } }
Example 6
Source File: SimpleTraversalTest.java From jolt with Apache License 2.0 | 5 votes |
@DataProvider public Object[][] inAndOutTestCases() throws Exception { return new Object[][] { { "Simple Map Test", SimpleTraversal.newTraversal( "a.b" ), JsonUtils.jsonToMap( "{ \"a\" : null }" ), JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : \"tuna\" } }" ), "tuna" }, { "Simple explicit array test", SimpleTraversal.newTraversal( "a.[1].b" ), JsonUtils.jsonToMap( "{ \"a\" : null }" ), JsonUtils.jsonToMap( "{ \"a\" : [ null, { \"b\" : \"tuna\" } ] }" ), "tuna" }, { "Leading Array test", SimpleTraversal.newTraversal( "[0].a" ), JsonUtils.jsonToObject( "[ ]" ), JsonUtils.jsonToObject( "[ { \"a\" : \"b\" } ]" ), "b" }, { "Auto expand array test", SimpleTraversal.newTraversal( "a.[].b" ), JsonUtils.jsonToMap( "{ \"a\" : null }" ), JsonUtils.jsonToMap( "{ \"a\" : [ { \"b\" : null } ] }" ), null } }; }
Example 7
Source File: JoltUtilsRemoveTest.java From jolt with Apache License 2.0 | 5 votes |
@Test( description = "No exception if we don't try to remove from an ImmutableMap.") public void doNotUnnecessarilyDieOnImmutableMaps() { Map expected = JsonUtils.jsonToMap( JsonUtils.toJsonString( top ) ); JoltUtils.removeRecursive( top, "tuna" ); Diffy.Result result = diffy.diff( expected, top ); if (!result.isEmpty()) { Assert.fail( "Failed.\nhere is a diff:\nexpected: " + JsonUtils.toJsonString(result.expected) + "\n actual: " + JsonUtils.toJsonString(result.actual)); } }
Example 8
Source File: MappingTest2.java From jolt with Apache License 2.0 | 4 votes |
@Test public void testPolymorphicJacksonSerializationAndDeserialization() { ObjectMapper mapper = new ObjectMapper(); SimpleModule testModule = new SimpleModule("testModule", new Version(1, 0, 0, null, null, null)) .addDeserializer( QueryFilter.class, new QueryFilterDeserializer() ) .addSerializer( LogicalFilter2.class, new LogicalFilter2Serializer() ); mapper.registerModule(testModule); // Verifying that we can pass in a custom Mapper and create a new JsonUtil JsonUtil jsonUtil = JsonUtils.customJsonUtil( mapper ); String testFixture = "/jsonUtils/testdomain/two/queryFilter-realAndLogical2.json"; // TEST JsonUtil and our deserialization logic QueryFilter queryFilter = jsonUtil.classpathToType( testFixture, new TypeReference<QueryFilter>() {} ); // Make sure the hydrated QFilter looks right Assert.assertTrue( queryFilter instanceof LogicalFilter2 ); Assert.assertEquals( QueryParam.AND, queryFilter.getQueryParam() ); Assert.assertTrue( queryFilter.isLogical() ); Assert.assertEquals( 3, queryFilter.getFilters().size() ); Assert.assertNotNull( queryFilter.getFilters().get( QueryParam.OR ) ); // Make sure one of the top level RealFilters looks right QueryFilter productIdFilter = queryFilter.getFilters().get( QueryParam.PRODUCTID ); Assert.assertTrue( productIdFilter.isReal() ); Assert.assertEquals( QueryParam.PRODUCTID, productIdFilter.getQueryParam() ); Assert.assertEquals( "Acme-1234", productIdFilter.getValue() ); // Make sure the nested OR looks right QueryFilter orFilter = queryFilter.getFilters().get( QueryParam.OR ); Assert.assertTrue( orFilter.isLogical() ); Assert.assertEquals( QueryParam.OR, orFilter.getQueryParam() ); Assert.assertEquals( 2, orFilter.getFilters().size() ); // Make sure nested AND looks right QueryFilter nestedAndFilter = orFilter.getFilters().get( QueryParam.AND ); Assert.assertTrue( nestedAndFilter.isLogical() ); Assert.assertEquals( QueryParam.AND, nestedAndFilter.getQueryParam() ); Assert.assertEquals( 2, nestedAndFilter.getFilters().size() ); // SERIALIZE TO STRING to test serialization logic String unitTestString = jsonUtil.toJsonString( queryFilter ); // LOAD and Diffy the plain vanilla JSON versions of the documents Map<String, Object> actual = JsonUtils.jsonToMap( unitTestString ); Map<String, Object> expected = JsonUtils.classpathToMap( testFixture ); // Diffy the vanilla versions Diffy.Result result = diffy.diff( expected, actual ); if (!result.isEmpty()) { Assert.fail( "Failed.\nhere is a diff:\nexpected: " + JsonUtils.toJsonString( result.expected ) + "\n actual: " + JsonUtils.toJsonString( result.actual ) ); } }
Example 9
Source File: MappingTest4.java From jolt with Apache License 2.0 | 4 votes |
@Test public void testPolymorphicJacksonSerializationAndDeserialization() { ObjectMapper mapper = new ObjectMapper(); SimpleModule testModule = new SimpleModule("testModule", new Version(1, 0, 0, null, null, null)) .addDeserializer( QueryFilter4.class, new QueryFilter4Deserializer() ); mapper.registerModule(testModule); // Verifying that we can pass in a custom Mapper and create a new JsonUtil JsonUtil jsonUtil = JsonUtils.customJsonUtil( mapper ); String testFixture = "/jsonUtils/testdomain/four/queryFilter-realAndLogical4.json"; // TEST JsonUtil and our deserialization logic QueryFilter4 queryFilter = jsonUtil.classpathToType( testFixture, new TypeReference<QueryFilter4>() {} ); // Make sure the hydrated QFilter looks right Assert.assertTrue( queryFilter instanceof LogicalFilter4); Assert.assertEquals( QueryParam.AND, queryFilter.getQueryParam() ); Assert.assertTrue( queryFilter.isLogical() ); Assert.assertEquals( 3, queryFilter.getFilters().size() ); Assert.assertNotNull( queryFilter.getFilters().get( QueryParam.OR ) ); // Make sure one of the top level RealFilters looks right QueryFilter4 productIdFilter = queryFilter.getFilters().get( QueryParam.PRODUCTID ); Assert.assertTrue( productIdFilter.isReal() ); Assert.assertTrue( productIdFilter instanceof StringRealFilter4); StringRealFilter4 stringRealProductIdFilter = (StringRealFilter4) productIdFilter; Assert.assertEquals( QueryParam.PRODUCTID, stringRealProductIdFilter.getQueryParam() ); Assert.assertEquals( "Acme-1234", stringRealProductIdFilter.getValue() ); // Make sure the nested OR looks right QueryFilter4 orFilter = queryFilter.getFilters().get( QueryParam.OR ); Assert.assertTrue( orFilter.isLogical() ); Assert.assertEquals( QueryParam.OR, orFilter.getQueryParam() ); Assert.assertEquals( 2, orFilter.getFilters().size() ); // Make sure nested AND looks right QueryFilter4 nestedAndFilter = orFilter.getFilters().get( QueryParam.AND ); Assert.assertTrue( nestedAndFilter.isLogical() ); Assert.assertEquals( QueryParam.AND, nestedAndFilter.getQueryParam() ); Assert.assertEquals( 2, nestedAndFilter.getFilters().size() ); // SERIALIZE TO STRING to test serialization logic String unitTestString = jsonUtil.toJsonString( queryFilter ); // LOAD and Diffy the plain vanilla JSON versions of the documents Map<String, Object> actual = JsonUtils.jsonToMap( unitTestString ); Map<String, Object> expected = JsonUtils.classpathToMap( testFixture ); // Diffy the vanilla versions Diffy.Result result = diffy.diff( expected, actual ); if (!result.isEmpty()) { Assert.fail( "Failed.\nhere is a diff:\nexpected: " + JsonUtils.toJsonString( result.expected ) + "\n actual: " + JsonUtils.toJsonString( result.actual ) ); } }
Example 10
Source File: MappingTest3.java From jolt with Apache License 2.0 | 4 votes |
@Test public void testPolymorphicJacksonSerializationAndDeserialization() { ObjectMapper mapper = new ObjectMapper(); SimpleModule testModule = new SimpleModule("testModule", new Version(1, 0, 0, null, null, null)) .addDeserializer( QueryFilter.class, new QueryFilterDeserializer() ); mapper.registerModule(testModule); // Verifying that we can pass in a custom Mapper and create a new JsonUtil JsonUtil jsonUtil = JsonUtils.customJsonUtil( mapper ); String testFixture = "/jsonUtils/testdomain/two/queryFilter-realAndLogical2.json"; // TEST JsonUtil and our deserialization logic QueryFilter queryFilter = jsonUtil.classpathToType( testFixture, new TypeReference<QueryFilter>() {} ); // Make sure the hydrated QFilter looks right Assert.assertTrue( queryFilter instanceof LogicalFilter3 ); Assert.assertEquals( QueryParam.AND, queryFilter.getQueryParam() ); Assert.assertTrue( queryFilter.isLogical() ); Assert.assertEquals( 3, queryFilter.getFilters().size() ); Assert.assertNotNull( queryFilter.getFilters().get( QueryParam.OR ) ); // Make sure one of the top level RealFilters looks right QueryFilter productIdFilter = queryFilter.getFilters().get( QueryParam.PRODUCTID ); Assert.assertTrue( productIdFilter.isReal() ); Assert.assertEquals( QueryParam.PRODUCTID, productIdFilter.getQueryParam() ); Assert.assertEquals( "Acme-1234", productIdFilter.getValue() ); // Make sure the nested OR looks right QueryFilter orFilter = queryFilter.getFilters().get( QueryParam.OR ); Assert.assertTrue( orFilter.isLogical() ); Assert.assertEquals( QueryParam.OR, orFilter.getQueryParam() ); Assert.assertEquals( 2, orFilter.getFilters().size() ); // Make sure nested AND looks right QueryFilter nestedAndFilter = orFilter.getFilters().get( QueryParam.AND ); Assert.assertTrue( nestedAndFilter.isLogical() ); Assert.assertEquals( QueryParam.AND, nestedAndFilter.getQueryParam() ); Assert.assertEquals( 2, nestedAndFilter.getFilters().size() ); // SERIALIZE TO STRING to test serialization logic String unitTestString = jsonUtil.toJsonString( queryFilter ); // LOAD and Diffy the plain vanilla JSON versions of the documents Map<String, Object> actual = JsonUtils.jsonToMap( unitTestString ); Map<String, Object> expected = JsonUtils.classpathToMap( testFixture ); // Diffy the vanilla versions Diffy.Result result = diffy.diff( expected, actual ); if (!result.isEmpty()) { Assert.fail( "Failed.\nhere is a diff:\nexpected: " + JsonUtils.toJsonString( result.expected ) + "\n actual: " + JsonUtils.toJsonString( result.actual ) ); } }
Example 11
Source File: MappingTest5.java From jolt with Apache License 2.0 | 4 votes |
@Test public void testPolymorphicJacksonSerializationAndDeserialization() { ObjectMapper mapper = new ObjectMapper(); SimpleModule testModule = new SimpleModule("testModule", new Version(1, 0, 0, null, null, null)) .addDeserializer( QueryFilter5.class, new QueryFilter5Deserializer() ); mapper.registerModule(testModule); // Verifying that we can pass in a custom Mapper and create a new JsonUtil JsonUtil jsonUtil = JsonUtils.customJsonUtil( mapper ); String testFixture = "/jsonUtils/testdomain/five/queryFilter-realAndLogical5.json"; // TEST JsonUtil and our deserialization logic QueryFilter5 queryFilter = jsonUtil.classpathToType( testFixture, new TypeReference<QueryFilter5>() {} ); // Make sure the hydrated QFilter looks right Assert.assertTrue( queryFilter instanceof LogicalFilter5); LogicalFilter5 andFilter = (LogicalFilter5) queryFilter; Assert.assertEquals( Operator.AND, andFilter.getOperator() ); Assert.assertNotNull(andFilter.getValues()); Assert.assertEquals(3, andFilter.getValues().size()); // Make sure one of the top level RealFilters looks right QueryFilter5 productIdFilter = andFilter.getValues().get(1); Assert.assertTrue( productIdFilter instanceof StringRealFilter5); StringRealFilter5 stringRealProductIdFilter = (StringRealFilter5) productIdFilter; Assert.assertEquals( Field.PRODUCTID, stringRealProductIdFilter.getField() ); Assert.assertEquals( Operator.EQ, stringRealProductIdFilter.getOperator() ); Assert.assertEquals( "Acme-1234", stringRealProductIdFilter.getValues().get(0) ); // Make sure the nested OR looks right QueryFilter5 orFilter = andFilter.getValues().get(2); Assert.assertTrue( orFilter instanceof LogicalFilter5 ); LogicalFilter5 realOrFilter = (LogicalFilter5) orFilter; Assert.assertEquals( Operator.OR, realOrFilter.getOperator() ); Assert.assertEquals( 2, realOrFilter.getValues().size() ); // Make sure nested AND looks right QueryFilter5 nestedAndFilter = realOrFilter.getValues().get(1); Assert.assertTrue( nestedAndFilter instanceof LogicalFilter5 ); Assert.assertEquals( Operator.AND, nestedAndFilter.getOperator() ); Assert.assertEquals( 3, nestedAndFilter.getValues().size() ); // SERIALIZE TO STRING to test serialization logic String unitTestString = jsonUtil.toJsonString( queryFilter ); // LOAD and Diffy the plain vanilla JSON versions of the documents Map<String, Object> actual = JsonUtils.jsonToMap( unitTestString ); Map<String, Object> expected = JsonUtils.classpathToMap( testFixture ); // Diffy the vanilla versions Diffy.Result result = diffy.diff( expected, actual ); if (!result.isEmpty()) { Assert.fail( "Failed.\nhere is a diff:\nexpected: " + JsonUtils.toJsonString( result.expected ) + "\n actual: " + JsonUtils.toJsonString( result.actual ) ); } }
Example 12
Source File: MappingTest1.java From jolt with Apache License 2.0 | 4 votes |
@Test public void testPolymorphicJacksonSerializationAndDeserialization() { ObjectMapper mapper = new ObjectMapper(); SimpleModule testModule = new SimpleModule("testModule", new Version(1, 0, 0, null, null, null)) .addDeserializer( QueryFilter.class, new QueryFilter1Deserializer() ); mapper.registerModule(testModule); // Verifying that we can pass in a custom Mapper and create a new JsonUtil JsonUtil jsonUtil = JsonUtils.customJsonUtil( mapper ); String testFixture = "/jsonUtils/testdomain/one/queryFilter-realAndLogical.json"; // TEST JsonUtil and our deserialization logic QueryFilter queryFilter = jsonUtil.classpathToType( testFixture, new TypeReference<QueryFilter>() {} ); // Make sure the hydrated queryFilter looks right Assert.assertTrue( queryFilter instanceof LogicalFilter1 ); Assert.assertEquals( QueryParam.AND, queryFilter.getQueryParam() ); Assert.assertTrue( queryFilter.isLogical() ); Assert.assertEquals( 3, queryFilter.getFilters().size() ); Assert.assertNotNull( queryFilter.getFilters().get( QueryParam.OR ) ); // Make sure one of the top level RealFilters looks right QueryFilter productIdFilter = queryFilter.getFilters().get( QueryParam.PRODUCTID ); Assert.assertTrue( productIdFilter.isReal() ); Assert.assertEquals( QueryParam.PRODUCTID, productIdFilter.getQueryParam() ); Assert.assertEquals( "Acme-1234", productIdFilter.getValue() ); // Make sure the nested OR looks right QueryFilter orFilter = queryFilter.getFilters().get( QueryParam.OR ); Assert.assertTrue( orFilter.isLogical() ); Assert.assertEquals( QueryParam.OR, orFilter.getQueryParam() ); Assert.assertEquals( 2, orFilter.getFilters().size() ); // Make sure nested AND looks right QueryFilter nestedAndFilter = orFilter.getFilters().get( QueryParam.AND ); Assert.assertTrue( nestedAndFilter.isLogical() ); Assert.assertEquals( QueryParam.AND, nestedAndFilter.getQueryParam() ); Assert.assertEquals( 2, nestedAndFilter.getFilters().size() ); // SERIALIZE TO STRING to test serialization logic String unitTestString = jsonUtil.toJsonString( queryFilter ); // LOAD and Diffy the plain vanilla JSON versions of the documents Map<String, Object> actual = JsonUtils.jsonToMap( unitTestString ); Map<String, Object> expected = JsonUtils.classpathToMap( testFixture ); // Diffy the vanilla versions Diffy.Result result = diffy.diff( expected, actual ); if (!result.isEmpty()) { Assert.fail( "Failed.\nhere is a diff:\nexpected: " + JsonUtils.toJsonString( result.expected ) + "\n actual: " + JsonUtils.toJsonString( result.actual ) ); } }
Example 13
Source File: ShiftrTraversrTest.java From jolt with Apache License 2.0 | 4 votes |
@DataProvider public Object[][] inAndOutTestCases() throws Exception { return new Object[][] { { "simple place", Arrays.asList( "tuna" ), "tuna", "a.b", Arrays.asList( "a", "b" ), JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : \"tuna\" } }" ) }, { "simple explicit array place", Arrays.asList( "tuna" ), null, "a.b[]", Arrays.asList( "a", "b", "[]" ), JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : [ \"tuna\" ] } }" ) }, { "simple explicit array place with sub", Arrays.asList( "tuna" ), null, "a.b[].c", Arrays.asList( "a", "b", "[]", "c" ), JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : [ { \"c\" : \"tuna\" } ] } }" ) }, { "simple array place", Arrays.asList( "tuna" ), "tuna", "a.b.[1]", Arrays.asList( "a", "b", "1" ), JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : [ null, \"tuna\" ] } }" ) }, { "nested array place", Arrays.asList( "tuna" ), "tuna", "a.b[1].c", Arrays.asList( "a", "b", "1", "c" ), JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : [ null, { \"c\" : \"tuna\" } ] } }" ) }, { "simple place into write array", Arrays.asList( "tuna", "marlin" ), Arrays.asList( "tuna", "marlin" ), "a.b", Arrays.asList( "a", "b" ), JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : [ \"tuna\", \"marlin\" ] } }" ) }, { "simple array place with nested write array", Arrays.asList( "tuna", "marlin" ), Arrays.asList( "tuna", "marlin" ), "a.b.[1]", Arrays.asList( "a", "b", "1" ), JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : [ null, [ \"tuna\", \"marlin\" ] ] } }" ) }, { "nested array place with nested ouptut array", Arrays.asList( "tuna", "marlin" ), Arrays.asList( "tuna", "marlin" ), "a.b.[1].c", Arrays.asList( "a", "b", "1", "c" ), JsonUtils.jsonToMap( "{ \"a\" : { \"b\" : [ null, { \"c\" : [ \"tuna\", \"marlin\"] } ] } }" ) } }; }
Example 14
Source File: ShiftrUnitTest.java From jolt with Apache License 2.0 | 4 votes |
@DataProvider public Object[][] shiftrTestCases() throws IOException { return new Object[][] { { "Simple * and Reference", JsonUtils.jsonToMap("{ \"tuna-*-marlin-*\" : { \"rating-*\" : \"&(1,2).&.value\" } }"), JsonUtils.jsonToMap("{ \"tuna-A-marlin-AAA\" : { \"rating-BBB\" : \"bar\" } }"), JsonUtils.jsonToMap("{ \"AAA\" : { \"rating-BBB\" : { \"value\" : \"bar\" } } }") }, { "Shift to two places", JsonUtils.jsonToMap("{ \"tuna-*-marlin-*\" : { \"rating-*\" : [ \"&(1,2).&.value\", \"foo\"] } }"), JsonUtils.jsonToMap("{ \"tuna-A-marlin-AAA\" : { \"rating-BBB\" : \"bar\" } }"), JsonUtils.jsonToMap("{ \"foo\" : \"bar\", \"AAA\" : { \"rating-BBB\" : { \"value\" : \"bar\" } } }") }, { "Or", JsonUtils.jsonToMap("{ \"tuna|marlin\" : \"&-write\" }"), JsonUtils.jsonToMap("{ \"tuna\" : \"snapper\" }"), JsonUtils.jsonToMap("{ \"tuna-write\" : \"snapper\" }") }, { "KeyRef", JsonUtils.jsonToMap("{ \"rating-*\" : { \"&(0,1)\" : { \"match\" : \"&\" } } }"), JsonUtils.jsonToMap("{ \"rating-a\" : { \"a\" : { \"match\": \"a-match\" }, \"random\" : { \"match\" : \"noise\" } }," + " \"rating-c\" : { \"c\" : { \"match\": \"c-match\" }, \"random\" : { \"match\" : \"noise\" } } }"), JsonUtils.jsonToMap("{ \"match\" : [ \"a-match\", \"c-match\" ] }") }, { "Complex array write", JsonUtils.jsonToMap("{ \"tuna-*-marlin-*\" : { \"rating-*\" : \"tuna[&(1,1)].marlin[&(1,2)].&(0,1)\" } }"), JsonUtils.jsonToMap("{ \"tuna-2-marlin-3\" : { \"rating-BBB\" : \"bar\" }," + "\"tuna-1-marlin-0\" : { \"rating-AAA\" : \"mahi\" } }"), JsonUtils.jsonToMap("{ \"tuna\" : [ null, " + " { \"marlin\" : [ { \"AAA\" : \"mahi\" } ] }, " + " { \"marlin\" : [ null, null, null, { \"BBB\" : \"bar\" } ] } " + " ] " + " }") } }; }
Example 15
Source File: ShiftrUnitTest.java From jolt with Apache License 2.0 | 4 votes |
@DataProvider public Object[][] badSpecs() throws IOException { return new Object[][] { { "Null Spec", null, }, { "List Spec", new ArrayList<>(), }, { "Empty spec", JsonUtils.jsonToMap( "{ }" ), }, { "Empty sub-spec", JsonUtils.javason( "{ 'tuna' : {} }" ), }, { "Bad @", JsonUtils.javason( "{ 'tuna-*-marlin-*' : { 'rating-@' : '&(1,2).&.value' } }" ), }, { "RHS @ by itself", JsonUtils.javason( "{ 'tuna-*-marlin-*' : { 'rating-*' : '&(1,2)[email protected]' } }" ), }, { "RHS @ with bad Parens", JsonUtils.javason( "{ 'tuna-*-marlin-*' : { 'rating-*' : '&(1,2).@(data.&(1,1).value' } }" ), }, { "RHS *", JsonUtils.javason( "{ 'tuna-*-marlin-*' : { 'rating-*' : '&(1,2).*.value' } }" ), }, { "RHS $", JsonUtils.javason( "{ 'tuna-*-marlin-*' : { 'rating-*' : '&(1,2).$.value' } }" ), }, { "Two Arrays", JsonUtils.javason("{ 'tuna-*-marlin-*' : { 'rating-*' : [ '&(1,2).photos[&(0,1)]-subArray[&(1,2)].value', 'foo'] } }"), }, { "Can't mix * and & in the same key", JsonUtils.javason("{ 'tuna-*-marlin-*' : { 'rating-&(1,2)-*' : [ '&(1,2).value', 'foo'] } }"), }, { "Don't put negative numbers in array references", JsonUtils.javason("{ 'tuna' : 'marlin[-1]' }"), } }; }