@Test public void testCopyIncludeDescent() throws Exception { Fields fields = new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "result", JSONCoercibleType.TYPE ) ); TupleEntry entry = new TupleEntry( fields, Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, JSONData.simple ); CopySpec copySpec = new CopySpec() .include( "/person/firstName" ) .include( "/**/age" ); JSONCopyIntoFunction function = new JSONCopyIntoFunction( new Fields( "result" ), copySpec ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "value", ( (ObjectNode) value ).get( "existing" ).textValue() ); // confirm we put data into an existing object assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() ); assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() ); assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) ); }
@Test public void testCopyIncludeWild() throws Exception { Fields fields = new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "result", JSONCoercibleType.TYPE ) ); TupleEntry entry = new TupleEntry( fields, Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, JSONData.simple ); CopySpec copySpec = new CopySpec() .include( "/person/firstName" ) .include( "/*/age" ); JSONCopyIntoFunction function = new JSONCopyIntoFunction( new Fields( "result" ), copySpec ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "value", ( (ObjectNode) value ).get( "existing" ).textValue() ); // confirm we put data into an existing object assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() ); assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() ); assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) ); }
@Test public void testCopyInclude() throws Exception { Fields fields = new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "result", JSONCoercibleType.TYPE ) ); TupleEntry entry = new TupleEntry( fields, Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, JSONData.simple ); CopySpec copySpec = new CopySpec() .include( "/person/firstName" ) .include( "/person/age" ); JSONCopyIntoFunction function = new JSONCopyIntoFunction( new Fields( "result" ), copySpec ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "value", ( (ObjectNode) value ).get( "existing" ).textValue() ); // confirm we put data into an existing object assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() ); assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() ); assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) ); }
@Test public void testCopyInclude() throws Exception { Fields fields = new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "result", JSONCoercibleType.TYPE ) ); TupleEntry entry = new TupleEntry( fields, Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, JSONData.simple ); CopySpec copySpec = new CopySpec() .include( "/person/firstName" ) .include( "/person/age" ); JSONCopyIntoFunction function = new JSONCopyIntoFunction( new Fields( "result" ), copySpec ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "value", ( (ObjectNode) value ).get( "existing" ).textValue() ); // confirm we put data into an existing object assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() ); assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() ); assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) ); }
@Test public void testCopyIncludeWild() throws Exception { Fields fields = new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "result", JSONCoercibleType.TYPE ) ); TupleEntry entry = new TupleEntry( fields, Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, JSONData.simple ); CopySpec copySpec = new CopySpec() .include( "/person/firstName" ) .include( "/*/age" ); JSONCopyIntoFunction function = new JSONCopyIntoFunction( new Fields( "result" ), copySpec ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "value", ( (ObjectNode) value ).get( "existing" ).textValue() ); // confirm we put data into an existing object assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() ); assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() ); assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) ); }
@Test public void testCopyIncludeDescent() throws Exception { Fields fields = new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "result", JSONCoercibleType.TYPE ) ); TupleEntry entry = new TupleEntry( fields, Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, JSONData.simple ); CopySpec copySpec = new CopySpec() .include( "/person/firstName" ) .include( "/**/age" ); JSONCopyIntoFunction function = new JSONCopyIntoFunction( new Fields( "result" ), copySpec ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "value", ( (ObjectNode) value ).get( "existing" ).textValue() ); // confirm we put data into an existing object assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() ); assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() ); assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) ); }
assertEquals( "John", value.findPath( "name" ).findPath( "first" ).textValue() ); assertEquals( JsonNodeType.STRING, value.findPath( "age" ).getNodeType() ); assertEquals( "50", value.findPath( "age" ).textValue() ); assertEquals( "123-45-6789", value.findValue( "ssn" ).textValue() ); assertEquals( JsonNodeType.ARRAY, value.findPath( "childAges" ).getNodeType() ); assertEquals( 1, value.findPath( "childAges" ).size() ); assertEquals( JsonNodeType.NUMBER, value.findPath( "childAges" ).get( 0 ).getNodeType() );
@Test public void testCopyIncludeWild() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) ); entry.setObject( 0, JSONData.nested ); CopySpec copySpec = new CopySpec() .include( "/person/firstName" ) .include( "/*/age" ); JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() ); assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() ); assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) ); }
@Test public void testCopyInclude() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) ); entry.setObject( 0, JSONData.nested ); CopySpec copySpec = new CopySpec() .include( "/person/firstName" ) .include( "/person/age" ); JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() ); assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() ); assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) ); }
@Test public void testCopyExclude() throws Exception { Fields fields = new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "result", JSONCoercibleType.TYPE ) ); TupleEntry entry = new TupleEntry( fields, Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, JSONData.simple ); CopySpec copySpec = new CopySpec() .exclude( "/person/ssn", "/person/children" ); JSONCopyIntoFunction function = new JSONCopyIntoFunction( new Fields( "result" ), copySpec ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "value", ( (ObjectNode) value ).get( "existing" ).textValue() ); // confirm we put data into an existing object assertEquals( "John Doe", ( (ObjectNode) value ).findPath( "name" ).textValue() ); assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() ); assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) ); assertEquals( null, ( (ObjectNode) value ).findValue( "children" ) ); }
@Test public void testCopyIncludeDescent() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) ); entry.setObject( 0, JSONData.nested ); CopySpec copySpec = new CopySpec() .include( "/person/firstName" ) .include( "/**/age" ); JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() ); assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() ); assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) ); }
@Test public void testCopyIncludeWild() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) ); entry.setObject( 0, JSONData.nested ); CopySpec copySpec = new CopySpec() .include( "/person/firstName" ) .include( "/*/age" ); JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() ); assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() ); assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) ); }
@Test public void testCopyInclude() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) ); entry.setObject( 0, JSONData.nested ); CopySpec copySpec = new CopySpec() .include( "/person/firstName" ) .include( "/person/age" ); JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() ); assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() ); assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) ); }
assertEquals( "John", value.findPath( "name" ).findPath( "first" ).textValue() ); assertEquals( JsonNodeType.STRING, value.findPath( "age" ).getNodeType() ); assertEquals( "50", value.findPath( "age" ).textValue() ); assertEquals( "123-45-6789", value.findValue( "ssn" ).textValue() ); assertEquals( JsonNodeType.ARRAY, value.findPath( "childAges" ).getNodeType() ); assertEquals( 1, value.findPath( "childAges" ).size() ); assertEquals( JsonNodeType.NUMBER, value.findPath( "childAges" ).get( 0 ).getNodeType() );
@Test public void testCopyExclude() throws Exception { Fields fields = new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "result", JSONCoercibleType.TYPE ) ); TupleEntry entry = new TupleEntry( fields, Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, JSONData.simple ); CopySpec copySpec = new CopySpec() .exclude( "/person/ssn", "/person/children" ); JSONCopyIntoFunction function = new JSONCopyIntoFunction( new Fields( "result" ), copySpec ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "value", ( (ObjectNode) value ).get( "existing" ).textValue() ); // confirm we put data into an existing object assertEquals( "John Doe", ( (ObjectNode) value ).findPath( "name" ).textValue() ); assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() ); assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) ); assertEquals( null, ( (ObjectNode) value ).findValue( "children" ) ); }
@Test public void testCopyIncludeDescent() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) ); entry.setObject( 0, JSONData.nested ); CopySpec copySpec = new CopySpec() .include( "/person/firstName" ) .include( "/**/age" ); JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() ); assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() ); assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) ); }
@Test public void testCopyExclude() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) ); entry.setObject( 0, JSONData.nested ); CopySpec copySpec = new CopySpec() .exclude( "/person/ssn", "/person/children" ); JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "John Doe", ( (ObjectNode) value ).findPath( "name" ).textValue() ); assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() ); assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) ); assertEquals( null, ( (ObjectNode) value ).findValue( "children" ) ); }
assertEquals( "John", value.findPath( "name" ).findPath( "first" ).textValue() ); assertEquals( JsonNodeType.STRING, value.findPath( "age" ).getNodeType() ); assertEquals( "50", value.findPath( "age" ).textValue() ); assertEquals( "123-45-6789", value.findValue( "ssn" ).textValue() ); assertEquals( JsonNodeType.ARRAY, value.findPath( "childAges" ).getNodeType() ); assertEquals( 1, value.findPath( "childAges" ).size() ); assertEquals( JsonNodeType.NUMBER, value.findPath( "childAges" ).get( 0 ).getNodeType() );
@Test public void testCopyExclude() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) ); entry.setObject( 0, JSONData.nested ); CopySpec copySpec = new CopySpec() .exclude( "/person/ssn", "/person/children" ); JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); Object value = result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "John Doe", ( (ObjectNode) value ).findPath( "name" ).textValue() ); assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() ); assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) ); assertEquals( null, ( (ObjectNode) value ).findValue( "children" ) ); }
assertEquals( "john", value.findPath( "name" ).findPath( "first" ).textValue() ); assertEquals( JsonNodeType.STRING, value.findPath( "age" ).getNodeType() ); assertEquals( "22", value.findPath( "age" ).textValue() ); assertEquals( "123-45-6789", value.findValue( "ssn" ).textValue() ); assertEquals( JsonNodeType.ARRAY, value.findPath( "childAges" ).getNodeType() ); assertEquals( 3, value.findPath( "childAges" ).size() ); assertEquals( JsonNodeType.NUMBER, value.findPath( "childAges" ).get( 0 ).getNodeType() );