Search in sources :

Example 1 with PipelineMetaModifier

use of org.apache.hop.testing.xp.PipelineMetaModifier in project hop by apache.

the class TestingGuiPlugin method setGoldenDataSet.

/**
 * We set an golden data set on the selected unit test
 */
@GuiContextAction(id = ACTION_ID_PIPELINE_GRAPH_TRANSFORM_DEFINE_GOLDEN_DATA_SET, parentId = HopGuiPipelineTransformContext.CONTEXT_ID, type = GuiActionType.Modify, name = "i18n::TestingGuiPlugin.ContextAction.SetGoldenDataset.Name", tooltip = "i18n::TestingGuiPlugin.ContextAction.SetGoldenDataset.Tooltip", image = "set-golden-dataset.svg", category = "i18n::TestingGuiPlugin.Category", categoryOrder = "8")
public void setGoldenDataSet(HopGuiPipelineTransformContext context) {
    PipelineMeta sourcePipelineMeta = context.getPipelineMeta();
    TransformMeta transformMeta = context.getTransformMeta();
    HopGuiPipelineGraph pipelineGraph = context.getPipelineGraph();
    IVariables variables = pipelineGraph.getVariables();
    HopGui hopGui = HopGui.getInstance();
    IHopMetadataProvider metadataProvider = hopGui.getMetadataProvider();
    if (checkTestPresent(hopGui, sourcePipelineMeta)) {
        return;
    }
    PipelineUnitTest unitTest = getCurrentUnitTest(sourcePipelineMeta);
    try {
        // Create a copy and modify the pipeline
        // This way we have
        PipelineMetaModifier modifier = new PipelineMetaModifier(variables, sourcePipelineMeta, unitTest);
        PipelineMeta pipelineMeta = modifier.getTestPipeline(LogChannel.UI, variables, metadataProvider);
        IHopMetadataSerializer<DataSet> setSerializer = metadataProvider.getSerializer(DataSet.class);
        List<String> setNames = setSerializer.listObjectNames();
        Collections.sort(setNames);
        EnterSelectionDialog esd = new EnterSelectionDialog(hopGui.getShell(), setNames.toArray(new String[setNames.size()]), BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.SetGoldenDataset.Header"), BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.SetGoldenDataset.Message"));
        String setName = esd.open();
        if (setName != null) {
            DataSet dataSet = setSerializer.load(setName);
            boolean changed = setGoldenDataSetOnTransform(variables, metadataProvider, pipelineMeta, transformMeta, unitTest, dataSet);
            if (changed) {
                pipelineGraph.updateGui();
            }
        }
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.SetGoldenDataset.Error.Header"), BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.SetGoldenDataset.Error.Message"), e);
    }
}
Also used : PipelineMetaModifier(org.apache.hop.testing.xp.PipelineMetaModifier) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) HopException(org.apache.hop.core.exception.HopException) HopTransformException(org.apache.hop.core.exception.HopTransformException) HopValueException(org.apache.hop.core.exception.HopValueException) HopPluginException(org.apache.hop.core.exception.HopPluginException) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) IVariables(org.apache.hop.core.variables.IVariables) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) HopGuiPipelineGraph(org.apache.hop.ui.hopgui.file.pipeline.HopGuiPipelineGraph) EnterSelectionDialog(org.apache.hop.ui.core.dialog.EnterSelectionDialog) HopGui(org.apache.hop.ui.hopgui.HopGui) GuiContextAction(org.apache.hop.core.action.GuiContextAction)

Aggregations

GuiContextAction (org.apache.hop.core.action.GuiContextAction)1 HopException (org.apache.hop.core.exception.HopException)1 HopPluginException (org.apache.hop.core.exception.HopPluginException)1 HopTransformException (org.apache.hop.core.exception.HopTransformException)1 HopValueException (org.apache.hop.core.exception.HopValueException)1 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)1 IVariables (org.apache.hop.core.variables.IVariables)1 IHopMetadataProvider (org.apache.hop.metadata.api.IHopMetadataProvider)1 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)1 TransformMeta (org.apache.hop.pipeline.transform.TransformMeta)1 PipelineMetaModifier (org.apache.hop.testing.xp.PipelineMetaModifier)1 EnterSelectionDialog (org.apache.hop.ui.core.dialog.EnterSelectionDialog)1 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)1 HopGui (org.apache.hop.ui.hopgui.HopGui)1 HopGuiPipelineGraph (org.apache.hop.ui.hopgui.file.pipeline.HopGuiPipelineGraph)1