use of org.apache.hop.testing.UnitTestResult in project hop by apache.
the class HopGuiUpdateStateMapExtensionPoint method callExtensionPoint.
@Override
public void callExtensionPoint(ILogChannel log, IVariables variables, HopGuiPipelineFinishedExtension ext) throws HopException {
final List<UnitTestResult> results = (List<UnitTestResult>) ext.pipeline.getExtensionDataMap().get(DataSetConst.UNIT_TEST_RESULTS);
if (results != null && !results.isEmpty()) {
Map<String, Object> stateMap = ext.pipelineGraph.getStateMap();
if (stateMap == null) {
stateMap = new HashMap<>();
ext.pipelineGraph.setStateMap(stateMap);
}
Map<String, Boolean> resultsMap = new HashMap<>();
stateMap.put(DataSetConst.STATE_KEY_GOLDEN_DATASET_RESULTS, resultsMap);
for (UnitTestResult result : results) {
if (StringUtils.isNotEmpty(result.getDataSetName())) {
resultsMap.put(result.getDataSetName(), !result.isError());
}
}
}
}
use of org.apache.hop.testing.UnitTestResult in project hop by apache.
the class ExecuteTests method processRow.
@Override
public boolean processRow() throws HopException {
if (first) {
first = false;
IHopMetadataSerializer<PipelineUnitTest> testSerializer = metadataProvider.getSerializer(PipelineUnitTest.class);
//
if (data.hasPrevious) {
data.tests = new ArrayList<>();
Object[] row = getRow();
if (row == null) {
// No input and as such no tests to execute. We're all done here.
//
setOutputDone();
return false;
}
int inputFieldIndex = getInputRowMeta().indexOfValue(meta.getTestNameInputField());
if (inputFieldIndex < 0) {
throw new HopException("Unable to find test name field '" + meta.getTestNameInputField() + "' in the input");
}
while (row != null) {
String testName = getInputRowMeta().getString(row, inputFieldIndex);
try {
PipelineUnitTest pipelineUnitTest = testSerializer.load(testName);
data.tests.add(pipelineUnitTest);
} catch (Exception e) {
throw new HopException("Unable to load test '" + testName + "'", e);
}
row = getRow();
}
} else {
//
try {
data.tests = new ArrayList<>();
for (String testName : testSerializer.listObjectNames()) {
PipelineUnitTest pipelineUnitTest = testSerializer.load(testName);
if (meta.getTypeToExecute() == null || meta.getTypeToExecute() == pipelineUnitTest.getType()) {
data.tests.add(pipelineUnitTest);
}
}
} catch (HopException e) {
throw new HopException("Unable to read pipeline unit tests from the metadata", e);
}
}
data.testsIterator = data.tests.iterator();
data.outputRowMeta = new RowMeta();
meta.getFields(data.outputRowMeta, getTransformName(), null, null, this, metadataProvider);
}
//
if (data.testsIterator.hasNext()) {
PipelineUnitTest test = data.testsIterator.next();
UnitTestUtil.executeUnitTest(test, this, getLogLevel(), metadataProvider, this, //
(pipeline, pipelineResult) -> {
if (pipelineResult.getNrErrors() != 0) {
// The pipeline had a failure, report this too.
//
Object[] row = RowDataUtil.allocateRowData(data.outputRowMeta.size());
int index = 0;
row[index++] = pipeline.getPipelineMeta().getName();
row[index++] = null;
row[index++] = null;
row[index++] = null;
row[index++] = Boolean.TRUE;
row[index++] = pipelineResult.getLogText();
ExecuteTests.this.putRow(data.outputRowMeta, row);
}
}, //
(pipeline, testResults) -> {
for (UnitTestResult testResult : testResults) {
Object[] row = RowDataUtil.allocateRowData(data.outputRowMeta.size());
int index = 0;
row[index++] = testResult.getPipelineName();
row[index++] = testResult.getUnitTestName();
row[index++] = testResult.getDataSetName();
row[index++] = testResult.getTransformName();
row[index++] = testResult.isError();
row[index++] = testResult.getComment();
putRow(data.outputRowMeta, row);
}
}, //
(test1, testPipelineMeta, e) -> {
// Some configuration or setup error...
//
Object[] row = RowDataUtil.allocateRowData(data.outputRowMeta.size());
int index = 0;
row[index++] = testPipelineMeta == null ? null : testPipelineMeta.getName();
row[index++] = test1.getName();
row[index++] = null;
row[index++] = null;
// ERROR!
row[index++] = Boolean.TRUE;
row[index++] = e.getMessage() + " : " + Const.getStackTracker(e);
ExecuteTests.this.putRow(data.outputRowMeta, row);
});
return true;
} else {
setOutputDone();
return false;
}
}
use of org.apache.hop.testing.UnitTestResult in project hop by apache.
the class RunPipelineTests method execute.
@Override
public Result execute(Result prevResult, int nr) throws HopException {
IHopMetadataSerializer<PipelineUnitTest> testSerializer = getMetadataProvider().getSerializer(PipelineUnitTest.class);
AtomicBoolean success = new AtomicBoolean(true);
for (String testName : testNames) {
PipelineUnitTest test = testSerializer.load(testName);
UnitTestUtil.executeUnitTest(test, this, getLogLevel(), getMetadataProvider(), this, //
(pipeline, result) -> {
if (result.getNrErrors() > 0) {
this.logError("There was an error running the pipeline for unit test '" + test.getName() + "'");
success.set(false);
}
}, // The pipeline ran fine so we can evaluate the test results
(pipeline, testResults) -> {
int errorCount = 0;
for (UnitTestResult testResult : testResults) {
if (testResult.isError()) {
this.logError("Error in validating test data set '" + testResult.getDataSetName() + " : " + testResult.getComment());
errorCount++;
}
}
if (errorCount > 0) {
this.logError("There were test result evaluation errors in pipeline unit test '" + test.getName());
success.set(false);
}
}, (test1, pipelineMeta, e) -> {
this.logError("There was an exception executing pipeline unit test '" + test.getName(), e);
success.set(false);
});
}
if (success.get()) {
prevResult.setNrErrors(0);
prevResult.setResult(true);
} else {
prevResult.setNrErrors(prevResult.getNrErrors() + 1);
prevResult.setResult(false);
}
return prevResult;
}
use of org.apache.hop.testing.UnitTestResult in project hop by apache.
the class LocationMouseDoubleClickExtensionPoint method callExtensionPoint.
@Override
public void callExtensionPoint(ILogChannel log, IVariables variables, HopGuiPipelineGraphExtension pipelineGraphExtension) throws HopException {
HopGuiPipelineGraph pipelineGraph = pipelineGraphExtension.getPipelineGraph();
PipelineMeta pipelineMeta = pipelineGraph.getPipelineMeta();
PipelineUnitTest unitTest = TestingGuiPlugin.getCurrentUnitTest(pipelineMeta);
if (unitTest == null) {
return;
}
HopGui hopGui = HopGui.getInstance();
try {
List<DataSet> dataSets = hopGui.getMetadataProvider().getSerializer(DataSet.class).loadAll();
Map<String, IRowMeta> transformFieldsMap = new HashMap<>();
for (TransformMeta transformMeta : pipelineMeta.getTransforms()) {
try {
IRowMeta transformFields = pipelineMeta.getTransformFields(pipelineGraph.getVariables(), transformMeta);
transformFieldsMap.put(transformMeta.getName(), transformFields);
} catch (Exception e) {
// Ignore GUI errors...
}
}
// Find the location that was double clicked on...
//
MouseEvent e = pipelineGraphExtension.getEvent();
Point point = pipelineGraphExtension.getPoint();
if (e.button == 1 || e.button == 2) {
AreaOwner areaOwner = pipelineGraph.getVisibleAreaOwner(point.x, point.y);
if (areaOwner != null && areaOwner.getAreaType() != null) {
//
if (DataSetConst.AREA_DRAWN_INPUT_DATA_SET.equals(areaOwner.getParent())) {
// Open the dataset double clicked on...
//
String transformName = (String) areaOwner.getOwner();
PipelineUnitTestSetLocation inputLocation = unitTest.findInputLocation(transformName);
if (inputLocation != null) {
PipelineUnitTestSetLocationDialog dialog = new PipelineUnitTestSetLocationDialog(hopGui.getShell(), variables, hopGui.getMetadataProvider(), inputLocation, dataSets, transformFieldsMap);
if (dialog.open()) {
hopGui.getMetadataProvider().getSerializer(PipelineUnitTest.class).save(unitTest);
pipelineGraph.updateGui();
}
}
} else if (DataSetConst.AREA_DRAWN_GOLDEN_DATA_SET.equals(areaOwner.getParent())) {
// Open the dataset double clicked on...
//
String transformName = (String) areaOwner.getOwner();
PipelineUnitTestSetLocation goldenLocation = unitTest.findGoldenLocation(transformName);
if (goldenLocation != null) {
PipelineUnitTestSetLocationDialog dialog = new PipelineUnitTestSetLocationDialog(hopGui.getShell(), variables, hopGui.getMetadataProvider(), goldenLocation, dataSets, transformFieldsMap);
if (dialog.open()) {
// Save the unit test
hopGui.getMetadataProvider().getSerializer(PipelineUnitTest.class).save(unitTest);
pipelineGraph.updateGui();
}
}
} else if (DataSetConst.AREA_DRAWN_GOLDEN_DATA_RESULT.equals(areaOwner.getParent())) {
// Open the dataset double clicked on...
//
String transformName = (String) areaOwner.getOwner();
PipelineUnitTestSetLocation goldenLocation = unitTest.findGoldenLocation(transformName);
if (goldenLocation != null) {
// Find the errors list of the unit test...
//
IPipelineEngine<PipelineMeta> pipeline = pipelineGraph.getPipeline();
if (pipeline == null) {
return;
}
List<UnitTestResult> results = (List<UnitTestResult>) pipeline.getExtensionDataMap().get(DataSetConst.UNIT_TEST_RESULTS);
if (results == null || results.isEmpty()) {
return;
}
ValidatePipelineUnitTestExtensionPoint.showUnitTestErrors(pipeline, results, hopGui);
}
}
}
}
} catch (Exception e) {
new ErrorDialog(hopGui.getShell(), "Error", "Error editing location", e);
}
}
use of org.apache.hop.testing.UnitTestResult in project hop by apache.
the class ValidatePipelineUnitTestExtensionPoint method callExtensionPoint.
@Override
public void callExtensionPoint(ILogChannel log, IVariables variables, IPipelineEngine<PipelineMeta> pipeline) throws HopException {
final PipelineMeta pipelineMeta = pipeline.getPipelineMeta();
boolean runUnitTest = "Y".equalsIgnoreCase(pipeline.getVariable(DataSetConst.VAR_RUN_UNIT_TEST));
if (!runUnitTest) {
return;
}
// We should always have a unit test name here...
String unitTestName = pipeline.getVariable(DataSetConst.VAR_UNIT_TEST_NAME);
if (StringUtil.isEmpty(unitTestName)) {
return;
}
try {
IHopMetadataProvider metadataProvider = pipelineMeta.getMetadataProvider();
if (metadataProvider == null) {
// Nothing to do here, we can't reference data sets.
return;
}
// If the pipeline has a variable set with the unit test in it, we're dealing with a unit test
// situation.
//
PipelineUnitTest unitTest = metadataProvider.getSerializer(PipelineUnitTest.class).load(unitTestName);
final List<UnitTestResult> results = new ArrayList<>();
pipeline.getExtensionDataMap().put(DataSetConst.UNIT_TEST_RESULTS, results);
// Validate execution results with what's in the data sets...
//
int errors = DataSetConst.validateTransformResultAgainstUnitTest(pipeline, unitTest, metadataProvider, results);
if (errors == 0) {
log.logBasic("Unit test '" + unitTest.getName() + "' passed successfully");
} else {
log.logBasic("Unit test '" + unitTest.getName() + "' failed, " + errors + " errors detected, " + results.size() + " comments to report.");
String dontShowResults = pipeline.getVariable(DataSetConst.VAR_DO_NOT_SHOW_UNIT_TEST_ERRORS, "N");
if ("N".equalsIgnoreCase(dontShowResults)) {
final HopGui hopGui = HopGui.getInstance();
if (hopGui != null) {
showUnitTestErrors(pipeline, results, hopGui);
}
}
}
log.logBasic("----------------------------------------------");
for (UnitTestResult result : results) {
if (result.getDataSetName() != null) {
log.logBasic(result.getTransformName() + " - " + result.getDataSetName() + " : " + result.getComment());
} else {
log.logBasic(result.getComment());
}
}
log.logBasic("----------------------------------------------");
} catch (Throwable e) {
log.logError("Unable to validate unit test/golden rows", e);
}
}
Aggregations