Search in sources :

Example 1 with TransformationHasNoDisabledHopsImportRule

use of org.pentaho.di.imp.rules.TransformationHasNoDisabledHopsImportRule 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());
}
Also used : TransformationHasNoDisabledHopsImportRule(org.pentaho.di.imp.rules.TransformationHasNoDisabledHopsImportRule) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)

Aggregations

PluginInterface (org.pentaho.di.core.plugins.PluginInterface)1 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)1 TransformationHasNoDisabledHopsImportRule (org.pentaho.di.imp.rules.TransformationHasNoDisabledHopsImportRule)1 TransHopMeta (org.pentaho.di.trans.TransHopMeta)1 TransMeta (org.pentaho.di.trans.TransMeta)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)1