Java Code Examples for org.pentaho.di.core.row.value.ValueMetaString#setStorageType()

The following examples show how to use org.pentaho.di.core.row.value.ValueMetaString#setStorageType() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: pentaho-kettle   File: StreamLookupTest.java    License: Apache License 2.0 6 votes vote down vote up
private RowSet mockDataRowSet( boolean binary ) {
  final int storageType = binary ? ValueMetaInterface.STORAGE_TYPE_BINARY_STRING : ValueMetaInterface.STORAGE_TYPE_NORMAL;
  Object[][] data = { { "Name1", "1" }, { "Name2", "2" } };

  if ( binary ) {
    convertDataToBinary( data );
  }

  RowSet dataRowSet = smh.getMockInputRowSet( data );

  RowMeta dataRowMeta = new RowMeta();
  ValueMetaString valueMeta = new ValueMetaString( "Name" );
  valueMeta.setStorageType( storageType );
  valueMeta.setStorageMetadata( new ValueMetaString() );
  dataRowMeta.addValueMeta( valueMeta );
  ValueMetaString idMeta = new ValueMetaString( "Id" );
  idMeta.setStorageType( storageType );
  idMeta.setStorageMetadata( new ValueMetaString() );
  dataRowMeta.addValueMeta( idMeta );

  doReturn( dataRowMeta ).when( dataRowSet ).getRowMeta();

  return dataRowSet;
}
 
Example 2
private RowSet mockInputRowSet() {
  ValueMetaString valueMeta = new ValueMetaString( "Value" );
  valueMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING );
  valueMeta.setStorageMetadata( new ValueMetaString( "Value" ) );

  RowMeta inputRowMeta = new RowMeta();
  inputRowMeta.addValueMeta( valueMeta );

  RowSet inputRowSet = smh.getMockInputRowSet( new Object[][] { { " Value ".getBytes() } } );
  doReturn( inputRowMeta ).when( inputRowSet ).getRowMeta();

  return inputRowSet;
}
 
Example 3
Source Project: pentaho-kettle   File: PDI5436Test.java    License: Apache License 2.0 5 votes vote down vote up
private RowMeta mockInputRowMeta() {
  RowMeta inputRowMeta = new RowMeta();
  ValueMetaString nameMeta = new ValueMetaString( "name" );
  nameMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING );
  nameMeta.setStorageMetadata( new ValueMetaString( "name" ) );
  inputRowMeta.addValueMeta( nameMeta );
  ValueMetaString idMeta = new ValueMetaString( "id" );
  idMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING );
  idMeta.setStorageMetadata( new ValueMetaString( "id" ) );
  inputRowMeta.addValueMeta( idMeta );

  return inputRowMeta;
}
 
Example 4
Source Project: pentaho-kettle   File: StreamLookupTest.java    License: Apache License 2.0 5 votes vote down vote up
private RowSet mockLookupRowSet( boolean binary ) {
  final int storageType = binary ? ValueMetaInterface.STORAGE_TYPE_BINARY_STRING : ValueMetaInterface.STORAGE_TYPE_NORMAL;
  Object[][] data = { { "Value1", "1" }, { "Value2", "2" } };

  if ( binary ) {
    convertDataToBinary( data );
  }

  RowSet lookupRowSet =
    smh.getMockInputRowSet( data );
  doReturn( "Lookup" ).when( lookupRowSet ).getOriginStepName();
  doReturn( "StreamLookup" ).when( lookupRowSet ).getDestinationStepName();

  RowMeta lookupRowMeta = new RowMeta();
  ValueMetaString valueMeta = new ValueMetaString( "Value" );
  valueMeta.setStorageType( storageType );
  valueMeta.setStorageMetadata( new ValueMetaString() );
  lookupRowMeta.addValueMeta( valueMeta );
  ValueMetaString idMeta = new ValueMetaString( "Id" );
  idMeta.setStorageType( storageType );
  idMeta.setStorageMetadata( new ValueMetaString() );
  lookupRowMeta.addValueMeta( idMeta );

  doReturn( lookupRowMeta ).when( lookupRowSet ).getRowMeta();

  return lookupRowSet;
}
 
