use of org.pentaho.di.core.plugins.PluginRegistry in project pentaho-kettle by pentaho.
the class WebServiceIT method testProcessRow.
public void testProcessRow() throws Exception {
KettleEnvironment.init();
//
// Create a new transformation...
//
TransMeta transMeta = new TransMeta();
transMeta.setName("WebServiceTest");
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 a dummy step 1
//
String dummyStepname1 = "dummy step 1";
DummyTransMeta dm1 = new DummyTransMeta();
String dummyPid1 = registry.getPluginId(StepPluginType.class, dm1);
StepMeta dummyStep1 = new StepMeta(dummyPid1, dummyStepname1, dm1);
transMeta.addStep(dummyStep1);
TransHopMeta hi = new TransHopMeta(injectorStep, dummyStep1);
transMeta.addTransHop(hi);
//
// Create a String Cut step
//
String webServiceStepname = "web service step";
WebServiceMeta scm = new WebServiceMeta();
// scm.setUrl(HTTP_LOCALHOST_9998+ "wsdl");
// scm.setOperationName("CelciusToFahrenheit");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(new java.io.StringReader(STEP_META)));
scm.loadXML(doc.getFirstChild(), null, (IMetaStore) null);
String webServicePid = registry.getPluginId(StepPluginType.class, scm);
StepMeta webServiceStep = new StepMeta(webServicePid, webServiceStepname, scm);
transMeta.addStep(webServiceStep);
TransHopMeta hi2 = new TransHopMeta(dummyStep1, webServiceStep);
transMeta.addTransHop(hi2);
//
// Create a dummy step 2
//
String dummyStepname2 = "dummy step 2";
DummyTransMeta dm2 = new DummyTransMeta();
String dummyPid2 = registry.getPluginId(StepPluginType.class, dm2);
StepMeta dummyStep2 = new StepMeta(dummyPid2, dummyStepname2, dm2);
transMeta.addStep(dummyStep2);
TransHopMeta hi3 = new TransHopMeta(webServiceStep, dummyStep2);
transMeta.addTransHop(hi3);
// Now execute the transformation...
Trans trans = new Trans(transMeta);
trans.prepareExecution(null);
StepInterface si = trans.getStepInterface(dummyStepname1, 0);
RowStepCollector dummyRc1 = new RowStepCollector();
si.addRowListener(dummyRc1);
si = trans.getStepInterface(webServiceStepname, 0);
RowStepCollector webServiceRc = new RowStepCollector();
si.addRowListener(webServiceRc);
RowProducer rp = trans.addRowProducer(injectorStepname, 0);
trans.startThreads();
// add rows
List<RowMetaAndData> inputList = createData(createRowMetaInterface(), new Object[][] { new Object[] { 10 } });
for (RowMetaAndData rm : inputList) {
rp.putRow(rm.getRowMeta(), rm.getData());
}
rp.finished();
trans.waitUntilFinished();
List<RowMetaAndData> goldRows = createData(createOutputRowMetaInterface(), new Object[][] { new Object[] { 10, new BigDecimal(20) } });
List<RowMetaAndData> resultRows2 = webServiceRc.getRowsWritten();
assertEquals(goldRows, resultRows2);
}
use of org.pentaho.di.core.plugins.PluginRegistry in project pentaho-kettle by pentaho.
the class DatabaseConfigurationImportRuleIT method testRule.
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());
}
use of org.pentaho.di.core.plugins.PluginRegistry in project pentaho-kettle by pentaho.
the class TransformationHasANoteImportRuleIT method testRule.
public void testRule() throws Exception {
// Create a transformation to test.
//
TransMeta transMeta = new TransMeta();
NotePadMeta note = new NotePadMeta("A note documenting the transformation", 50, 50, 200, 50);
transMeta.addNote(note);
// Load the plugin to test from the registry.
//
PluginRegistry registry = PluginRegistry.getInstance();
PluginInterface plugin = registry.findPluginWithId(ImportRulePluginType.class, "TransformationHasANote");
assertNotNull("The 'transformation has a note' rule could not be found in the plugin registry!", plugin);
TransformationHasANoteImportRule rule = (TransformationHasANoteImportRule) registry.loadClass(plugin);
assertNotNull("The 'transformation has a note' 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 a note' rule", !feedback.isEmpty());
assertTrue("An approval ruling was expected", feedback.get(0).getResultType() == ImportValidationResultType.APPROVAL);
transMeta.removeNote(0);
feedback = rule.verifyRule(transMeta);
assertTrue("We didn't get any feedback from the 'transformation has a note' rule", !feedback.isEmpty());
assertTrue("An error ruling was expected", feedback.get(0).getResultType() == ImportValidationResultType.ERROR);
rule.setEnabled(false);
feedback = rule.verifyRule(transMeta);
assertTrue("We didn't expect any feedback from the 'transformation has a note' rule while disabled", feedback.isEmpty());
}
use of org.pentaho.di.core.plugins.PluginRegistry in project pentaho-kettle by pentaho.
the class TransformationHasNoDisabledHopsImportRuleIT method testRule.
public void testRule() throws Exception {
// Create a transformation to test.
//
TransMeta transMeta = new TransMeta();
// Add 3 dummy steps connected with hops.
//
StepMeta lastStep = null;
for (int i = 0; i < 3; i++) {
DummyTransMeta dummyTransMeta = new DummyTransMeta();
StepMeta stepMeta = new StepMeta("dummy" + (i + 1), dummyTransMeta);
stepMeta.setLocation(50 + i * 50, 50);
stepMeta.setDraw(true);
transMeta.addStep(stepMeta);
if (lastStep != null) {
TransHopMeta hop = new TransHopMeta(lastStep, stepMeta);
transMeta.addTransHop(hop);
}
lastStep = stepMeta;
}
// Load the plugin to test from the registry.
//
PluginRegistry registry = PluginRegistry.getInstance();
PluginInterface plugin = registry.findPluginWithId(ImportRulePluginType.class, "TransformationHasNoDisabledHops");
assertNotNull("The 'transformation has no disabled hops' rule could not be found in the plugin registry!", plugin);
TransformationHasNoDisabledHopsImportRule rule = (TransformationHasNoDisabledHopsImportRule) registry.loadClass(plugin);
assertNotNull("The 'transformation has no disabled hops' 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 no disabled hops'", !feedback.isEmpty());
assertTrue("An approval ruling was expected", feedback.get(0).getResultType() == ImportValidationResultType.APPROVAL);
transMeta.getTransHop(0).setEnabled(false);
feedback = rule.verifyRule(transMeta);
assertTrue("We didn't get any feedback from the 'transformation has no disabled hops'", !feedback.isEmpty());
assertTrue("An error ruling was expected", feedback.get(0).getResultType() == ImportValidationResultType.ERROR);
rule.setEnabled(false);
feedback = rule.verifyRule(transMeta);
assertTrue("We didn't expect any feedback from the 'transformation has no disabled hops' while disabled", feedback.isEmpty());
}
use of org.pentaho.di.core.plugins.PluginRegistry in project pentaho-kettle by pentaho.
the class TransformationHasTransLogConfiguredImportRuleIT method testRule.
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());
}
Aggregations