Java Code Examples for org.pentaho.di.core.row.value.ValueMetaFactory#pluginRegistry()

The following examples show how to use org.pentaho.di.core.row.value.ValueMetaFactory#pluginRegistry() . 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 File: RestorePDIEnvironment.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
void cleanUp() {
    KettleClientEnvironment.reset();
    PluginRegistry.getInstance().reset();
    MetricsRegistry.getInstance().reset();
    ExtensionPointMap.getInstance().reset();
    if ( KettleLogStore.isInitialized() ) {
      KettleLogStore.getInstance().reset();
    }
    KettleLogStore.setLogChannelInterfaceFactory( new LogChannelFactory() );
    if ( Props.isInitialized() ) {
      Props.getInstance().reset();
    }
    KettleVFS.getInstance().reset();
    XMLHandlerCache.getInstance().clear();
    ValueMetaFactory.pluginRegistry = PluginRegistry.getInstance();
    // under no circumstance reset the LoggingRegistry
//    LoggingRegistry.getInstance().reset();
  }
 
Example 2
Source File: ValueMetaAndDataTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
@PrepareForTest( { EnvUtil.class } )
public void testLoadXML() throws ParseException, KettleXMLException {
  PowerMockito.mockStatic( EnvUtil.class );
  Mockito.when( EnvUtil.getSystemProperty( Const.KETTLE_DEFAULT_DATE_FORMAT ) )
    .thenReturn( "yyyy-MM-dd HH:mm:ss.SSS" );
  ValueMetaAndData valueMetaAndData = new ValueMetaAndData( Mockito.mock( ValueMetaInterface.class ), new Object() );
  List<PluginInterface> pluginTypeList = new ArrayList<>();
  PluginInterface plugin = Mockito.mock( PluginInterface.class );
  Mockito.when( plugin.getName() ).thenReturn( "3" );
  String[] ids = { "3" };
  Mockito.when( plugin.getIds() ).thenReturn( ids );
  pluginTypeList.add( plugin );
  Mockito.when( pluginRegistry.getPlugins( ValueMetaPluginType.class ) ).thenReturn( pluginTypeList );
  ValueMetaFactory.pluginRegistry = pluginRegistry;

  String testData = "2010/01/01 00:00:00.000";
  Node node = XMLHandler.loadXMLString(
    "<value>\n"
      + "    <name/>\n"
      + "    <type>3</type>\n"
      + "    <text>" + testData + "</text>\n"
      + "    <length>-1</length>\n"
      + "    <precision>-1</precision>\n"
      + "    <isnull>N</isnull>\n"
      + "    <mask/>\n"
      + "</value>", "value" );

  valueMetaAndData.loadXML( node );
  Assert.assertEquals( valueMetaAndData.getValueData(),
    new SimpleDateFormat( ValueMetaBase.COMPATIBLE_DATE_FORMAT_PATTERN ).parse( testData ) );
}
 
Example 3
Source File: ExcelInputDialogTest.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Test
/**
 * http://jira.pentaho.com/browse/PDI-13930
 */
public void getFieldsTest() throws Exception {
  ExcelInputDialog dialog = Mockito.mock( ExcelInputDialog.class );
  RowMeta fields = new RowMeta();

  ExcelInputMeta info = Mockito.mock( ExcelInputMeta.class );
  Mockito.doReturn( true ).when( info ).readAllSheets();
  int[] startColumn = {0};
  Mockito.doReturn( startColumn ).when( info ).getStartColumn();
  int[] startRow = {0};
  Mockito.doReturn( startRow ).when( info ).getStartRow();


  KWorkbook workbook =  Mockito.mock( KWorkbook.class );
  Mockito.doReturn( 1 ).when( workbook ).getNumberOfSheets();
  KSheet sheet = Mockito.mock( KSheet.class );
  Mockito.doReturn( sheet ).when( workbook ).getSheet( 0 );
  KCell cell  = Mockito.mock( KCell.class );
  int fieldCount = 400;
  for ( int i = 0; i <= fieldCount - 1; i++ ) {
    Mockito.doReturn( cell ).when( sheet ).getCell( i, 0 );
    Mockito.doReturn( cell ).when( sheet ).getCell( i, 1 );
  }
  Mockito.doReturn( "testValue" ).when( cell ).getContents();
  Mockito.doReturn( KCellType.NUMBER ).when( cell ).getType();

  PluginRegistry pluginRegistry = Mockito.mock( PluginRegistry.class );
  PluginInterface stringPlugin = Mockito.mock( PluginInterface.class );
  Mockito.doReturn( stringPlugin ).when( pluginRegistry ).getPlugin( ValueMetaPluginType.class, "1" );
  Mockito.doReturn( Mockito.mock( ValueMetaInterface.class ) ).when( pluginRegistry ).
          loadClass( stringPlugin, ValueMetaInterface.class );
  ValueMetaFactory.pluginRegistry = pluginRegistry;


  Method processingWorkbookMethod = ExcelInputDialog.class.getDeclaredMethod( "processingWorkbook", RowMetaInterface.class,
          ExcelInputMeta.class, KWorkbook.class );
  processingWorkbookMethod.setAccessible( true );
  processingWorkbookMethod.invoke( dialog, fields, info, workbook );

  Assert.assertEquals( fieldCount, fields.size() );
}