Search in sources :

Example 1 with VariableValue

use of org.apache.hop.testing.VariableValue in project hop by apache.

the class PipelineUnitTestEditor method setWidgetsContent.

@Override
public void setWidgetsContent() {
    PipelineUnitTest pipelineUnitTest = this.getMetadata();
    wName.setText(Const.NVL(pipelineUnitTest.getName(), ""));
    wDescription.setText(Const.NVL(pipelineUnitTest.getDescription(), ""));
    wTestType.setText(Const.NVL(DataSetConst.getTestTypeDescription(pipelineUnitTest.getType()), ""));
    wPipelineFilename.setText(Const.NVL(pipelineUnitTest.getPipelineFilename(), ""));
    wFilename.setText(Const.NVL(pipelineUnitTest.getFilename(), ""));
    wBasePath.setText(Const.NVL(pipelineUnitTest.getBasePath(), ""));
    wAutoOpen.setSelection(pipelineUnitTest.isAutoOpening());
    for (int i = 0; i < pipelineUnitTest.getDatabaseReplacements().size(); i++) {
        PipelineUnitTestDatabaseReplacement dbReplacement = pipelineUnitTest.getDatabaseReplacements().get(i);
        wDbReplacements.setText(Const.NVL(dbReplacement.getOriginalDatabaseName(), ""), 1, i);
        wDbReplacements.setText(Const.NVL(dbReplacement.getReplacementDatabaseName(), ""), 2, i);
    }
    for (int i = 0; i < pipelineUnitTest.getVariableValues().size(); i++) {
        VariableValue variableValue = pipelineUnitTest.getVariableValues().get(i);
        wVariableValues.setText(Const.NVL(variableValue.getKey(), ""), 1, i);
        wVariableValues.setText(Const.NVL(variableValue.getValue(), ""), 2, i);
    }
    wDbReplacements.removeEmptyRows();
    wDbReplacements.setRowNums();
}
Also used : VariableValue(org.apache.hop.testing.VariableValue) PipelineUnitTest(org.apache.hop.testing.PipelineUnitTest) PipelineUnitTestDatabaseReplacement(org.apache.hop.testing.PipelineUnitTestDatabaseReplacement)

Example 2 with VariableValue

use of org.apache.hop.testing.VariableValue in project hop by apache.

the class PipelineUnitTestEditor method getWidgetsContent.

@Override
public void getWidgetsContent(PipelineUnitTest test) {
    test.setName(wName.getText());
    test.setDescription(wDescription.getText());
    test.setType(DataSetConst.getTestTypeForDescription(wTestType.getText()));
    test.setPipelineFilename(wPipelineFilename.getText());
    test.setFilename(wFilename.getText());
    test.setBasePath(wBasePath.getText());
    test.setAutoOpening(wAutoOpen.getSelection());
    test.getDatabaseReplacements().clear();
    int nrFields = wDbReplacements.nrNonEmpty();
    for (int i = 0; i < nrFields; i++) {
        TableItem item = wDbReplacements.getNonEmpty(i);
        String sourceDb = item.getText(1);
        String replaceDb = item.getText(2);
        PipelineUnitTestDatabaseReplacement dbReplacement = new PipelineUnitTestDatabaseReplacement(sourceDb, replaceDb);
        test.getDatabaseReplacements().add(dbReplacement);
    }
    test.getVariableValues().clear();
    int nrVars = wVariableValues.nrNonEmpty();
    for (int i = 0; i < nrVars; i++) {
        TableItem item = wVariableValues.getNonEmpty(i);
        String key = item.getText(1);
        String value = item.getText(2);
        VariableValue variableValue = new VariableValue(key, value);
        test.getVariableValues().add(variableValue);
    }
}
Also used : VariableValue(org.apache.hop.testing.VariableValue) PipelineUnitTestDatabaseReplacement(org.apache.hop.testing.PipelineUnitTestDatabaseReplacement)

Example 3 with VariableValue

use of org.apache.hop.testing.VariableValue in project hop by apache.