Example 5
@Test
public void testGetValueFromResultSet() throws Exception {
  Object rtn = null;
  ResultSet resultSet = Mockito.mock( ResultSet.class );
  ResultSetMetaData metaData = Mockito.mock( ResultSetMetaData.class );
  Mockito.when( resultSet.getMetaData() ).thenReturn( metaData );

  Mockito.when( resultSet.getTimestamp( 1 ) ).thenReturn( new java.sql.Timestamp( 65535 ) );
  Mockito.when( resultSet.getTime( 2 ) ).thenReturn( new java.sql.Time( 1000 ) );
  Mockito.when( resultSet.getTimestamp( 3 ) ).thenReturn( new java.sql.Timestamp( 65535 ) ); // ValueMetaDate -> Timestamp
  ValueMetaTimestamp ts = new ValueMetaTimestamp( "FOO" );
  ts.setOriginalColumnType( java.sql.Types.TIMESTAMP );
  ValueMetaDate tm = new ValueMetaDate( "BAR" );
  tm.setOriginalColumnType( java.sql.Types.TIME );
  ValueMetaDate dt = new ValueMetaDate( "WIBBLE" );
  dt.setOriginalColumnType( java.sql.Types.DATE );

  rtn = nativeMeta.getValueFromResultSet( resultSet, ts, 0 );
  assertNotNull( rtn );
  assertEquals( "java.sql.Timestamp", rtn.getClass().getName() );

  rtn = nativeMeta.getValueFromResultSet( resultSet, tm, 1 );
  assertNotNull( rtn );
  assertEquals( "java.sql.Time", rtn.getClass().getName() );

  rtn = nativeMeta.getValueFromResultSet( resultSet, dt, 2 );
  assertNotNull( rtn );
  assertEquals( "java.sql.Timestamp", rtn.getClass().getName() );

  Mockito.when( resultSet.wasNull() ).thenReturn( true );
  rtn = nativeMeta.getValueFromResultSet( resultSet, new ValueMetaString( "WOBBLE" ), 3 );
  assertNull( rtn );

  // Verify that getDate is not called, getTime is called once, and getTimestamp was called 2 times (once for TimeStamp, once for Date)
  Mockito.verify( resultSet, Mockito.times( 0 ) ).getDate( Mockito.anyInt() );
  Mockito.verify( resultSet, Mockito.times( 1 ) ).getTime( Mockito.anyInt() );
  Mockito.verify( resultSet, Mockito.times( 2 ) ).getTimestamp( Mockito.anyInt() );

  // Now that the date stuff is done, validate the behaviors of other aspects of getValueFromResultSet
  Mockito.when( resultSet.wasNull() ).thenReturn( false );
  Mockito.when(  resultSet.getBoolean( 1 ) ).thenReturn( new Boolean( true ) );
  Mockito.when(  resultSet.getDouble( 1 ) ).thenReturn( new Double( 15 ) );
  Mockito.when(  resultSet.getBigDecimal( 1 ) ).thenReturn( new BigDecimal( "15" ) );
  Mockito.when(  resultSet.getLong( 1 ) ).thenReturn( new Long( "15" ) );
  Mockito.when(  resultSet.getString( 1 ) ).thenReturn( "ASTRING" );
  Mockito.when(  resultSet.getBytes( 1 ) ).thenReturn( "ASTRING".getBytes() );
  Blob mockBlob = Mockito.mock( Blob.class );
  byte[] bytes = "FOO".getBytes();
  ByteArrayInputStream bais = new ByteArrayInputStream( bytes );

  Mockito.when( mockBlob.getBinaryStream() ).thenReturn( bais );
  Mockito.when( mockBlob.length() ).thenReturn( new Long( bytes.length ) );
  Mockito.when( mockBlob.getBytes( Mockito.anyLong(), Mockito.anyInt() ) ).thenReturn( bytes );
  Mockito.when(  resultSet.getBlob( 1 ) ).thenReturn( mockBlob );

  rtn = nativeMeta.getValueFromResultSet( resultSet, new ValueMetaBoolean( "FOO" ), 0 );
  assertNotNull( rtn );
  assertTrue( rtn instanceof Boolean );
  rtn = nativeMeta.getValueFromResultSet( resultSet, new ValueMetaNumber( "FOO", 15, 5 ), 0 );
  assertNotNull( rtn );
  assertTrue( rtn instanceof Double );
  rtn = nativeMeta.getValueFromResultSet( resultSet, new ValueMetaBigNumber( "FOO", 15, 5 ), 0 );
  assertNotNull( rtn );
  assertTrue( rtn instanceof BigDecimal );
  rtn = nativeMeta.getValueFromResultSet( resultSet, new ValueMetaInteger( "FOO", 5, 0 ), 0 );
  assertNotNull( rtn );
  assertTrue( rtn instanceof Long );
  rtn = nativeMeta.getValueFromResultSet( resultSet, new ValueMetaString( "FOO", 25, 0 ), 0 );
  assertNotNull( rtn );
  assertTrue( rtn instanceof String );

  ValueMetaString binStr = new ValueMetaString( "FOO" );
  binStr.setStorageType( ValueMetaString.STORAGE_TYPE_BINARY_STRING );
  rtn = nativeMeta.getValueFromResultSet( resultSet, binStr, 0 );
  assertNotNull( rtn );
  assertTrue( rtn instanceof byte[] );

  rtn = nativeMeta.getValueFromResultSet( resultSet, new ValueMetaBinary( "FOO", 150, 0 ), 0 );
  assertNotNull( rtn );
  assertTrue( rtn instanceof byte[] );

  try {
    Mockito.when(  resultSet.getBoolean( 15 ) ).thenThrow( new SQLException( "Expected Exception Here" ) );
    rtn = nativeMeta.getValueFromResultSet( resultSet, new ValueMetaBoolean( "FOO" ), 14 );
    fail( "Should not get here" );
  } catch ( Exception someException ) {
    assertTrue( someException instanceof KettleDatabaseException );
  }

}