Java Code Examples for org.pentaho.di.core.plugins.PluginRegistry#findPluginWithId()

The following examples show how to use org.pentaho.di.core.plugins.PluginRegistry#findPluginWithId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Encr.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public static void init( String encoderPluginId ) throws KettleException {
  if ( Utils.isEmpty( encoderPluginId ) ) {
    throw new KettleException( "Unable to initialize the two way password encoder: No encoder plugin type specified." );
  }
  PluginRegistry registry = PluginRegistry.getInstance();
  PluginInterface plugin = registry.findPluginWithId( TwoWayPasswordEncoderPluginType.class, encoderPluginId );
  if ( plugin == null ) {
    throw new KettleException( "Unable to find plugin with ID '" + encoderPluginId + "'.  If this is a test, make sure"
      + " kettle-core tests jar is a dependency.  If this is live make sure a kettle-password-encoder-plugins.xml"
      + " exits in the classpath" );
  }
  encoder = (TwoWayPasswordEncoderInterface) registry.loadClass( plugin );

  // Load encoder specific options...
  //
  try {
    encoder.init();
  } catch ( PasswordEncoderException e ) {
    throw new KettleException( e );
  }
}
 
Example 2
Source File: StepPartitioningMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void createPartitioner( String method ) throws KettlePluginException {
  methodType = getMethodType( method );
  switch ( methodType ) {
    case PARTITIONING_METHOD_SPECIAL: {
      PluginRegistry registry = PluginRegistry.getInstance();
      PluginInterface plugin = registry.findPluginWithId( PartitionerPluginType.class, method );
      partitioner = (Partitioner) registry.loadClass( plugin );
      partitioner.setId( plugin.getIds()[0] );
      break;
    }
    case PARTITIONING_METHOD_NONE:
    default:
      partitioner = null;
  }
  if ( partitioner != null ) {
    partitioner.setMeta( this );
  }
}
 
Example 3
Source File: ImportRules.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void loadXML( Node rulesNode ) throws KettleException {
  List<Node> ruleNodes = XMLHandler.getNodes( rulesNode, BaseImportRule.XML_TAG );
  for ( Node ruleNode : ruleNodes ) {
    String id = XMLHandler.getTagValue( ruleNode, "id" );

    PluginRegistry registry = PluginRegistry.getInstance();

    PluginInterface plugin = registry.findPluginWithId( ImportRulePluginType.class, id );
    if ( plugin == null ) {
      throw new KettleException( "The import rule of type '"
        + id + "' could not be found in the plugin registry." );
    }
    ImportRuleInterface rule = (ImportRuleInterface) registry.loadClass( plugin );

    rule.loadXML( ruleNode );

    getRules().add( rule );
  }
}
 
Example 4
Source File: TransformationHasANoteImportRuleIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
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() );

  }
 
Example 5
Source File: StepMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void setDeprecationAndSuggestedStep() {
  PluginRegistry registry = PluginRegistry.getInstance();
  final List<PluginInterface> deprecatedSteps = registry.getPluginsByCategory( StepPluginType.class,
    BaseMessages.getString( PKG, "BaseStep.Category.Deprecated" ) );
  for ( PluginInterface p : deprecatedSteps ) {
    String[] ids = p.getIds();
    if ( !ArrayUtils.isEmpty( ids ) && ids[0].equals( this.stepid ) ) {
      this.isDeprecated = true;
      this.suggestion = registry.findPluginWithId( StepPluginType.class, this.stepid ) != null
        ? registry.findPluginWithId( StepPluginType.class, this.stepid ).getSuggestion() : "";
      break;
    }
  }
}
 
Example 6
Source File: JobHasANoteImportRuleIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
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() );
  }
 
Example 7
Source File: StepPartitioningMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static final String getMethod( String name ) {
  if ( Utils.isEmpty( name ) ) {
    return methodCodes[PARTITIONING_METHOD_NONE];
  }

  for ( int i = 0; i < methodDescriptions.length; i++ ) {
    if ( methodDescriptions[i].equalsIgnoreCase( name ) ) {
      return methodCodes[i];
    }
  }

  for ( int i = 0; i < methodCodes.length; i++ ) {
    if ( methodCodes[i].equalsIgnoreCase( name ) ) {
      return methodCodes[i];
    }
  }

  PluginRegistry registry = PluginRegistry.getInstance();
  PluginInterface plugin = registry.findPluginWithName( PartitionerPluginType.class, name );
  if ( plugin != null ) {
    return name;
  }
  plugin = registry.findPluginWithId( PartitionerPluginType.class, name );
  if ( plugin != null ) {
    return name;
  }

  return methodCodes[PARTITIONING_METHOD_NONE];
}
 
Example 8
Source File: JobHasDescriptionImportRuleIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
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() );
  }
 
