Search in sources :

Example 16 with PipelineUnitTest

use of org.apache.hop.testing.PipelineUnitTest 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)

Example 17 with PipelineUnitTest

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

the class DrawTweakOnTransformExtensionPoint method callExtensionPoint.

@Override
public void callExtensionPoint(ILogChannel log, IVariables variables, PipelinePainterExtension ext) throws HopException {
    TransformMeta transformMeta = ext.transformMeta;
    PipelineUnitTest unitTest = TestingGuiPlugin.getCurrentUnitTest(ext.pipelineMeta);
    if (unitTest == null) {
        return;
    }
    PipelineUnitTestTweak tweak = unitTest.findTweak(transformMeta.getName());
    if (tweak == null || tweak.getTweak() == null) {
        return;
    }
    try {
        switch(tweak.getTweak()) {
            case NONE:
                break;
            case REMOVE_TRANSFORM:
                drawRemovedTweak(ext, transformMeta);
                break;
            case BYPASS_TRANSFORM:
                drawBypassedTweak(ext, transformMeta);
                break;
            default:
                break;
        }
    } catch (Exception e) {
    // Ignore
    }
}
Also used : TransformMeta(org.apache.hop.pipeline.transform.TransformMeta) PipelineUnitTest(org.apache.hop.testing.PipelineUnitTest) PipelineUnitTestTweak(org.apache.hop.testing.PipelineUnitTestTweak) HopException(org.apache.hop.core.exception.HopException)

Example 18 with PipelineUnitTest

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

the class HopGuiUnitTestCreateBeforeDialog method callExtensionPoint.

@Override
public void callExtensionPoint(ILogChannel log, IVariables variables, Object object) throws HopException {
    // 
    if (!(object instanceof PipelineUnitTest)) {
        return;
    }
    PipelineUnitTest test = (PipelineUnitTest) object;
    PipelineMeta pipelineMeta = TestingGuiPlugin.getActivePipelineMeta();
    if (pipelineMeta != null) {
        test.setName(pipelineMeta.getName() + " UNIT");
        test.setType(TestType.UNIT_TEST);
        test.setRelativeFilename(HopGui.getInstance().getVariables(), pipelineMeta.getFilename());
    }
}
Also used : PipelineUnitTest(org.apache.hop.testing.PipelineUnitTest) PipelineMeta(org.apache.hop.pipeline.PipelineMeta)

Aggregations

PipelineUnitTest (org.apache.hop.testing.PipelineUnitTest)18 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)8 HopException (org.apache.hop.core.exception.HopException)7 TransformMeta (org.apache.hop.pipeline.transform.TransformMeta)5 HopGui (org.apache.hop.ui.hopgui.HopGui)5 UnitTestResult (org.apache.hop.testing.UnitTestResult)4 ExtensionPoint (org.apache.hop.core.extension.ExtensionPoint)3 IExtensionPoint (org.apache.hop.core.extension.IExtensionPoint)3 IHopMetadataProvider (org.apache.hop.metadata.api.IHopMetadataProvider)3 VariableValue (org.apache.hop.testing.VariableValue)3 HopGuiPipelineGraph (org.apache.hop.ui.hopgui.file.pipeline.HopGuiPipelineGraph)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 IRowMeta (org.apache.hop.core.row.IRowMeta)2 LocalPipelineEngine (org.apache.hop.pipeline.engines.local.LocalPipelineEngine)2 PipelineUnitTestDatabaseReplacement (org.apache.hop.testing.PipelineUnitTestDatabaseReplacement)2 PipelineUnitTestSetLocation (org.apache.hop.testing.PipelineUnitTestSetLocation)2 TestingGuiPlugin (org.apache.hop.testing.gui.TestingGuiPlugin)2 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)2