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);
}
}
}
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
}
}
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());
}
}
Aggregations