Example 9
Source File: JobEntryCopy.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void setDeprecationAndSuggestedJobEntry() {
  PluginRegistry registry = PluginRegistry.getInstance();
  final List<PluginInterface> deprecatedJobEntries = registry.getPluginsByCategory( JobEntryPluginType.class,
    BaseMessages.getString( JobMeta.class, "JobCategory.Category.Deprecated" ) );
  for ( PluginInterface p : deprecatedJobEntries ) {
    String[] ids = p.getIds();
    if ( !ArrayUtils.isEmpty( ids ) && ids[0].equals( this.entry != null ? this.entry.getPluginId() : "" ) ) {
      this.isDeprecated = true;
      this.suggestion = registry.findPluginWithId( JobEntryPluginType.class, this.entry.getPluginId() ) != null
        ? registry.findPluginWithId( JobEntryPluginType.class, this.entry.getPluginId() ).getSuggestion() : "";
      break;
    }
  }
}
 
Example 10
Source File: JobEntryCopy.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public JobEntryCopy( Node entrynode, List<DatabaseMeta> databases, List<SlaveServer> slaveServers, Repository rep,
    IMetaStore metaStore ) throws KettleXMLException {
  try {
    String stype = XMLHandler.getTagValue( entrynode, "type" );
    PluginRegistry registry = PluginRegistry.getInstance();
    PluginInterface jobPlugin = registry.findPluginWithId( JobEntryPluginType.class, stype, true );
    if ( jobPlugin == null ) {
      String name = XMLHandler.getTagValue( entrynode, "name" );
      entry = new MissingEntry( name, stype );
    } else {
      entry = registry.loadClass( jobPlugin, JobEntryInterface.class );
    }
    // Get an empty JobEntry of the appropriate class...
    if ( entry != null ) {
      if ( jobPlugin != null ) {
        entry.setPluginId( jobPlugin.getIds()[0] );
      }
      entry.setMetaStore( metaStore ); // inject metastore
      entry.loadXML( entrynode, databases, slaveServers, rep, metaStore );
      compatibleLoadXml( entrynode, databases, slaveServers, rep );

      // Handle GUI information: nr & location?
      setNr( Const.toInt( XMLHandler.getTagValue( entrynode, "nr" ), 0 ) );
      setLaunchingInParallel( "Y".equalsIgnoreCase( XMLHandler.getTagValue( entrynode, "parallel" ) ) );
      setDrawn( "Y".equalsIgnoreCase( XMLHandler.getTagValue( entrynode, "draw" ) ) );
      int x = Const.toInt( XMLHandler.getTagValue( entrynode, "xloc" ), 0 );
      int y = Const.toInt( XMLHandler.getTagValue( entrynode, "yloc" ), 0 );
      setLocation( x, y );

      Node jobEntryCopyAttributesNode = XMLHandler.getSubNode( entrynode, XML_ATTRIBUTE_JOB_ENTRY_COPY );
      if ( jobEntryCopyAttributesNode != null ) {
        attributesMap = AttributesUtil.loadAttributes( jobEntryCopyAttributesNode );
      } else {
        // [PDI-17345] If the appropriate attributes node wasn't found, this must be an old file (prior to this fix).
        // Before this fix it was very probable to exist two attributes groups. While this is not very valid, in some
        // scenarios the Job worked as expected; so by trying to load the LAST one into the JobEntryCopy, we
        // simulate that behaviour.
        attributesMap =
          AttributesUtil.loadAttributes( XMLHandler.getLastSubNode( entrynode, AttributesUtil.XML_TAG ) );
      }

      setDeprecationAndSuggestedJobEntry();
    }
  } catch ( Throwable e ) {
    String message = "Unable to read Job Entry copy info from XML node : " + e.toString();
    throw new KettleXMLException( message, e );
  }
}
 
Example 11
Source File: PurRepositoryProxy.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public PurRepositoryProxy( PluginRegistry registry ) throws KettlePluginException {
  PluginInterface purPlugin = registry.findPluginWithId( RepositoryPluginType.class, PUR_PLUGIN_ID );
  purPluginClassLoader = registry.getClassLoader( purPlugin );
}
 
Example 12
Source File: KettleDatabaseRepositoryStepDelegate.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Create a new step by loading the metadata from the specified repository.
 *
 * @param rep
 * @param stepId
 * @param databases
 * @param counters
 * @param partitionSchemas
 * @throws KettleException
 */
