当前位置: 首页>>代码示例>>Java>>正文


Java JsonUtils.classpathToMap方法代码示例

本文整理汇总了Java中com.bazaarvoice.jolt.JsonUtils.classpathToMap方法的典型用法代码示例。如果您正苦于以下问题:Java JsonUtils.classpathToMap方法的具体用法?Java JsonUtils.classpathToMap怎么用?Java JsonUtils.classpathToMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.bazaarvoice.jolt.JsonUtils的用法示例。


在下文中一共展示了JsonUtils.classpathToMap方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCases

import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@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();
}
 
开发者ID:bazaarvoice,项目名称:jolt,代码行数:24,代码来源:GuicedChainrContextTest.java

示例2: itBlowsUpForMissingProviderStockTransform

import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@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 ) );
}
 
开发者ID:bazaarvoice,项目名称:jolt,代码行数:22,代码来源:GuicedChainrTest.java

示例3: itBlowsUpForMissingProviderSpecTransform

import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@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 ) );
}
 
开发者ID:bazaarvoice,项目名称:jolt,代码行数:22,代码来源:GuicedChainrTest.java

示例4: successTestCase

import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@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 );
}
 
开发者ID:bazaarvoice,项目名称:jolt,代码行数:36,代码来源:GuicedChainrTest.java

示例5: testPolymorphicJacksonSerializationAndDeserialization

import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@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 ) );
    }
}
 
开发者ID:bazaarvoice,项目名称:jolt,代码行数:59,代码来源:MappingTest2.java

示例6: testPolymorphicJacksonSerializationAndDeserialization

import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@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 ) );
    }
}
 
开发者ID:bazaarvoice,项目名称:jolt,代码行数:60,代码来源:MappingTest4.java

示例7: testPolymorphicJacksonSerializationAndDeserialization

import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@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 ) );
    }
}
 
开发者ID:bazaarvoice,项目名称:jolt,代码行数:58,代码来源:MappingTest3.java

示例8: testPolymorphicJacksonSerializationAndDeserialization

import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@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 ) );
    }
}
 
开发者ID:bazaarvoice,项目名称:jolt,代码行数:61,代码来源:MappingTest5.java

示例9: testPolymorphicJacksonSerializationAndDeserialization

import com.bazaarvoice.jolt.JsonUtils; //导入方法依赖的package包/类
@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 ) );
    }
}
 
开发者ID:bazaarvoice,项目名称:jolt,代码行数:58,代码来源:MappingTest1.java


注:本文中的com.bazaarvoice.jolt.JsonUtils.classpathToMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。