Java Code Examples for org.pentaho.di.trans.TransMeta#addDatabase()
The following examples show how to use
org.pentaho.di.trans.TransMeta#addDatabase() .
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: BaseStepDialog_ConnectionLine_Test.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private void test_showDbDialogUnlessCancelledOrValid_ShownOnce( String inputName, String expectedResult ) throws Exception { DatabaseDialog databaseDialog = mock( DatabaseDialog.class ); when( databaseDialog.open() ).thenReturn( inputName ); when( databaseDialog.getDatabaseMeta() ).thenReturn( createDefaultDatabase() ); TransMeta transMeta = new TransMeta(); DatabaseMeta db = createDefaultDatabase(); transMeta.addDatabase( db ); BaseStepDialog dialog = mock( BaseStepDialog.class ); dialog.databaseDialog = databaseDialog; dialog.transMeta = transMeta; when( dialog.showDbDialogUnlessCancelledOrValid( anyDbMeta(), anyDbMeta() ) ).thenCallRealMethod(); when( dialog.getDatabaseDialog( any( Shell.class ) ) ).thenCallRealMethod(); String result = dialog.showDbDialogUnlessCancelledOrValid( (DatabaseMeta) db.clone(), db ); assertEquals( expectedResult, result ); // database dialog should be shown only once verify( databaseDialog, times( 1 ) ).open(); }
Example 2
Source File: DatabaseIT.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public Database setupDatabase2() throws Exception { // Create a new transformation... TransMeta transMeta = new TransMeta(); transMeta.setName( "transname" ); // Add the database connections DatabaseMeta databaseMeta = new DatabaseMeta( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<connection>" + "<name>db2</name>" + "<server>10.12.4.1</server>" + "<type>H2</type>" + "<access>Native</access>" + "<database>mem:db2</database>" + "<port></port>" + "<username>sa</username>" + "<password></password>" + "</connection>" ); transMeta.addDatabase( databaseMeta ); Database database = new Database( transMeta, databaseMeta ); return database; }
Example 3
Source File: DatabaseIT.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public Database setupPoolingDatabaseWOConnect() throws Exception { // Create a new transformation... TransMeta transMeta = new TransMeta(); transMeta.setName( "transname" ); DatabaseMeta dbInfo = new DatabaseMeta( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<connection>\n" + "<name>db_pool</name>\n" + "<server>127.0.0.1</server>\n" + "<type>H2</type>\n" + "<access>Native</access>\n" + "<database>mem:db</database>\n" + "<port></port>\n" + "<username>sa</username>\n" + "<password></password>\n" + "<attributes>\n" + "<attribute><code>INITIAL_POOL_SIZE</code><attribute>5</attribute></attribute>\n" + "<attribute><code>IS_CLUSTERED</code><attribute>N</attribute></attribute>\n" + "<attribute><code>MAXIMUM_POOL_SIZE</code><attribute>10</attribute></attribute>\n" + "<attribute><code>USE_POOLING</code><attribute>Y</attribute></attribute>\n" + "</attributes>\n" + "</connection>" ); // Add the database connections transMeta.addDatabase( dbInfo ); Database database = new Database( transMeta, dbInfo ); return database; }
Example 4
Source File: BaseStepDialog_ConnectionLine_Test.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void ignores_WhenConnectionNameIsUsed() throws Exception { TransMeta transMeta = new TransMeta(); transMeta.addDatabase( createDefaultDatabase() ); invokeAddConnectionListener( transMeta, null ); assertOnlyDbExists( transMeta, INITIAL_NAME, INITIAL_HOST ); }
Example 5
Source File: BaseStepDialog_ConnectionLine_Test.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void ignores_WhenNewNameIsUsed() throws Exception { TransMeta transMeta = new TransMeta(); transMeta.addDatabase( createDefaultDatabase() ); invokeEditConnectionListener( transMeta, null ); assertOnlyDbExists( transMeta, INITIAL_NAME, INITIAL_HOST ); }
Example 6
Source File: BaseStepDialog_ConnectionLine_Test.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void edits_WhenNotRenamed() throws Exception { TransMeta transMeta = new TransMeta(); transMeta.addDatabase( createDefaultDatabase() ); invokeEditConnectionListener( transMeta, INITIAL_NAME ); assertOnlyDbExists( transMeta, INITIAL_NAME, INPUT_HOST ); }
Example 7
Source File: ExecSQLRowIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Basic Test case for Exec SQL Row. This tests a commit size of two (i.e. not autocommit and not the input row size) */ @Test public void testExecSQLRow3() throws Exception { KettleEnvironment.init(); // // Create a new transformation... // TransMeta transMeta = new TransMeta(); transMeta.setName( "transname" ); // Add the database connections for ( int i = 0; i < databasesXML.length; i++ ) { DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] ); transMeta.addDatabase( databaseMeta ); } DatabaseMeta dbInfo = transMeta.findDatabase( "db" ); PluginRegistry registry = PluginRegistry.getInstance(); // // create an injector step... // String injectorStepname = "injector step"; InjectorMeta im = new InjectorMeta(); // Set the information of the injector. String injectorPid = registry.getPluginId( StepPluginType.class, im ); StepMeta injectorStep = new StepMeta( injectorPid, injectorStepname, im ); transMeta.addStep( injectorStep ); // // create the Exec SQL Row step... // String stepName = "delete from [" + execsqlrow_testtable + "]"; ExecSQLRowMeta execsqlmeta = new ExecSQLRowMeta(); execsqlmeta.setDatabaseMeta( transMeta.findDatabase( "db" ) ); execsqlmeta.setCommitSize( 2 ); execsqlmeta.setSqlFieldName( "SQL" ); String execSqlRowId = registry.getPluginId( StepPluginType.class, execsqlmeta ); StepMeta execSqlRowStep = new StepMeta( execSqlRowId, stepName, execsqlmeta ); execSqlRowStep.setDescription( "Deletes information from table [" + execsqlrow_testtable + "] on database [" + dbInfo + "]" ); transMeta.addStep( execSqlRowStep ); TransHopMeta hi = new TransHopMeta( injectorStep, execSqlRowStep ); transMeta.addTransHop( hi ); // Now execute the transformation... Trans trans = new Trans( transMeta ); trans.prepareExecution( null ); StepInterface si = trans.getStepInterface( stepName, 0 ); RowStepCollector rc = new RowStepCollector(); si.addRowListener( rc ); RowProducer rp = trans.addRowProducer( injectorStepname, 0 ); trans.startThreads(); // add rows List<RowMetaAndData> inputList = createDataRows(); for ( RowMetaAndData rm : inputList ) { rp.putRow( rm.getRowMeta(), rm.getData() ); } rp.finished(); trans.waitUntilFinished(); List<RowMetaAndData> resultRows = rc.getRowsWritten(); List<RowMetaAndData> goldRows = createResultDataRows(); checkRows( goldRows, resultRows ); }
Example 8
Source File: ExecSQLRowIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Basic Test case for Exec SQL Row. This tests a commit size of three (i.e. not autocommit but equal to input row * size) */ @Test public void testExecSQLRow4() throws Exception { KettleEnvironment.init(); // // Create a new transformation... // TransMeta transMeta = new TransMeta(); transMeta.setName( "transname" ); // Add the database connections for ( int i = 0; i < databasesXML.length; i++ ) { DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] ); transMeta.addDatabase( databaseMeta ); } DatabaseMeta dbInfo = transMeta.findDatabase( "db" ); PluginRegistry registry = PluginRegistry.getInstance(); // // create an injector step... // String injectorStepname = "injector step"; InjectorMeta im = new InjectorMeta(); // Set the information of the injector. String injectorPid = registry.getPluginId( StepPluginType.class, im ); StepMeta injectorStep = new StepMeta( injectorPid, injectorStepname, im ); transMeta.addStep( injectorStep ); // // create the Exec SQL Row step... // String stepName = "delete from [" + execsqlrow_testtable + "]"; ExecSQLRowMeta execsqlmeta = new ExecSQLRowMeta(); execsqlmeta.setDatabaseMeta( transMeta.findDatabase( "db" ) ); execsqlmeta.setCommitSize( 3 ); execsqlmeta.setSqlFieldName( "SQL" ); String execSqlRowId = registry.getPluginId( StepPluginType.class, execsqlmeta ); StepMeta execSqlRowStep = new StepMeta( execSqlRowId, stepName, execsqlmeta ); execSqlRowStep.setDescription( "Deletes information from table [" + execsqlrow_testtable + "] on database [" + dbInfo + "]" ); transMeta.addStep( execSqlRowStep ); TransHopMeta hi = new TransHopMeta( injectorStep, execSqlRowStep ); transMeta.addTransHop( hi ); // Now execute the transformation... Trans trans = new Trans( transMeta ); trans.prepareExecution( null ); StepInterface si = trans.getStepInterface( stepName, 0 ); RowStepCollector rc = new RowStepCollector(); si.addRowListener( rc ); RowProducer rp = trans.addRowProducer( injectorStepname, 0 ); trans.startThreads(); // add rows List<RowMetaAndData> inputList = createDataRows(); for ( RowMetaAndData rm : inputList ) { rp.putRow( rm.getRowMeta(), rm.getData() ); } rp.finished(); trans.waitUntilFinished(); List<RowMetaAndData> resultRows = rc.getRowsWritten(); List<RowMetaAndData> goldRows = createResultDataRows(); checkRows( goldRows, resultRows ); }
Example 9
Source File: ExecSQLRowIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Basic Test case for Exec SQL Row. This tests a commit size of one (i.e. "simulated" autocommit) */ @Test public void testExecSQLRow2() throws Exception { KettleEnvironment.init(); // // Create a new transformation... // TransMeta transMeta = new TransMeta(); transMeta.setName( "transname" ); // Add the database connections for ( int i = 0; i < databasesXML.length; i++ ) { DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] ); transMeta.addDatabase( databaseMeta ); } DatabaseMeta dbInfo = transMeta.findDatabase( "db" ); PluginRegistry registry = PluginRegistry.getInstance(); // // create an injector step... // String injectorStepname = "injector step"; InjectorMeta im = new InjectorMeta(); // Set the information of the injector. String injectorPid = registry.getPluginId( StepPluginType.class, im ); StepMeta injectorStep = new StepMeta( injectorPid, injectorStepname, im ); transMeta.addStep( injectorStep ); // // create the Exec SQL Row step... // String stepName = "delete from [" + execsqlrow_testtable + "]"; ExecSQLRowMeta execsqlmeta = new ExecSQLRowMeta(); execsqlmeta.setDatabaseMeta( transMeta.findDatabase( "db" ) ); execsqlmeta.setCommitSize( 1 ); execsqlmeta.setSqlFieldName( "SQL" ); String execSqlRowId = registry.getPluginId( StepPluginType.class, execsqlmeta ); StepMeta execSqlRowStep = new StepMeta( execSqlRowId, stepName, execsqlmeta ); execSqlRowStep.setDescription( "Deletes information from table [" + execsqlrow_testtable + "] on database [" + dbInfo + "]" ); transMeta.addStep( execSqlRowStep ); TransHopMeta hi = new TransHopMeta( injectorStep, execSqlRowStep ); transMeta.addTransHop( hi ); // Now execute the transformation... Trans trans = new Trans( transMeta ); trans.prepareExecution( null ); StepInterface si = trans.getStepInterface( stepName, 0 ); RowStepCollector rc = new RowStepCollector(); si.addRowListener( rc ); RowProducer rp = trans.addRowProducer( injectorStepname, 0 ); trans.startThreads(); // add rows List<RowMetaAndData> inputList = createDataRows(); for ( RowMetaAndData rm : inputList ) { rp.putRow( rm.getRowMeta(), rm.getData() ); } rp.finished(); trans.waitUntilFinished(); List<RowMetaAndData> resultRows = rc.getRowsWritten(); List<RowMetaAndData> goldRows = createResultDataRows(); checkRows( goldRows, resultRows ); }
Example 10
Source File: InsertUpdateIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@Override @Before public void setUp() throws Exception { KettleEnvironment.init(); /* SET UP TRANSFORMATION */ // Create a new transformation... TransMeta transMeta = new TransMeta(); transMeta.setName( "insert/update test" ); // Add the database connections for ( int i = 0; i < databasesXML.length; i++ ) { DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] ); transMeta.addDatabase( databaseMeta ); } DatabaseMeta dbInfo = transMeta.findDatabase( "db" ); /* SET UP DATABASE */ // Create target table db = new Database( transMeta, dbInfo ); db.connect(); String source = db.getCreateTableStatement( TARGET_TABLE, getTargetTableRowMeta(), null, false, null, true ); db.execStatement( source ); // populate target table for ( String sql : insertStatement ) { db.execStatement( sql ); } /* SET UP TRANSFORMATION STEPS */ PluginRegistry registry = PluginRegistry.getInstance(); // create an injector step... String injectorStepName = "injector step"; InjectorMeta im = new InjectorMeta(); // Set the information of the injector. String injectorPid = registry.getPluginId( StepPluginType.class, im ); StepMeta injectorStep = new StepMeta( injectorPid, injectorStepName, im ); transMeta.addStep( injectorStep ); // create the update step... String updateStepName = "insert/update [" + TARGET_TABLE + "]"; insupd = new InsertUpdateMeta(); insupd.setDatabaseMeta( transMeta.findDatabase( "db" ) ); insupd.setTableName( TARGET_TABLE ); insupd.setUpdateLookup( new String[] { "VALUE", "ROW_ORDER" } ); insupd.setUpdateStream( new String[] { "VALUE", "ROW_ORDER" } ); insupd.setUpdate( new Boolean[] { true, false } ); String fromid = registry.getPluginId( StepPluginType.class, insupd ); StepMeta updateStep = new StepMeta( fromid, updateStepName, insupd ); updateStep.setDescription( "insert/update data in table [" + TARGET_TABLE + "] on database [" + dbInfo + "]" ); transMeta.addStep( updateStep ); TransHopMeta hi = new TransHopMeta( injectorStep, updateStep ); transMeta.addTransHop( hi ); /* PREPARE TRANSFORMATION EXECUTION */ trans = new Trans( transMeta ); trans.prepareExecution( null ); StepInterface si = trans.getStepInterface( updateStepName, 0 ); rc = new RowStepCollector(); si.addRowListener( rc ); rp = trans.addRowProducer( injectorStepName, 0 ); }
Example 11
Source File: ExecSQLRowIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Basic Test case for Exec SQL Row. This tests a commit size of zero (i.e. autocommit) */ @Test public void testExecSQLRow1() throws Exception { KettleEnvironment.init(); // // Create a new transformation... // TransMeta transMeta = new TransMeta(); transMeta.setName( "transname" ); // Add the database connections for ( int i = 0; i < databasesXML.length; i++ ) { DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] ); transMeta.addDatabase( databaseMeta ); } DatabaseMeta dbInfo = transMeta.findDatabase( "db" ); PluginRegistry registry = PluginRegistry.getInstance(); // // create an injector step... // String injectorStepname = "injector step"; InjectorMeta im = new InjectorMeta(); // Set the information of the injector. String injectorPid = registry.getPluginId( StepPluginType.class, im ); StepMeta injectorStep = new StepMeta( injectorPid, injectorStepname, im ); transMeta.addStep( injectorStep ); // // create the Exec SQL Row step... // String stepName = "delete from [" + execsqlrow_testtable + "]"; ExecSQLRowMeta execsqlmeta = new ExecSQLRowMeta(); execsqlmeta.setDatabaseMeta( transMeta.findDatabase( "db" ) ); execsqlmeta.setCommitSize( 0 ); // use Autocommit execsqlmeta.setSqlFieldName( "SQL" ); String execSqlRowId = registry.getPluginId( StepPluginType.class, execsqlmeta ); StepMeta execSqlRowStep = new StepMeta( execSqlRowId, stepName, execsqlmeta ); execSqlRowStep.setDescription( "Deletes information from table [" + execsqlrow_testtable + "] on database [" + dbInfo + "]" ); transMeta.addStep( execSqlRowStep ); TransHopMeta hi = new TransHopMeta( injectorStep, execSqlRowStep ); transMeta.addTransHop( hi ); // Now execute the transformation... Trans trans = new Trans( transMeta ); trans.prepareExecution( null ); StepInterface si = trans.getStepInterface( stepName, 0 ); RowStepCollector rc = new RowStepCollector(); si.addRowListener( rc ); RowProducer rp = trans.addRowProducer( injectorStepname, 0 ); trans.startThreads(); // add rows List<RowMetaAndData> inputList = createDataRows(); for ( RowMetaAndData rm : inputList ) { rp.putRow( rm.getRowMeta(), rm.getData() ); } rp.finished(); trans.waitUntilFinished(); List<RowMetaAndData> resultRows = rc.getRowsWritten(); List<RowMetaAndData> goldRows = createResultDataRows(); checkRows( goldRows, resultRows ); }
Example 12
Source File: DatabaseLookupIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Basic Test case for database lookup. */ @Test public void basicDatabaseLookup() throws Exception { KettleEnvironment.init(); // // Create a new transformation... // TransMeta transMeta = new TransMeta(); transMeta.setName( "transname" ); // Add the database connections for ( int i = 0; i < databasesXML.length; i++ ) { DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] ); transMeta.addDatabase( databaseMeta ); } DatabaseMeta dbInfo = transMeta.findDatabase( "db" ); PluginRegistry registry = PluginRegistry.getInstance(); // // create an injector step... // String injectorStepname = "injector step"; InjectorMeta im = new InjectorMeta(); // Set the information of the injector. String injectorPid = registry.getPluginId( StepPluginType.class, im ); StepMeta injectorStep = new StepMeta( injectorPid, injectorStepname, im ); transMeta.addStep( injectorStep ); // // create the lookup step... // String lookupName = "look up from [" + lookup_table + "]"; DatabaseLookupMeta dbl = new DatabaseLookupMeta(); dbl.setDatabaseMeta( transMeta.findDatabase( "db" ) ); dbl.setTablename( lookup_table ); dbl.setCached( false ); dbl.setEatingRowOnLookupFailure( false ); dbl.setFailingOnMultipleResults( false ); dbl.setOrderByClause( "" ); dbl.setTableKeyField( new String[] { "ID" } ); dbl.setKeyCondition( new String[] { "=" } ); dbl.setStreamKeyField1( new String[] { "int_field" } ); dbl.setStreamKeyField2( new String[] { "" } ); dbl.setReturnValueField( new String[] { "CODE", "STRING" } ); dbl.setReturnValueDefaultType( new int[] { ValueMetaInterface.TYPE_INTEGER, ValueMetaInterface.TYPE_STRING } ); dbl.setReturnValueDefault( new String[] { "-1", "UNDEF" } ); dbl.setReturnValueNewName( new String[] { "RET_CODE", "RET_STRING" } ); String lookupId = registry.getPluginId( StepPluginType.class, dbl ); StepMeta lookupStep = new StepMeta( lookupId, lookupName, dbl ); lookupStep.setDescription( "Reads information from table [" + lookup_table + "] on database [" + dbInfo + "]" ); transMeta.addStep( lookupStep ); TransHopMeta hi = new TransHopMeta( injectorStep, lookupStep ); transMeta.addTransHop( hi ); // Now execute the transformation... Trans trans = new Trans( transMeta ); trans.prepareExecution( null ); StepInterface si = trans.getStepInterface( lookupName, 0 ); RowStepCollector rc = new RowStepCollector(); si.addRowListener( rc ); RowProducer rp = trans.addRowProducer( injectorStepname, 0 ); trans.startThreads(); // add rows List<RowMetaAndData> inputList = createDataRows(); for ( RowMetaAndData rm : inputList ) { rp.putRow( rm.getRowMeta(), rm.getData() ); } rp.finished(); trans.waitUntilFinished(); List<RowMetaAndData> resultRows = rc.getRowsWritten(); List<RowMetaAndData> goldRows = createResultDataRows(); checkRows( goldRows, resultRows ); }
Example 13
Source File: SpoonJobDelegate.java From pentaho-kettle with Apache License 2.0 | 4 votes |
private void setTransMetaDatabase( DatabaseMeta sourceDbInfo, DatabaseMeta targetDbInfo, TransMeta transMeta ) { transMeta.addDatabase( sourceDbInfo ); transMeta.addDatabase( targetDbInfo ); }
Example 14
Source File: BaseStepDialog_ConnectionLine_Test.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@Test public void showDbDialog_LoopsUntilUniqueValueIsInput() throws Exception { DatabaseMeta db1 = createDefaultDatabase(); DatabaseMeta db2 = createDefaultDatabase(); db2.setName( INPUT_NAME ); TransMeta transMeta = new TransMeta(); transMeta.addDatabase( db1 ); transMeta.addDatabase( db2 ); final String expectedResult = INPUT_NAME + "2"; DatabaseDialog databaseDialog = mock( DatabaseDialog.class ); when( databaseDialog.open() ) // duplicate .thenReturn( INPUT_NAME ) // duplicate with spaces .thenReturn( INPUT_NAME + " " ) // duplicate in other case .thenReturn( INPUT_NAME.toUpperCase() ) // unique value .thenReturn( expectedResult ); when( databaseDialog.getDatabaseMeta() ).thenReturn( createDefaultDatabase() ); BaseStepDialog dialog = mock( BaseStepDialog.class ); dialog.databaseDialog = databaseDialog; dialog.transMeta = transMeta; when( dialog.showDbDialogUnlessCancelledOrValid( anyDbMeta(), anyDbMeta() ) ).thenCallRealMethod(); when( dialog.getDatabaseDialog( any( Shell.class ) ) ).thenCallRealMethod(); // try to rename db1 ("qwerty") String result = dialog.showDbDialogUnlessCancelledOrValid( (DatabaseMeta) db1.clone(), db1 ); assertEquals( expectedResult, result ); // database dialog should be shown four times verify( databaseDialog, times( 4 ) ).open(); // and the error message should be shown three times verify( dialog, times( 3 ) ).showDbExistsDialog( anyDbMeta() ); }
Example 15
Source File: DatabaseConfigurationImportRuleIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public void testRule() throws Exception { // Assemble a new database. // String DBNAME = "test"; String HOSTNAME = "localhost"; String PORT = "3306"; String USERNAME = "foo"; String PASSWORD = "bar"; DatabaseMeta verifyMeta = new DatabaseMeta( "LOGDB", "MYSQL", "JDBC", HOSTNAME, DBNAME, PORT, USERNAME, PASSWORD ); // Create a transformation to test. // TransMeta transMeta = new TransMeta(); transMeta.addDatabase( (DatabaseMeta) verifyMeta.clone() ); // Load the plugin to test from the registry. // PluginRegistry registry = PluginRegistry.getInstance(); PluginInterface plugin = registry.findPluginWithId( ImportRulePluginType.class, "DatabaseConfiguration" ); assertNotNull( "The 'database configuration' rule could not be found in the plugin registry!", plugin ); DatabaseConfigurationImportRule rule = (DatabaseConfigurationImportRule) registry.loadClass( plugin ); assertNotNull( "The 'database configuration' class could not be loaded by the plugin registry!", plugin ); // Set the appropriate rule.. // rule.setEnabled( true ); List<ImportValidationFeedback> feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'database configuration'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); rule.setDatabaseMeta( verifyMeta ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An approval ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.APPROVAL ); // Create some errors... // verifyMeta.setDBName( "incorrect-test" ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected validating the db name", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); verifyMeta.setDBName( DBNAME ); verifyMeta.setHostname( "incorrect-hostname" ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected validating the db hostname", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); verifyMeta.setHostname( HOSTNAME ); verifyMeta.setDBPort( "incorrect-port" ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected validating the db port", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); verifyMeta.setDBPort( PORT ); verifyMeta.setUsername( "incorrect-username" ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected validating the db username", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); verifyMeta.setUsername( USERNAME ); verifyMeta.setPassword( "incorrect-password" ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected validating the db password", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); verifyMeta.setPassword( PASSWORD ); // No feedback expected! // rule.setEnabled( false ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't expect any feedback from the 'transformation has trans log table configured' since disabled", feedback.isEmpty() ); }
Example 16
Source File: TableOutputIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Test case for normal table output case. */ @SuppressWarnings( "deprecation" ) public void testTableOutputNormal() throws Exception { KettleEnvironment.init(); // // Create a new transformation... // TransMeta transMeta = new TransMeta(); transMeta.setName( "table output normal test" ); // Add the database connections for ( int i = 0; i < databasesXML.length; i++ ) { DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] ); transMeta.addDatabase( databaseMeta ); } DatabaseMeta dbInfo = transMeta.findDatabase( "db" ); // Execute our setup SQLs in the database. Database database = new Database( transMeta, dbInfo ); database.connect(); createTable( database, target_table, createSourceRowMetaInterface1() ); PluginRegistry registry = PluginRegistry.getInstance(); // // create an injector step... // String injectorStepname = "injector step"; InjectorMeta im = new InjectorMeta(); // Set the information of the injector. String injectorPid = registry.getPluginId( StepPluginType.class, im ); StepMeta injectorStep = new StepMeta( injectorPid, injectorStepname, im ); transMeta.addStep( injectorStep ); // // create the source step... // String outputname = "output to [" + target_table + "]"; TableOutputMeta tom = new TableOutputMeta(); tom.setDatabaseMeta( transMeta.findDatabase( "db" ) ); tom.setTablename( target_table ); String fromid = registry.getPluginId( StepPluginType.class, tom ); StepMeta fromstep = new StepMeta( fromid, outputname, tom ); fromstep.setDescription( "write data to table [" + target_table + "] on database [" + dbInfo + "]" ); transMeta.addStep( fromstep ); TransHopMeta hi = new TransHopMeta( injectorStep, fromstep ); transMeta.addTransHop( hi ); // Now execute the transformation... Trans trans = new Trans( transMeta ); trans.prepareExecution( null ); StepInterface si = trans.getStepInterface( outputname, 0 ); RowStepCollector rc = new RowStepCollector(); si.addRowListener( rc ); RowProducer rp = trans.addRowProducer( injectorStepname, 0 ); trans.startThreads(); // add rows List<RowMetaAndData> inputList = createNormalDataRows(); for ( RowMetaAndData rm : inputList ) { rp.putRow( rm.getRowMeta(), rm.getData() ); } rp.finished(); trans.waitUntilFinished(); List<RowMetaAndData> resultRows = rc.getRowsWritten(); List<RowMetaAndData> goldRows = createNormalDataRows(); checkRows( goldRows, resultRows ); checkResultsNormal( database ); }
Example 17
Source File: TableOutputIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Test case for normal table output where the table is included in the instream, but the tablename is not stored in * the table. */ public void testTableOutputJIRA897() throws Exception { KettleEnvironment.init(); // // Create a new transformation... // TransMeta transMeta = new TransMeta(); transMeta.setName( "table output JIRA897 test" ); // Add the database connections for ( int i = 0; i < databasesXML.length; i++ ) { DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] ); transMeta.addDatabase( databaseMeta ); } DatabaseMeta dbInfo = transMeta.findDatabase( "db" ); // Execute our setup SQLs in the database. Database database = new Database( transMeta, dbInfo ); database.connect(); createTable( database, target_table1, createSourceRowMetaInterface1() ); createTable( database, target_table2, createSourceRowMetaInterface1() ); PluginRegistry registry = PluginRegistry.getInstance(); // // create an injector step... // String injectorStepname = "injector step"; InjectorMeta im = new InjectorMeta(); // Set the information of the injector. String injectorPid = registry.getPluginId( StepPluginType.class, im ); StepMeta injectorStep = new StepMeta( injectorPid, injectorStepname, im ); transMeta.addStep( injectorStep ); // // create the source step... // String outputname = "output to [" + target_table1 + "] and [" + target_table2 + "]"; TableOutputMeta tom = new TableOutputMeta(); tom.setDatabaseMeta( transMeta.findDatabase( "db" ) ); tom.setTableNameInField( true ); tom.setTableNameField( "TABLE" ); tom.setTableNameInTable( false ); String fromid = registry.getPluginId( StepPluginType.class, tom ); StepMeta fromstep = new StepMeta( fromid, outputname, tom ); fromstep.setDescription( "write data to tables on database [" + dbInfo + "]" ); transMeta.addStep( fromstep ); TransHopMeta hi = new TransHopMeta( injectorStep, fromstep ); transMeta.addTransHop( hi ); // Now execute the transformation... Trans trans = new Trans( transMeta ); trans.prepareExecution( null ); StepInterface si = trans.getStepInterface( outputname, 0 ); RowStepCollector rc = new RowStepCollector(); si.addRowListener( rc ); RowProducer rp = trans.addRowProducer( injectorStepname, 0 ); trans.startThreads(); // add rows List<RowMetaAndData> inputList = createJIRA897DataRows(); for ( RowMetaAndData rm : inputList ) { rp.putRow( rm.getRowMeta(), rm.getData() ); } rp.finished(); trans.waitUntilFinished(); List<RowMetaAndData> resultRows = rc.getRowsWritten(); // The name of the table should still be in here. List<RowMetaAndData> goldRows = createJIRA897DataRows(); checkRows( goldRows, resultRows ); checkResultsJIRA897( database ); }
Example 18
Source File: UpdateIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@Override @Before public void setUp() throws Exception { KettleEnvironment.init(); /* SET UP TRANSFORMATION */ // Create a new transformation... TransMeta transMeta = new TransMeta(); transMeta.setName( "update test" ); // Add the database connections for ( int i = 0; i < databasesXML.length; i++ ) { DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] ); transMeta.addDatabase( databaseMeta ); } DatabaseMeta dbInfo = transMeta.findDatabase( "db" ); /* SET UP DATABASE */ // Create target table db = new Database( transMeta, dbInfo ); db.connect(); String source = db.getCreateTableStatement( TARGET_TABLE, getTargetTableRowMeta(), null, false, null, true ); db.execStatement( source ); // populate target table for ( String sql : insertStatement ) { db.execStatement( sql ); } /* SET UP TRANSFORMATION STEPS */ PluginRegistry registry = PluginRegistry.getInstance(); // create an injector step... String injectorStepName = "injector step"; InjectorMeta im = new InjectorMeta(); // Set the information of the injector. String injectorPid = registry.getPluginId( StepPluginType.class, im ); StepMeta injectorStep = new StepMeta( injectorPid, injectorStepName, im ); transMeta.addStep( injectorStep ); // create the update step... String updateStepName = "update [" + TARGET_TABLE + "]"; upd = new UpdateMeta(); upd.setDatabaseMeta( transMeta.findDatabase( "db" ) ); upd.setTableName( TARGET_TABLE ); upd.setUpdateLookup( new String[] { "VALUE" } ); upd.setUpdateStream( new String[] { "VALUE" } ); upd.setErrorIgnored( true ); String fromid = registry.getPluginId( StepPluginType.class, upd ); StepMeta updateStep = new StepMeta( fromid, updateStepName, upd ); updateStep.setDescription( "update data in table [" + TARGET_TABLE + "] on database [" + dbInfo + "]" ); transMeta.addStep( updateStep ); TransHopMeta hi = new TransHopMeta( injectorStep, updateStep ); transMeta.addTransHop( hi ); /* PREPARE TRANSFORMATION EXECUTION */ trans = new Trans( transMeta ); trans.prepareExecution( null ); StepInterface si = trans.getStepInterface( updateStepName, 0 ); rc = new RowStepCollector(); si.addRowListener( rc ); rp = trans.addRowProducer( injectorStepName, 0 ); }
Example 19
Source File: TableInputIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Test case for table input which is taking its input from a hop. This is a regression test case for JIRA PDI-588. * * The query in the table input step has one '?' and this parameter is filled by values read from an input hop. */ public void testTableInputWithParam() throws Exception { KettleEnvironment.init(); // // Create a new transformation... // TransMeta transMeta = new TransMeta(); transMeta.setName( "transname" ); // Add the database connections for ( int i = 0; i < databasesXML.length; i++ ) { DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] ); transMeta.addDatabase( databaseMeta ); } DatabaseMeta dbInfo = transMeta.findDatabase( "db" ); // Execute our setup SQLs in the database. Database database = new Database( transMeta, dbInfo ); database.connect(); createTables( database ); createData( database ); PluginRegistry registry = PluginRegistry.getInstance(); // // create an injector step... // String injectorStepname = "injector step"; InjectorMeta im = new InjectorMeta(); // Set the information of the injector. String injectorPid = registry.getPluginId( StepPluginType.class, im ); StepMeta injectorStep = new StepMeta( injectorPid, injectorStepname, im ); transMeta.addStep( injectorStep ); // // create the source step... // String fromstepname = "read from [" + source_table + "]"; TableInputMeta tii = new TableInputMeta(); tii.setDatabaseMeta( transMeta.findDatabase( "db" ) ); tii.setLookupFromStep( injectorStep ); tii.setExecuteEachInputRow( true ); String selectSQL = "SELECT " + Const.CR; selectSQL += "ID, CODE "; selectSQL += "FROM " + source_table + " WHERE CODE = ? ORDER BY ID, CODE;"; tii.setSQL( selectSQL ); String fromstepid = registry.getPluginId( StepPluginType.class, tii ); StepMeta fromstep = new StepMeta( fromstepid, fromstepname, tii ); fromstep.setDescription( "Reads information from table [" + source_table + "] on database [" + dbInfo + "]" ); transMeta.addStep( fromstep ); TransHopMeta hi = new TransHopMeta( injectorStep, fromstep ); transMeta.addTransHop( hi ); // Now execute the transformation... Trans trans = new Trans( transMeta ); trans.prepareExecution( null ); StepInterface si = trans.getStepInterface( fromstepname, 0 ); RowStepCollector rc = new RowStepCollector(); si.addRowListener( rc ); RowProducer rp = trans.addRowProducer( injectorStepname, 0 ); trans.startThreads(); // add rows List<RowMetaAndData> inputList = createDataRows(); for ( RowMetaAndData rm : inputList ) { rp.putRow( rm.getRowMeta(), rm.getData() ); } rp.finished(); trans.waitUntilFinished(); List<RowMetaAndData> resultRows = rc.getRowsWritten(); List<RowMetaAndData> goldRows = createResultDataRows(); checkRows( goldRows, resultRows ); }
Example 20
Source File: TransformationHasTransLogConfiguredImportRuleIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public void testRule() throws Exception { TransMeta transMeta = new TransMeta(); DatabaseMeta logDbMeta = new DatabaseMeta( "LOGDB", "MYSQL", "JDBC", "localhost", "test", "3306", "foo", "bar" ); transMeta.addDatabase( logDbMeta ); TransLogTable logTable = transMeta.getTransLogTable(); PluginRegistry registry = PluginRegistry.getInstance(); PluginInterface plugin = registry.findPluginWithId( ImportRulePluginType.class, "TransformationHasTransLogConfigured" ); assertNotNull( "The 'transformation has trans log table configured' rule could not be found in the plugin registry!", plugin ); TransformationHasTransLogConfiguredImportRule rule = (TransformationHasTransLogConfiguredImportRule) registry.loadClass( plugin ); assertNotNull( "The 'transformation has trans log table configured' class could not be loaded by the plugin registry!", plugin ); rule.setEnabled( true ); List<ImportValidationFeedback> feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has trans log table configured'", !feedback .isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); logTable.setTableName( "SCHEMA" ); logTable.setTableName( "LOGTABLE" ); logTable.setConnectionName( logDbMeta.getName() ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An approval ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.APPROVAL ); // Make the rules stricter! // rule.setTableName( "SCHEMA" ); rule.setTableName( "LOGTABLE" ); rule.setConnectionName( logDbMeta.getName() ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An approval ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.APPROVAL ); // Break the rule // rule.setSchemaName( "INCORRECT_SCHEMA" ); rule.setTableName( "LOGTABLE" ); rule.setConnectionName( logDbMeta.getName() ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); rule.setSchemaName( "SCHEMA" ); rule.setTableName( "INCORRECT_LOGTABLE" ); rule.setConnectionName( logDbMeta.getName() ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); rule.setSchemaName( "SCHEMA" ); rule.setTableName( "LOGTABLE" ); rule.setConnectionName( "INCORRECT_DATABASE" ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); // No feedback expected! // rule.setEnabled( false ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't expect any feedback from the 'transformation has trans " + "log table configured' since the rule is not enabled", feedback.isEmpty() ); }