Java Code Examples for com.bazaarvoice.jolt.JsonUtils#classpathToMap()
The following examples show how to use
com.bazaarvoice.jolt.JsonUtils#classpathToMap() .
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: GuicedChainrContextTest.java From jolt with Apache License 2.0 | 6 votes |
@DataProvider public Iterator<Object[]> getCases() throws IOException { String testPath = "/json/chainr/guice_spec_with_context.json"; Map<String, Object> testSuite = JsonUtils.classpathToMap( testPath ); Object spec = testSuite.get( "spec" ); List<Map> tests = (List<Map>) testSuite.get( "tests" ); List<Object[]> accum = Lists.newLinkedList(); for ( Map testCase : tests ) { String testCaseName = (String) testCase.get( "testCaseName" ); Object input = testCase.get( "input" ); Map<String,Object> context = (Map<String,Object>) testCase.get( "context" ); Object expected = testCase.get( "expected" ); accum.add( new Object[] { testCaseName, spec, input, context, expected } ); } return accum.iterator(); }
Example 2
Source File: GuicedChainrTest.java From jolt with Apache License 2.0 | 6 votes |
@Test( expectedExceptions = SpecException.class ) public void itBlowsUpForMissingProviderStockTransform() throws IOException { String testPath = "/json/chainr/guice_spec.json"; Map<String, Object> testUnit = JsonUtils.classpathToMap( testPath ); Object spec = testUnit.get( "spec" ); Module parentModule = new AbstractModule() { @Override protected void configure() { } @Provides public GuiceSpecDrivenTransform.GuiceConfig getConfigD() { return new GuiceSpecDrivenTransform.GuiceConfig( "dd" ); } }; Chainr.fromSpec( spec, new GuiceChainrInstantiator( parentModule ) ); }
Example 3
Source File: GuicedChainrTest.java From jolt with Apache License 2.0 | 6 votes |
@Test( expectedExceptions = SpecException.class ) public void itBlowsUpForMissingProviderSpecTransform() throws IOException { String testPath = "/json/chainr/guice_spec.json"; Map<String, Object> testUnit = JsonUtils.classpathToMap( testPath ); Object spec = testUnit.get( "spec" ); Module parentModule = new AbstractModule() { @Override protected void configure() { } @Provides public GuiceTransform.GuiceConfig getConfigC() { return new GuiceTransform.GuiceConfig( "c", "cc" ); } }; Chainr.fromSpec( spec, new GuiceChainrInstantiator( parentModule ) ); }
Example 4
Source File: GuicedChainrTest.java From jolt with Apache License 2.0 | 5 votes |
@Test public void successTestCase() throws IOException { String testPath = "/json/chainr/guice_spec.json"; Map<String, Object> testUnit = JsonUtils.classpathToMap( testPath ); Object input = testUnit.get( "input" ); Object spec = testUnit.get( "spec" ); Object expected = testUnit.get( "expected" ); Module parentModule = new AbstractModule() { @Override protected void configure() { } @Provides public GuiceTransform.GuiceConfig getConfigC() { return new GuiceTransform.GuiceConfig( "c", "cc" ); } @Provides public GuiceSpecDrivenTransform.GuiceConfig getConfigD() { return new GuiceSpecDrivenTransform.GuiceConfig( "dd" ); } }; Chainr unit = Chainr.fromSpec( spec, new GuiceChainrInstantiator( parentModule ) ); Assert.assertFalse( unit.hasContextualTransforms() ); Assert.assertEquals( unit.getContextualTransforms().size(), 0 ); Object actual = unit.transform( input, null ); JoltTestUtil.runDiffy( "failed case " + testPath, expected, actual ); }
Example 5
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 6
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 7
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 8
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 9
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 ) ); } }