@Test public void testSetMap() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "name", String.class ) ), Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, "Jane Doe" ); JSONSetFunction function = new JSONSetFunction( new Fields( "result" ), singletonMap( new Fields( "name", String.class ), "/person/name" ) ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); JsonNode value = (JsonNode) result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "Jane Doe", value.at( "/person/name" ).textValue() ); }
@Test public void testSetMapResolved() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "name", String.class ) ), Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, "Jane Doe" ); JSONSetFunction function = new JSONSetFunction( new Fields( "result" ), singletonMap( new Fields( 1, String.class ), "/person/name" ) ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); JsonNode value = (JsonNode) result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "Jane Doe", value.at( "/person/name" ).textValue() ); }
@Test public void testSetMap() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "name", String.class ) ), Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, "Jane Doe" ); JSONSetFunction function = new JSONSetFunction( new Fields( "result" ), singletonMap( new Fields( "name", String.class ), "/person/name" ) ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); JsonNode value = (JsonNode) result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "Jane Doe", value.at( "/person/name" ).textValue() ); }
@Test public void testSetMapResolved() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "name", String.class ) ), Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, "Jane Doe" ); JSONSetFunction function = new JSONSetFunction( new Fields( "result" ), singletonMap( new Fields( 1, String.class ), "/person/name" ) ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); JsonNode value = (JsonNode) result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "Jane Doe", value.at( "/person/name" ).textValue() ); }
@Test public void testSetResolvedArguments() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "name", String.class ) ), Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, "Jane Doe" ); Fields fieldDeclaration = new Fields( "result" ); JSONSetFunction function = new JSONSetFunction( fieldDeclaration ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); JsonNode value = (JsonNode) result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "Jane Doe", value.at( "/name" ).textValue() ); }
@Test public void testSetResolvedArguments() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "name", String.class ) ), Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, "Jane Doe" ); Fields fieldDeclaration = new Fields( "result" ); JSONSetFunction function = new JSONSetFunction( fieldDeclaration ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); JsonNode value = (JsonNode) result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "Jane Doe", value.at( "/name" ).textValue() ); }
@Test public void testSetResolvedArgumentsWithRoot() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "name", String.class ) ), Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, "Jane Doe" ); Fields fieldDeclaration = new Fields( "result" ); JSONSetFunction function = new JSONSetFunction( fieldDeclaration, "/person2" ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); JsonNode value = (JsonNode) result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "Jane Doe", value.at( "/person2/name" ).textValue() ); }
@Test public void testSetResolvedArgumentsWithRoot() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "name", String.class ) ), Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, "Jane Doe" ); Fields fieldDeclaration = new Fields( "result" ); JSONSetFunction function = new JSONSetFunction( fieldDeclaration, "/person2" ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); JsonNode value = (JsonNode) result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "Jane Doe", value.at( "/person2/name" ).textValue() ); }
@Test public void testSetReplace() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "name", String.class ) ), Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, "Jane Doe" ); JSONSetFunction function = new JSONSetFunction( new Fields( "result" ), new Fields( "name", String.class ), "/person/name" ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); JsonNode value = (JsonNode) result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "Jane Doe", value.at( "/person/name" ).textValue() ); }
@Test public void testSet() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "name", String.class ) ), Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, "Jane Doe" ); JSONSetFunction function = new JSONSetFunction( new Fields( "result" ), new Fields( "name", String.class ), "/person/otherName" ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); JsonNode value = (JsonNode) result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "Jane Doe", value.at( "/person/otherName" ).textValue() ); }
@Test public void testSetDeep() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "name", String.class ) ), Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, "Jane Doe" ); JSONSetFunction function = new JSONSetFunction( new Fields( "result" ), new Fields( "name", String.class ), "/person/foo/name" ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); JsonNode value = (JsonNode) result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "Jane Doe", value.at( "/person/foo/name" ).textValue() ); }
@Test public void testSetReplace() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "name", String.class ) ), Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, "Jane Doe" ); JSONSetFunction function = new JSONSetFunction( new Fields( "result" ), new Fields( "name", String.class ), "/person/name" ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); JsonNode value = (JsonNode) result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "Jane Doe", value.at( "/person/name" ).textValue() ); }
@Test public void testSet() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "name", String.class ) ), Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, "Jane Doe" ); JSONSetFunction function = new JSONSetFunction( new Fields( "result" ), new Fields( "name", String.class ), "/person/otherName" ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); JsonNode value = (JsonNode) result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "Jane Doe", value.at( "/person/otherName" ).textValue() ); }
@Test public void testSetDeep() throws Exception { TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "name", String.class ) ), Tuple.size( 2 ) ); entry.setObject( 0, JSONData.nested ); entry.setObject( 1, "Jane Doe" ); JSONSetFunction function = new JSONSetFunction( new Fields( "result" ), new Fields( "name", String.class ), "/person/foo/name" ); TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) ); JsonNode value = (JsonNode) result.iterator().next().getObject( 0 ); assertNotNull( value ); assertEquals( "Jane Doe", value.at( "/person/foo/name" ).textValue() ); }