use of org.pentaho.di.core.logging.LogChannel in project pentaho-kettle by pentaho.
the class StepMockHelper method redirectLog.
/**
* In case you need to use log methods during the tests
* use redirectLog method after creating new StepMockHelper object.
* Examples:
* stepMockHelper.redirectLog( System.out, LogLevel.ROWLEVEL );
* stepMockHelper.redirectLog( new FileOutputStream("log.txt"), LogLevel.BASIC );
*/
public void redirectLog(final OutputStream out, LogLevel channelLogLevel) {
final LogChannel log = spy(new LogChannel(this.getClass().getName(), true));
log.setLogLevel(channelLogLevel);
when(logChannelInterfaceFactory.create(any(), any(LoggingObjectInterface.class))).thenReturn(log);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
LogLevel logLevel = (LogLevel) args[1];
LogLevel channelLogLevel = log.getLogLevel();
if (!logLevel.isVisible(channelLogLevel)) {
// not for our eyes.
return null;
}
if (channelLogLevel.getLevel() >= logLevel.getLevel()) {
LogMessageInterface logMessage = (LogMessageInterface) args[0];
out.write(logMessage.getMessage().getBytes());
out.write('\n');
out.write('\r');
out.flush();
return true;
}
return false;
}
}).when(log).println((LogMessageInterface) anyObject(), (LogLevel) anyObject());
}
use of org.pentaho.di.core.logging.LogChannel in project pentaho-kettle by pentaho.
the class TransExecutorUnitTest method testExecuteTrans.
@Test
public // PDI-16066
void testExecuteTrans() throws KettleException {
String childParam = "childParam";
String childValue = "childValue";
String paramOverwrite = "paramOverwrite";
String parentValue = "parentValue";
meta.getParameters().setVariable(new String[] { childParam, paramOverwrite });
meta.getParameters().setInput(new String[] { childValue, childValue });
Trans parent = new Trans();
Mockito.when(executor.getTrans()).thenReturn(parent);
executor.init(meta, data);
executor.setVariable(paramOverwrite, parentValue);
Mockito.when(executor.getLogLevel()).thenReturn(LogLevel.NOTHING);
parent.setLog(new LogChannel(this));
Mockito.doCallRealMethod().when(executor).createInternalTrans();
Mockito.when(executor.getData().getExecutorTransMeta().listVariables()).thenReturn(new String[0]);
Mockito.when(executor.getData().getExecutorTransMeta().listParameters()).thenReturn(new String[0]);
Trans internalTrans = executor.createInternalTrans();
executor.getData().setExecutorTrans(internalTrans);
executor.passParametersToTrans();
// When the child parameter does exist in the parent parameters, overwrite the child parameter by the parent parameter.
Assert.assertEquals(parentValue, internalTrans.getVariable(paramOverwrite));
// All other parent parameters need to get copied into the child parameters (when the 'Inherit all variables from the transformation?' option is checked)
Assert.assertEquals(childValue, internalTrans.getVariable(childParam));
}
use of org.pentaho.di.core.logging.LogChannel in project pentaho-kettle by pentaho.
the class FileStreamTest method before.
@Before
public void before() throws IOException, KettleException {
streamFile = temporaryFolder.newFile();
writer = new FileWriter(streamFile);
KettleEnvironment.init();
trans.setTransMeta(transMeta);
trans.setLog(new LogChannel(this));
streamMeta.setTransformationPath(getClass().getResource("/subtrans.ktr").getPath());
streamMeta.setBatchDuration("5");
streamMeta.setBatchSize("1");
streamMeta.setSourcePath(streamFile.getPath());
when(stepMeta.getName()).thenReturn("mocked name");
when(stepMeta.getStepMetaInterface()).thenReturn(streamMeta);
when(transMeta.findStep(any())).thenReturn(stepMeta);
}
use of org.pentaho.di.core.logging.LogChannel in project pentaho-kettle by pentaho.
the class StreamToTransNodeConverter method convertPostRepoSave.
public void convertPostRepoSave(RepositoryFile repositoryFile) {
if (repositoryFile != null) {
try {
Repository repo = connectToRepository();
if (repo != null) {
TransMeta transMeta = repo.loadTransformation(new StringObjectId(repositoryFile.getId().toString()), null);
ExtensionPointHandler.callExtensionPoint(new LogChannel(this), KettleExtensionPoint.TransImportAfterSaveToRepo.id, transMeta);
}
} catch (Exception e) {
logger.error(KettleExtensionPoint.TransImportAfterSaveToRepo.id, e);
}
}
}
use of org.pentaho.di.core.logging.LogChannel in project pentaho-kettle by pentaho.
the class PurRepository method init.
@Override
public void init(final RepositoryMeta repositoryMeta) {
this.log = new LogChannel(this.getClass().getSimpleName());
this.repositoryMeta = (PurRepositoryMeta) repositoryMeta;
purRepositoryConnector = new PurRepositoryConnector(this, this.repositoryMeta, rootRef);
}
Aggregations