ValueMetaResolver { public Object getTypedValue( String fieldName, int originalType, Object value ) throws PushDownOptimizationException { ValueMetaInterface valueMeta = getValueMeta( fieldName ); if ( valueMeta.getType() == originalType ) { return value; } return convertToType( valueMeta, originalType, value ); } ValueMetaResolver( RowMetaInterface rowMeta ); RowMetaInterface getRowMeta(); ValueMetaInterface getValueMeta( String fieldName ); Object getTypedValue( String fieldName, int originalType, Object value ); Object[] inListToTypedObjectArray( String fieldName, String value );  }
@Test public void stringResolvedToLong() throws KettleException { ValueMetaResolver resolver = new ValueMetaResolver( getTestRowMeta( ValueMetaInterface.TYPE_INTEGER ) ); int originalType = ValueMetaInterface.TYPE_STRING; Object value = resolver.getTypedValue( "field", originalType, "101010" ); assertTrue( value instanceof Long ); assertTrue( value.equals( new Long( 101010 ) ) ); }
@Test public void getMixedValues() throws KettleException { ValueMetaResolver resolver = new ValueMetaResolver( getTestRowMeta( new String[] { "field1", "field2", "field3" }, new int[] { ValueMetaInterface.TYPE_INTEGER, ValueMetaInterface.TYPE_BIGNUMBER, ValueMetaInterface.TYPE_BOOLEAN } ) ); assertEquals( new Long( 123 ), resolver.getTypedValue( "field1", ValueMetaInterface.TYPE_INTEGER, 123l ) ); assertEquals( new BigDecimal( 123 ), resolver.getTypedValue( "field2", ValueMetaInterface.TYPE_INTEGER, 123l ) ); assertEquals( new Boolean( true ), resolver.getTypedValue( "field3", ValueMetaInterface.TYPE_INTEGER, 1l ) ); try { resolver.getTypedValue( "fieldNonExistent", ValueMetaInterface.TYPE_STRING, "blah" ); } catch ( KettleException e ) { return; } fail( "Expected exception when resolving a non-existent field" ); }
@Test public void stringResolvedToDate() throws KettleException { ValueMetaResolver resolver = new ValueMetaResolver( getTestRowMeta( ValueMetaInterface.TYPE_DATE ) ); int originalType = ValueMetaInterface.TYPE_STRING; final String convertedDateStr = "2014-10-10"; Object value = resolver.getTypedValue( "field", originalType, convertedDateStr ); assertEquals( convertedDateStr, new SimpleDateFormat( "yyyy-MM-dd" ).format( value ) ); }
@Test public void stringResolvedToTimestamp() throws KettleException { ValueMetaResolver resolver = new ValueMetaResolver( getTestRowMeta( ValueMetaInterface.TYPE_TIMESTAMP ) ); int originalType = ValueMetaInterface.TYPE_STRING; final String convertedTimestampStr = "2014-10-10 12:24:32.012"; Object value = resolver.getTypedValue( "field", originalType, convertedTimestampStr ); assertEquals( convertedTimestampStr, new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss.SSS" ).format( value ) ); }