Java Code Examples for org.pentaho.di.job.JobMeta#addDatabase()

The following examples show how to use org.pentaho.di.job.JobMeta#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: JobEntryDialog_ConnectionLine_Test.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void test_showDbDialogUnlessCancelledOrValid_ShownOnce( String inputName,
                                                                String expectedResult ) throws Exception {
  DatabaseDialog databaseDialog = mock( DatabaseDialog.class );
  when( databaseDialog.open() ).thenReturn( inputName );

  JobMeta jobMeta = new JobMeta();
  DatabaseMeta db = createDefaultDatabase();
  jobMeta.addDatabase( db );

  JobEntryDialog dialog = mock( JobEntryDialog.class );
  dialog.databaseDialog = databaseDialog;
  dialog.jobMeta = jobMeta;
  when( dialog.showDbDialogUnlessCancelledOrValid( anyDbMeta(), anyDbMeta() ) ).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: SharedObjectSyncUtilTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void synchronizeConnections_should_not_sync_unshared() throws Exception {
  final String databaseName = "DB";
  JobMeta job1 = createJobMeta();
  DatabaseMeta sharedDB1 = createDatabaseMeta( databaseName, true );
  job1.addDatabase( sharedDB1 );
  spoonDelegates.jobs.addJob( job1 );
  DatabaseMeta db2 = createDatabaseMeta( databaseName, false );
  JobMeta job2 = createJobMeta();
  spoonDelegates.jobs.addJob( job2 );
  job2.addDatabase( db2 );

  db2.setHostname( AFTER_SYNC_VALUE );
  sharedUtil.synchronizeConnections( db2, db2.getName() );
  assertThat( sharedDB1.getHostname(), equalTo( BEFORE_SYNC_VALUE ) );
}
 
Example 3
Source File: JobEntryDialog_ConnectionLine_Test.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void ignores_WhenConnectionNameIsUsed() throws Exception {
  JobMeta jobMeta = new JobMeta();
  jobMeta.addDatabase( createDefaultDatabase() );

  invokeAddConnectionListener( jobMeta, null );

  assertOnlyDbExists( jobMeta, INITIAL_NAME, INITIAL_HOST );
}
 
Example 4
Source File: JobEntryDialog_ConnectionLine_Test.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void edits_WhenNotRenamed() throws Exception {
  JobMeta jobMeta = new JobMeta();
  jobMeta.addDatabase( createDefaultDatabase() );

  invokeEditConnectionListener( jobMeta, INITIAL_NAME );

  assertOnlyDbExists( jobMeta, INITIAL_NAME, INPUT_HOST );
}
 
Example 5
Source File: JobEntryDialog_ConnectionLine_Test.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void edits_WhenNewNameIsUnique() throws Exception {
  JobMeta jobMeta = new JobMeta();
  jobMeta.addDatabase( createDefaultDatabase() );

  invokeEditConnectionListener( jobMeta, INPUT_NAME );

  assertOnlyDbExists( jobMeta, INPUT_NAME, INPUT_HOST );
}
 
Example 6
Source File: JobEntryDialog_ConnectionLine_Test.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void ignores_WhenNewNameIsUsed() throws Exception {
  JobMeta jobMeta = new JobMeta();
  jobMeta.addDatabase( createDefaultDatabase() );

  invokeEditConnectionListener( jobMeta, null );

  assertOnlyDbExists( jobMeta, INITIAL_NAME, INITIAL_HOST );
}
 
Example 7
Source File: JobEntryDialog_ConnectionLine_Test.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void showDbDialog_LoopsUntilUniqueValueIsInput() throws Exception {
  DatabaseMeta db1 = createDefaultDatabase();

  DatabaseMeta db2 = createDefaultDatabase();
  db2.setName( INPUT_NAME );

  JobMeta jobMeta = new JobMeta();
  jobMeta.addDatabase( db1 );
  jobMeta.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 );


  JobEntryDialog dialog = mock( JobEntryDialog.class );
  dialog.databaseDialog = databaseDialog;
  dialog.jobMeta = jobMeta;
  when( dialog.showDbDialogUnlessCancelledOrValid( anyDbMeta(), anyDbMeta() ) ).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 8
Source File: SharedObjectSyncUtilTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void synchronizeConnections_sync_shared_only() throws Exception {
  final String databaseName = "DB";
  DatabaseMeta sharedDB0 = createDatabaseMeta( databaseName, true );

  saveSharedObjects( SHARED_OBJECTS_FILE, sharedDB0 );

  JobMeta job1 = createJobMeta();
  DatabaseMeta sharedDB1 = job1.getDatabase( 0 );

  spoonDelegates.jobs.addJob( job1 );

  DatabaseMeta unsharedDB2 = createDatabaseMeta( databaseName, false );
  JobMeta job2 = createJobMeta();
  spoonDelegates.jobs.addJob( job2 );
  job2.removeDatabase( 0 );
  job2.addDatabase( unsharedDB2 );

  JobMeta job3 = createJobMeta();
  DatabaseMeta sharedDB3 = job3.getDatabase( 0 );
  spoonDelegates.jobs.addJob( job3 );
  job3.addDatabase( sharedDB3 );

  sharedDB3.setHostname( AFTER_SYNC_VALUE );
  sharedUtil.synchronizeConnections( sharedDB3, sharedDB3.getName() );
  assertThat( sharedDB1.getHostname(), equalTo( AFTER_SYNC_VALUE ) );
  assertThat( unsharedDB2.getHostname(), equalTo( BEFORE_SYNC_VALUE ) );
}
 
Example 9
Source File: SharedObjectSyncUtilTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void synchronizeConnections_use_case_sensitive_name() throws Exception {
  JobMeta job1 = createJobMeta();
  DatabaseMeta sharedDB1 = createDatabaseMeta( "DB", true );
  job1.addDatabase( sharedDB1 );
  spoonDelegates.jobs.addJob( job1 );
  DatabaseMeta sharedDB2 = createDatabaseMeta( "Db", true );
  JobMeta job2 = createJobMeta();
  spoonDelegates.jobs.addJob( job2 );
  job2.addDatabase( sharedDB2 );

  sharedDB2.setHostname( AFTER_SYNC_VALUE );
  sharedUtil.synchronizeConnections( sharedDB2, sharedDB2.getName() );
  assertThat( sharedDB1.getHostname(), equalTo( BEFORE_SYNC_VALUE ) );
}
 
Example 10
Source File: StreamToJobNodeConverter.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void saveSharedObjects( final Repository repo, final RepositoryElementInterface element )
  throws KettleException {
  JobMeta jobMeta = (JobMeta) element;
  // First store the databases and other depending objects in the transformation.
  List<String> databaseNames = Arrays.asList( repo.getDatabaseNames( true ) );

  int dbIndex = 0;
  int indexToReplace = 0;
  boolean updateMeta = Boolean.FALSE;

  for ( DatabaseMeta databaseMeta : jobMeta.getDatabases() ) {
    if ( !databaseNames.contains( databaseMeta.getName() ) ) {
      if ( databaseMeta.getObjectId() == null || !StringUtils.isEmpty( databaseMeta.getHostname() ) ) {
        repo.save( databaseMeta, null, null );
      }
    } else if ( databaseMeta.getObjectId() == null ) {
      indexToReplace = dbIndex;
      updateMeta = Boolean.TRUE;
    }

    dbIndex++;
  }

  // if db already exists in repo, get that object id and put it
  // in the transMeta db collection
  if ( updateMeta ) {
    DatabaseMeta dbMetaToReplace = jobMeta.getDatabase( indexToReplace );
    dbMetaToReplace.setObjectId( repo.getDatabaseID( dbMetaToReplace.getName() ) );
    jobMeta.removeDatabase( indexToReplace );
    jobMeta.addDatabase( dbMetaToReplace );
  }
  // Store the slave servers...
  //
  for ( SlaveServer slaveServer : jobMeta.getSlaveServers() ) {
    if ( slaveServer.getObjectId() == null ) {
      repo.save( slaveServer, null, null );
    }
  }

}
 
Example 11
Source File: JobHasJobLogConfiguredImportRuleIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void testRule() throws Exception {

    JobMeta jobMeta = new JobMeta();
    DatabaseMeta logDbMeta =
      new DatabaseMeta( "LOGDB", "MYSQL", "JDBC", "localhost", "test", "3306", "foo", "bar" );
    jobMeta.addDatabase( logDbMeta );
    JobLogTable logTable = jobMeta.getJobLogTable();

    PluginRegistry registry = PluginRegistry.getInstance();

    PluginInterface plugin = registry.findPluginWithId( ImportRulePluginType.class, "JobHasJobLogConfigured" );
    assertNotNull(
      "The 'job has job log table configured' rule could not be found in the plugin registry!", plugin );

    JobHasJobLogConfiguredImportRule rule = (JobHasJobLogConfiguredImportRule) registry.loadClass( plugin );
    assertNotNull(
      "The 'job has job log table configured' class could not be loaded by the plugin registry!", plugin );

    rule.setEnabled( true );

    List<ImportValidationFeedback> feedback = rule.verifyRule( jobMeta );
    assertTrue( "We didn't get any feedback from the 'job has job 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( jobMeta );
    assertTrue( "We didn't get any feedback from the 'job 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( jobMeta );
    assertTrue( "We didn't get any feedback from the 'job 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( jobMeta );
    assertTrue( "We didn't get any feedback from the 'job 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( jobMeta );
    assertTrue( "We didn't get any feedback from the 'job 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( jobMeta );
    assertTrue( "We didn't get any feedback from the 'job 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( jobMeta );
    assertTrue(
      "We didn't expect any feedback from the 'job has job log table configured' since the rule is not enabled",
      feedback.isEmpty() );
  }