Search in sources :

Example 31 with LogChannel

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());
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) LogMessageInterface(org.pentaho.di.core.logging.LogMessageInterface) LogChannel(org.pentaho.di.core.logging.LogChannel) Matchers.anyObject(org.mockito.Matchers.anyObject) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) LogLevel(org.pentaho.di.core.logging.LogLevel)

Example 32 with LogChannel

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));
}
Also used : LogChannel(org.pentaho.di.core.logging.LogChannel) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Trans(org.pentaho.di.trans.Trans) Test(org.junit.Test)

Example 33 with LogChannel

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);
}
Also used : FileWriter(java.io.FileWriter) LogChannel(org.pentaho.di.core.logging.LogChannel) Before(org.junit.Before)

Example 34 with LogChannel

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);
        }
    }
}
Also used : Repository(org.pentaho.di.repository.Repository) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) TransMeta(org.pentaho.di.trans.TransMeta) LogChannel(org.pentaho.di.core.logging.LogChannel) StringObjectId(org.pentaho.di.repository.StringObjectId) KettleException(org.pentaho.di.core.exception.KettleException)

Example 35 with LogChannel

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);
}
Also used : LogChannel(org.pentaho.di.core.logging.LogChannel)

Aggregations

LogChannel (org.pentaho.di.core.logging.LogChannel)44 TransMeta (org.pentaho.di.trans.TransMeta)17 TransExecutionConfiguration (org.pentaho.di.trans.TransExecutionConfiguration)13 TransSplitter (org.pentaho.di.trans.cluster.TransSplitter)13 Test (org.junit.Test)8 File (java.io.File)6 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)6 Before (org.junit.Before)4 Repository (org.pentaho.di.repository.Repository)4 Node (org.w3c.dom.Node)4 IOException (java.io.IOException)3 FileObject (org.apache.commons.vfs2.FileObject)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 SlaveServer (org.pentaho.di.cluster.SlaveServer)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Display (org.eclipse.swt.widgets.Display)2 Matchers.anyObject (org.mockito.Matchers.anyObject)2 KettleException (org.pentaho.di.core.exception.KettleException)2