Search in sources :

Example 36 with CheckResultInterface

use of org.pentaho.di.core.CheckResultInterface in project pentaho-kettle by pentaho.

the class OptimizationLevelIT method testOptimizationLevel.

/**
 * Creates the transformation needed to test the java script step with an optimization level set.
 *
 * @param optimizationLevel
 * @return
 * @throws KettleException
 */
private List<CheckResultInterface> testOptimizationLevel(String optimizationLevel) throws KettleException {
    KettleEnvironment.init();
    // Create a new transformation...
    TransMeta transMeta = new TransMeta();
    transMeta.setName("Test optimization level exception handling");
    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 javascript step
    String javaScriptStepname = "javascript step";
    // Create the meta and populate
    ScriptValuesMetaMod scriptValuesMetaMod = new ScriptValuesMetaMod();
    ScriptValuesScript[] js = new ScriptValuesScript[] { new ScriptValuesScript(ScriptValuesScript.TRANSFORM_SCRIPT, "script", "var str = string;\n" + "var bool = LuhnCheck(str);") };
    scriptValuesMetaMod.setJSScripts(js);
    scriptValuesMetaMod.setFieldname(new String[] { "bool" });
    scriptValuesMetaMod.setRename(new String[] { "" });
    scriptValuesMetaMod.setType(new int[] { ValueMetaInterface.TYPE_BOOLEAN });
    scriptValuesMetaMod.setLength(new int[] { -1 });
    scriptValuesMetaMod.setPrecision(new int[] { -1 });
    scriptValuesMetaMod.setReplace(new boolean[] { false });
    scriptValuesMetaMod.setCompatible(false);
    scriptValuesMetaMod.setOptimizationLevel(optimizationLevel);
    // Create the step meta
    String javaScriptStepPid = registry.getPluginId(StepPluginType.class, scriptValuesMetaMod);
    StepMeta javaScriptStep = new StepMeta(javaScriptStepPid, javaScriptStepname, scriptValuesMetaMod);
    // Create a dummy step
    String dummyStepname = "dummy step";
    DummyTransMeta dm = new DummyTransMeta();
    String dummyPid = registry.getPluginId(StepPluginType.class, dm);
    StepMeta dummyStep = new StepMeta(dummyPid, dummyStepname, dm);
    transMeta.addStep(dummyStep);
    // hop the steps that were created
    TransHopMeta hi2 = new TransHopMeta(javaScriptStep, dummyStep);
    transMeta.addTransHop(hi2);
    // We use an existing test that creates data: we'll use that data here
    JavaScriptSpecialIT javaScriptSpecialTest = new JavaScriptSpecialIT();
    List<RowMetaAndData> inputList = javaScriptSpecialTest.createData1();
    // RowMetaInterface rowMetaInterface = null;
    // This is the collection of error messages that may be generated
    // and other things that the check method will need
    List<CheckResultInterface> remarks = new ArrayList<CheckResultInterface>();
    String[] input = new String[] { injectorStepname };
    String[] output = new String[] {};
    // We get the row meta and data....
    Iterator<RowMetaAndData> it = inputList.iterator();
    if (it.hasNext()) {
        RowMetaAndData rowMetaAndData = it.next();
        // .... and then call the scriptValuesMetaMod's check method
        scriptValuesMetaMod.check(remarks, transMeta, javaScriptStep, rowMetaAndData.getRowMeta(), input, output, null, transMeta, null, null);
    } else {
        fail("No data in the inputList");
    }
    // we then return the remarks made by scriptValuesMetaMod.check(....);
    return remarks;
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) ArrayList(java.util.ArrayList) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransHopMeta(org.pentaho.di.trans.TransHopMeta) CheckResultInterface(org.pentaho.di.core.CheckResultInterface)

Example 37 with CheckResultInterface

use of org.pentaho.di.core.CheckResultInterface in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceStepValidationTest method unsupportedFieldsAddToRemarks.

@Test
public void unsupportedFieldsAddToRemarks() throws MetaverseException {
    setupServiceStepNameMatches();
    checkStepWithMockedOriginSteps();
    ArgumentCaptor<CheckResultInterface> argumentCaptor = ArgumentCaptor.forClass(CheckResultInterface.class);
    verify(remarks, times(1)).add(argumentCaptor.capture());
    for (String field : FIELD_NAMES) {
        assertThat("Expected unsupported field to be in validation messages", argumentCaptor.getValue().getText(), containsString(field));
    }
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) CheckResultInterface(org.pentaho.di.core.CheckResultInterface) Test(org.junit.Test)

Aggregations

CheckResultInterface (org.pentaho.di.core.CheckResultInterface)37 ArrayList (java.util.ArrayList)33 Test (org.junit.Test)23 Variables (org.pentaho.di.core.variables.Variables)20 TransMeta (org.pentaho.di.trans.TransMeta)8 StepMeta (org.pentaho.di.trans.step.StepMeta)8 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)7 Repository (org.pentaho.di.repository.Repository)6 IMetaStore (org.pentaho.metastore.api.IMetaStore)6 SalesforceMetaTest (org.pentaho.di.trans.steps.salesforce.SalesforceMetaTest)5 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)4 KettleException (org.pentaho.di.core.exception.KettleException)4 VariableSpace (org.pentaho.di.core.variables.VariableSpace)3 Result (org.pentaho.di.core.Result)2 KettleStepException (org.pentaho.di.core.exception.KettleStepException)2 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)2 Trans (org.pentaho.di.trans.Trans)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Throwables (com.google.common.base.Throwables)1