/** * Creates a new JSONGetFunction instance. * * @param coercibleType of JSONCoercibleType * @param pointerMap of Map */ @ConstructorProperties({"coercibleType", "pointerMap"}) public JSONGetFunction( JSONCoercibleType coercibleType, Map<Fields, String> pointerMap ) { this( coercibleType, asFields( pointerMap.keySet() ), asArray( pointerMap.values() ) ); }
@Test public void testGetMap() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) ); entry.setObject( 0, JSONData.nested ); // the map ctor really expects large numbers of entries to be useful JSONGetFunction function = new JSONGetFunction( singletonMap( new Fields( "result" ), "/person/name" ) ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "John Doe", ( (TextNode) value ).textValue() ); } }
@Test public void testGetMap() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) ); entry.setObject( 0, JSONData.nested ); // the map ctor really expects large numbers of entries to be useful JSONGetFunction function = new JSONGetFunction( singletonMap( new Fields( "result" ), "/person/name" ) ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "John Doe", ( (TextNode) value ).textValue() ); } }
@Test public void testGetMissing() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) ); entry.setObject( 0, JSONData.nested ); JSONGetFunction function = new JSONGetFunction( new Fields( "result" ), "/person/foobar" ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNull( value ); }
/** * Creates a new JSONGetFunction instance. * * @param pointerMap of Map * @param failOnMissingNode of boolean */ @ConstructorProperties({"pointerMap", "failOnMissingNode"}) public JSONGetFunction( Map<Fields, String> pointerMap, boolean failOnMissingNode ) { this( asFields( pointerMap.keySet() ), failOnMissingNode, asArray( pointerMap.values() ) ); }
@Test public void testGetMissing() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) ); entry.setObject( 0, JSONData.nested ); JSONGetFunction function = new JSONGetFunction( new Fields( "result" ), "/person/foobar" ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNull( value ); }
@Test(expected = OperationException.class) public void testGetMissingFail() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) ); entry.setObject( 0, JSONData.nested ); JSONGetFunction function = new JSONGetFunction( new Fields( "result" ), true, "/person/foobar" ); invokeFunction( function, entry, new Fields( "result" ) ); }
/** * Creates a new JSONGetFunction instance. * * @param coercibleType of JSONCoercibleType * @param pointerMap of Map * @param failOnMissingNode of boolean */ @ConstructorProperties({"coercibleType", "pointerMap", "failOnMissingNode"}) public JSONGetFunction( JSONCoercibleType coercibleType, Map<Fields, String> pointerMap, boolean failOnMissingNode ) { this( coercibleType, asFields( pointerMap.keySet() ), failOnMissingNode, asArray( pointerMap.values() ) ); }
@Test(expected = OperationException.class) public void testGetMissingFail() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) ); entry.setObject( 0, JSONData.nested ); JSONGetFunction function = new JSONGetFunction( new Fields( "result" ), true, "/person/foobar" ); invokeFunction( function, entry, new Fields( "result" ) ); }
@Test public void testGet() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) ); entry.setObject( 0, JSONData.nested ); JSONGetFunction function = new JSONGetFunction( new Fields( "result" ), "/person/name" ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "John Doe", ( (TextNode) value ).textValue() ); }
@Test public void testGet() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) ); entry.setObject( 0, JSONData.nested ); JSONGetFunction function = new JSONGetFunction( new Fields( "result" ), "/person/name" ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "John Doe", ( (TextNode) value ).textValue() ); }
pipe = new Each( pipe, new Fields( "result" ), new JSONGetFunction( new Fields( "year", int.class ), "/approvalfy" ), Fields.ALL );
pipe = new Each( pipe, new Fields( "result" ), new JSONGetFunction( new Fields( "year", int.class ), "/approvalfy" ), Fields.ALL );