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
AssertJUnit.assertTrue( queryFilter instanceof LogicalFilter1 );
AssertJUnit.assertEquals( QueryParam.AND, queryFilter.getQueryParam() );
AssertJUnit.assertTrue( queryFilter.isLogical() );
AssertJUnit.assertEquals( 3, queryFilter.getFilters().size() );
AssertJUnit.assertNotNull( queryFilter.getFilters().get( QueryParam.OR ) );
// Make sure one of the top level RealFilters looks right
QueryFilter productIdFilter = queryFilter.getFilters().get( QueryParam.PRODUCTID );
AssertJUnit.assertTrue( productIdFilter.isReal() );
AssertJUnit.assertEquals( QueryParam.PRODUCTID, productIdFilter.getQueryParam() );
AssertJUnit.assertEquals( "Acme-1234", productIdFilter.getValue() );
// Make sure the nested OR looks right
QueryFilter orFilter = queryFilter.getFilters().get( QueryParam.OR );
AssertJUnit.assertTrue( orFilter.isLogical() );
AssertJUnit.assertEquals( QueryParam.OR, orFilter.getQueryParam() );
AssertJUnit.assertEquals( 2, orFilter.getFilters().size() );
// Make sure nested AND looks right
QueryFilter nestedAndFilter = orFilter.getFilters().get( QueryParam.AND );
AssertJUnit.assertTrue( nestedAndFilter.isLogical() );
AssertJUnit.assertEquals( QueryParam.AND, nestedAndFilter.getQueryParam() );
AssertJUnit.assertEquals( 2, nestedAndFilter.getFilters().size() );
// SERIALIZE TO STRING to test serialization logic
String unitTestString = jsonUtil.toJsonString( queryFilter );