Search in sources :

Example 91 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class KettleEnvironmentIT method lifecycleListenerEnvironmentInitCallback_exception_thrown.

/**
 * Validate that a LifecycleListener's environment init callback is called when the Kettle Environment is initialized.
 */
@Test
public void lifecycleListenerEnvironmentInitCallback_exception_thrown() throws Exception {
    resetKettleEnvironmentInitializationFlag();
    assertFalse("This test only works if the Kettle Environment is not yet initialized", KettleEnvironment.isInitialized());
    System.setProperty(Const.KETTLE_PLUGIN_CLASSES, FailingMockLifecycleListener.class.getName());
    KettleEnvironment.init();
    PluginInterface pi = PluginRegistry.getInstance().findPluginWithId(KettleLifecyclePluginType.class, pluginId);
    MockLifecycleListener l = (MockLifecycleListener) PluginRegistry.getInstance().loadClass(pi, KettleLifecycleListener.class);
    assertNotNull("Test plugin not registered properly", l);
    assertTrue(KettleEnvironment.isInitialized());
}
Also used : PluginInterface(org.pentaho.di.core.plugins.PluginInterface) KettleLifecycleListener(org.pentaho.di.core.lifecycle.KettleLifecycleListener) Test(org.junit.Test)

Example 92 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class StringEvaluatorIT method loadValueMetaPlugins.

private void loadValueMetaPlugins() {
    // Need to load the ValueMeta plugins
    PluginRegistry registry = PluginRegistry.getInstance();
    assertNotNull("Registry singleton was not found!", registry);
    // Register a new plugin type...
    // 
    PluginRegistry.addPluginType(ValueMetaPluginType.getInstance());
    // Plugin Registry should initialize without exception
    Exception initException = null;
    try {
        PluginRegistry.init();
    } catch (Exception e) {
        initException = e;
    }
    assertNull(initException);
    // There will always be a PluginRegistryPluginType, so see if we enough plugin types here.
    // 
    List<Class<? extends PluginTypeInterface>> pluginTypes = registry.getPluginTypes();
    assertTrue("At least two plugin types expected in the registry", pluginTypes.size() > 1);
    // ... and have at least 1 ValueMetaPlugin
    List<PluginInterface> valueMetaPlugins = registry.getPlugins(ValueMetaPluginType.class);
    assertTrue("Size of plugins list expected to be >1", valueMetaPlugins.size() > 1);
}
Also used : PluginTypeInterface(org.pentaho.di.core.plugins.PluginTypeInterface) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) ParseException(java.text.ParseException)

Example 93 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class JobHasANoteImportRuleIT method testRule.

public void testRule() throws Exception {
    // Create a job to test.
    // 
    JobMeta jobMeta = new JobMeta();
    NotePadMeta note = new NotePadMeta("A note documenting the transformation", 50, 50, 200, 50);
    jobMeta.addNote(note);
    // Load the plugin to test from the registry.
    // 
    PluginRegistry registry = PluginRegistry.getInstance();
    PluginInterface plugin = registry.findPluginWithId(ImportRulePluginType.class, "JobHasANote");
    assertNotNull("The 'job has a note' rule could not be found in the plugin registry!", plugin);
    JobHasANoteImportRule rule = (JobHasANoteImportRule) registry.loadClass(plugin);
    assertNotNull("The 'job has a note' rule 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 a note'", !feedback.isEmpty());
    assertTrue("An approval ruling was expected", feedback.get(0).getResultType() == ImportValidationResultType.APPROVAL);
    jobMeta.removeNote(0);
    feedback = rule.verifyRule(jobMeta);
    assertTrue("We didn't get any feedback from the 'job has a note' rule", !feedback.isEmpty());
    assertTrue("An error ruling was expected", feedback.get(0).getResultType() == ImportValidationResultType.ERROR);
    rule.setEnabled(false);
    feedback = rule.verifyRule(jobMeta);
    assertTrue("We didn't expect any feedback from the 'job has no note' rule while disabled", feedback.isEmpty());
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) NotePadMeta(org.pentaho.di.core.NotePadMeta) JobHasANoteImportRule(org.pentaho.di.imp.rules.JobHasANoteImportRule)

Example 94 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class JobHasDescriptionImportRuleIT method testRule.

public void testRule() throws Exception {
    JobMeta jobMeta = new JobMeta();
    jobMeta.setDescription("This job is used for testing an import rule");
    PluginRegistry registry = PluginRegistry.getInstance();
    PluginInterface plugin = registry.findPluginWithId(ImportRulePluginType.class, "JobHasDescription");
    assertNotNull("The 'job has description' rule could not be found in the plugin registry!", plugin);
    JobHasDescriptionImportRule rule = (JobHasDescriptionImportRule) registry.loadClass(plugin);
    assertNotNull("The 'job has description rule' class could not be loaded by the plugin registry!", plugin);
    rule.setMinLength(20);
    rule.setEnabled(true);
    List<ImportValidationFeedback> 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);
    rule.setMinLength(2000);
    rule.setEnabled(true);
    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.setEnabled(false);
    feedback = rule.verifyRule(jobMeta);
    assertTrue("We didn't expect any feedback from the 'job has description rule' while disabled", feedback.isEmpty());
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) JobHasDescriptionImportRule(org.pentaho.di.imp.rules.JobHasDescriptionImportRule) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface)

Example 95 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class JobHasJobLogConfiguredImportRuleIT method testRule.

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());
}
Also used : JobHasJobLogConfiguredImportRule(org.pentaho.di.imp.rules.JobHasJobLogConfiguredImportRule) JobMeta(org.pentaho.di.job.JobMeta) JobLogTable(org.pentaho.di.core.logging.JobLogTable) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Aggregations

PluginInterface (org.pentaho.di.core.plugins.PluginInterface)99 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)45 KettleException (org.pentaho.di.core.exception.KettleException)24 ArrayList (java.util.ArrayList)17 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)14 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)12 TransMeta (org.pentaho.di.trans.TransMeta)11 StepMeta (org.pentaho.di.trans.step.StepMeta)11 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)10 Test (org.junit.Test)9 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)9 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)8 Point (org.pentaho.di.core.gui.Point)8 JobMeta (org.pentaho.di.job.JobMeta)8 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)7 TransHopMeta (org.pentaho.di.trans.TransHopMeta)7 TreeItem (org.eclipse.swt.widgets.TreeItem)6 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)6 LongObjectId (org.pentaho.di.repository.LongObjectId)6 ObjectId (org.pentaho.di.repository.ObjectId)6