public StepMeta loadStepMeta( ObjectId stepId, List<DatabaseMeta> databases,
  List<PartitionSchema> partitionSchemas ) throws KettleException {
  StepMeta stepMeta = new StepMeta();
  PluginRegistry registry = PluginRegistry.getInstance();

  try {
    RowMetaAndData r = getStep( stepId );
    if ( r != null ) {
      stepMeta.setObjectId( stepId );

      stepMeta.setName( r.getString( KettleDatabaseRepository.FIELD_STEP_NAME, null ) );
      stepMeta.setDescription( r.getString( KettleDatabaseRepository.FIELD_STEP_DESCRIPTION, null ) );

      long id_step_type = r.getInteger( KettleDatabaseRepository.FIELD_STEP_ID_STEP_TYPE, -1L );
      RowMetaAndData steptyperow = getStepType( new LongObjectId( id_step_type ) );

      stepMeta.setStepID( steptyperow.getString( KettleDatabaseRepository.FIELD_STEP_TYPE_CODE, null ) );
      stepMeta.setDistributes( r.getBoolean( KettleDatabaseRepository.FIELD_STEP_DISTRIBUTE, true ) );
      int copies = (int) r.getInteger( KettleDatabaseRepository.FIELD_STEP_COPIES, 1 );
      String copiesString = r.getString( KettleDatabaseRepository.FIELD_STEP_COPIES_STRING, null );
      if ( !Utils.isEmpty( copiesString ) ) {
        stepMeta.setCopiesString( copiesString );
      } else {
        stepMeta.setCopies( copies );
      }

      int x = (int) r.getInteger( KettleDatabaseRepository.FIELD_STEP_GUI_LOCATION_X, 0 );
      int y = (int) r.getInteger( KettleDatabaseRepository.FIELD_STEP_GUI_LOCATION_Y, 0 );
      stepMeta.setLocation( new Point( x, y ) );
      stepMeta.setDraw( r.getBoolean( KettleDatabaseRepository.FIELD_STEP_GUI_DRAW, false ) );

      // Generate the appropriate class...
      PluginInterface sp = registry.findPluginWithId( StepPluginType.class, stepMeta.getStepID() );
      if ( sp == null ) {
        stepMeta.setStepMetaInterface( new MissingTrans( stepMeta.getName(), stepMeta.getStepID() ) );
      } else {
        stepMeta.setStepMetaInterface( (StepMetaInterface) registry.loadClass( sp ) );
      }
      if ( stepMeta.getStepMetaInterface() != null ) {
        // Read the step info from the repository!
        readRepCompatibleStepMeta(
          stepMeta.getStepMetaInterface(), repository, stepMeta.getObjectId(), databases );
        stepMeta.getStepMetaInterface().readRep(
          repository, repository.metaStore, stepMeta.getObjectId(), databases );
      }

      // Get the partitioning as well...
      //
      stepMeta.setStepPartitioningMeta( loadStepPartitioningMeta( stepMeta.getObjectId() ) );
      stepMeta.getStepPartitioningMeta().setPartitionSchemaAfterLoading( partitionSchemas );

      // Get the cluster schema name
      //
      stepMeta.setClusterSchemaName( repository.getStepAttributeString( stepId, "cluster_schema" ) );

      // Are we using a custom row distribution plugin?
      //
      String rowDistributionCode = repository.getStepAttributeString( stepId, 0, "row_distribution_code" );
      RowDistributionInterface rowDistribution =
        PluginRegistry.getInstance().loadClass(
          RowDistributionPluginType.class, rowDistributionCode, RowDistributionInterface.class );
      stepMeta.setRowDistribution( rowDistribution );

      // Load the attribute groups map
      //
      stepMeta.setAttributesMap( loadStepAttributesMap( stepId ) );

      // Done!
      //
      return stepMeta;
    } else {
      throw new KettleException( BaseMessages.getString(
        PKG, "StepMeta.Exception.StepInfoCouldNotBeFound", String.valueOf( stepId ) ) );
    }
  } catch ( KettleDatabaseException dbe ) {
    throw new KettleException( BaseMessages.getString( PKG, "StepMeta.Exception.StepCouldNotBeLoaded", String
      .valueOf( stepMeta.getObjectId() ) ), dbe );
  }
}
 
Example 13
Source File: DatabaseConfigurationImportRuleIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
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() );
  }
 
Example 14
Source File: TransformationHasDescriptionImportRuleIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void testRule() throws Exception {

    TransMeta transMeta = new TransMeta();
    transMeta.setDescription( "This transformation is used for testing an import rule" );

    PluginRegistry registry = PluginRegistry.getInstance();

    PluginInterface plugin =
      registry.findPluginWithId( ImportRulePluginType.class, "TransformationHasDescription" );
    assertNotNull( "The 'transformation has description' rule could not be found in the plugin registry!", plugin );

    TransformationHasDescriptionImportRule rule =
      (TransformationHasDescriptionImportRule) registry.loadClass( plugin );
    assertNotNull(
      "The 'transformation has description rule' class could not be loaded by the plugin registry!", plugin );

    rule.setMinLength( 20 );
    rule.setEnabled( true );

    List<ImportValidationFeedback> 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 );

    rule.setMinLength( 2000 );
    rule.setEnabled( true );

    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.setEnabled( false );

    feedback = rule.verifyRule( transMeta );
    assertTrue(
      "We didn't expect any feedback from the 'transformation has description rule' while disabled", feedback
        .isEmpty() );

  }
 
Example 15
Source File: JobHasNoDisabledHopsImportRuleIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
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() );
  }
 
Example 16
Source File: TransformationHasNoDisabledHopsImportRuleIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
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() );

  }
 
Example 17
Source File: TransformationHasTransLogConfiguredImportRuleIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
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() );
  }
 
Example 18
Source File: JobHasJobLogConfiguredImportRuleIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
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() );
  }