Search in sources :

Example 31 with JobHopMeta

use of org.pentaho.di.job.JobHopMeta in project pentaho-kettle by pentaho.

the class JobHasNoDisabledHopsImportRuleIT method testRule.

public void testRule() throws Exception {
    // Create a job to test.
    // 
    JobMeta jobMeta = new JobMeta();
    // Add 3 dummy steps connected with hops.
    // 
    JobEntryCopy lastCopy = null;
    for (int i = 0; i < 3; i++) {
        JobEntrySpecial dummy = new JobEntrySpecial();
        dummy.setDummy(true);
        dummy.setName("dummy" + (i + 1));
        JobEntryCopy copy = new JobEntryCopy(dummy);
        copy.setLocation(50 + i * 50, 50);
        copy.setDrawn();
        jobMeta.addJobEntry(copy);
        if (lastCopy != null) {
            JobHopMeta hop = new JobHopMeta(lastCopy, copy);
            jobMeta.addJobHop(hop);
        }
        lastCopy = copy;
    }
    // Load the plugin to test from the registry.
    // 
    PluginRegistry registry = PluginRegistry.getInstance();
    PluginInterface plugin = registry.findPluginWithId(ImportRulePluginType.class, "JobHasNoDisabledHops");
    assertNotNull("The 'job has no disabled hops' rule could not be found in the plugin registry!", plugin);
    JobHasNoDisabledHopsImportRule rule = (JobHasNoDisabledHopsImportRule) registry.loadClass(plugin);
    assertNotNull("The 'job has no disabled hops' 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 no disabled hops'", !feedback.isEmpty());
    assertTrue("An approval ruling was expected", feedback.get(0).getResultType() == ImportValidationResultType.APPROVAL);
    jobMeta.getJobHop(0).setEnabled(false);
    feedback = rule.verifyRule(jobMeta);
    assertTrue("We didn't get any feedback from the 'job has no disabled hops'", !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 disabled hops' while disabled", feedback.isEmpty());
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntrySpecial(org.pentaho.di.job.entries.special.JobEntrySpecial) JobHopMeta(org.pentaho.di.job.JobHopMeta) JobHasNoDisabledHopsImportRule(org.pentaho.di.imp.rules.JobHasNoDisabledHopsImportRule) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface)

Aggregations

JobHopMeta (org.pentaho.di.job.JobHopMeta)31 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)24 Point (org.pentaho.di.core.gui.Point)17 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)16 NotePadMeta (org.pentaho.di.core.NotePadMeta)12 KettleException (org.pentaho.di.core.exception.KettleException)10 JobMeta (org.pentaho.di.job.JobMeta)10 ArrayList (java.util.ArrayList)8 MessageBox (org.eclipse.swt.widgets.MessageBox)6 JobEntryInterface (org.pentaho.di.job.entry.JobEntryInterface)6 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)4 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)4 AreaOwner (org.pentaho.di.core.gui.AreaOwner)4 Job (org.pentaho.di.job.Job)4 Date (java.util.Date)3 Test (org.junit.Test)3 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)3 JobEntrySpecial (org.pentaho.di.job.entries.special.JobEntrySpecial)3 KettleRepositoryLostException (org.pentaho.di.repository.KettleRepositoryLostException)3 XulException (org.pentaho.ui.xul.XulException)3