the class ChangePipelineMetaPriorToExecutionExtensionPoint method callExtensionPoint.

@Override
public void callExtensionPoint(ILogChannel log, IVariables variables, IPipelineEngine<PipelineMeta> pipeline) throws HopException {
    PipelineMeta pipelineMeta = pipeline.getPipelineMeta();
    boolean runUnitTest = "Y".equalsIgnoreCase(variables.getVariable(DataSetConst.VAR_RUN_UNIT_TEST));
    // Only try to run a unit test when running with the local engine
    // 
    runUnitTest = runUnitTest && (pipeline instanceof LocalPipelineEngine);
    if (!runUnitTest) {
        // No business here...
        if (log.isDetailed()) {
            log.logDetailed("Not running a unit test...");
        }
        return;
    }
    String unitTestName = pipeline.getVariable(DataSetConst.VAR_UNIT_TEST_NAME);
    // 
    if (StringUtils.isEmpty(unitTestName)) {
        if (log.isDetailed()) {
            log.logDetailed("Unit test disabled.");
        }
        return;
    }
    PipelineUnitTest unitTest = null;
    try {
        unitTest = pipeline.getMetadataProvider().getSerializer(PipelineUnitTest.class).load(unitTestName);
    } catch (HopException e) {
        throw new HopException("Unable to load unit test '" + unitTestName + "'", e);
    }
    if (unitTest == null) {
        throw new HopException("Unit test '" + unitTestName + "' could not be found.");
    }
    // Get a modified copy of the pipeline using the unit test information
    // 
    PipelineMetaModifier modifier = new PipelineMetaModifier(pipeline, pipelineMeta, unitTest);
    PipelineMeta copyPipelineMeta = modifier.getTestPipeline(log, pipeline, pipeline.getMetadataProvider());
    // Now replace the metadata in the IPipelineEngine<PipelineMeta> object...
    // 
    pipeline.setPipelineMeta(copyPipelineMeta);
    // Set parameters and variables...
    // 
    String[] parameters = copyPipelineMeta.listParameters();
    List<VariableValue> variableValues = unitTest.getVariableValues();
    for (VariableValue variableValue : variableValues) {
        String key = pipeline.resolve(variableValue.getKey());
        String value = pipeline.resolve(variableValue.getValue());
        if (StringUtils.isEmpty(key)) {
            continue;
        }
        if (Const.indexOfString(key, parameters) < 0) {
            // set the variable in the pipeline metadata...
            // 
            pipeline.setVariable(key, value);
        } else {
            // Set the parameter value...
            // 
            pipeline.setParameterValue(key, value);
        }
    }
    String testFilename = pipeline.resolve(unitTest.getFilename());
    if (!StringUtil.isEmpty(testFilename)) {
        try {
            OutputStream os = HopVfs.getOutputStream(testFilename, false);
            os.write(XmlHandler.getXmlHeader().getBytes());
            os.write(copyPipelineMeta.getXml(variables).getBytes());
            os.close();
        } catch (Exception e) {
            throw new HopException("Error writing test filename to '" + testFilename + "'", e);
        }
    }
}
Also used : LocalPipelineEngine(org.apache.hop.pipeline.engines.local.LocalPipelineEngine) HopException(org.apache.hop.core.exception.HopException) VariableValue(org.apache.hop.testing.VariableValue) OutputStream(java.io.OutputStream) PipelineUnitTest(org.apache.hop.testing.PipelineUnitTest) HopException(org.apache.hop.core.exception.HopException) PipelineMeta(org.apache.hop.pipeline.PipelineMeta)

Aggregations

VariableValue (org.apache.hop.testing.VariableValue)3 PipelineUnitTest (org.apache.hop.testing.PipelineUnitTest)2 PipelineUnitTestDatabaseReplacement (org.apache.hop.testing.PipelineUnitTestDatabaseReplacement)2 OutputStream (java.io.OutputStream)1 HopException (org.apache.hop.core.exception.HopException)1 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)1 LocalPipelineEngine (org.apache.hop.pipeline.engines.local.LocalPipelineEngine)1