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());
}
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);
}
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());
}
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());
}
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());
}
Aggregations