Search in sources :

Example 61 with LogChannelInterface

use of org.pentaho.di.core.logging.LogChannelInterface in project pentaho-kettle by pentaho.

the class SalesforceConnectionIT method testConnect.

private void testConnect(String password) throws Exception {
    LogChannelInterface logInterface = mock(LogChannelInterface.class);
    String url = "http://localhost/services/Soap/u/37.0";
    String username = "MySampleUsername";
    SalesforceConnection connection;
    connection = spy(new SalesforceConnection(logInterface, url, username, password));
    ArgumentCaptor<ConnectorConfig> captorConfig = ArgumentCaptor.forClass(ConnectorConfig.class);
    ConnectorConfig mockConfig = mock(ConnectorConfig.class);
    doReturn(UUID.randomUUID().toString()).when(mockConfig).getUsername();
    doReturn(UUID.randomUUID().toString()).when(mockConfig).getPassword();
    doReturn(mockConfig).when(bindingStub).getConfig();
    doReturn(mock(LoginResult.class)).when(bindingStub).login(anyString(), anyString());
    try {
        connection.connect();
    } catch (KettleException e) {
    // The connection should fail
    // We just want to see the generated ConnectorConfig
    }
    verify(connection).createBinding(captorConfig.capture());
    assertEquals(username, captorConfig.getValue().getUsername());
    // Password is unchanged (not decrypted) when setting in ConnectorConfig
    assertEquals(password, captorConfig.getValue().getPassword());
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ConnectorConfig(com.sforce.ws.ConnectorConfig) LoginResult(com.sforce.soap.partner.LoginResult) Matchers.anyString(org.mockito.Matchers.anyString) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface)

Example 62 with LogChannelInterface

use of org.pentaho.di.core.logging.LogChannelInterface in project pentaho-kettle by pentaho.

the class BaseStepTest method testBaseStepPutRowLocalSpecialPartitioning.

/**
 * This test checks that data from one non-partitioned step copies to 2 partitioned steps right.
 *
 * @throws KettleException
 * @see {@link <a href="http://jira.pentaho.com/browse/PDI-12211">http://jira.pentaho.com/browse/PDI-12211<a>}
 */
@Test
public void testBaseStepPutRowLocalSpecialPartitioning() throws KettleException {
    List<StepMeta> stepMetas = new ArrayList<StepMeta>();
    stepMetas.add(mockHelper.stepMeta);
    stepMetas.add(mockHelper.stepMeta);
    StepPartitioningMeta stepPartitioningMeta = spy(new StepPartitioningMeta());
    BasePartitioner partitioner = mock(BasePartitioner.class);
    when(mockHelper.logChannelInterfaceFactory.create(any(), any(LoggingObjectInterface.class))).thenAnswer(new Answer<LogChannelInterface>() {

        @Override
        public LogChannelInterface answer(InvocationOnMock invocation) throws Throwable {
            ((BaseStep) invocation.getArguments()[0]).getLogLevel();
            return mockHelper.logChannelInterface;
        }
    });
    when(mockHelper.trans.isRunning()).thenReturn(true);
    when(mockHelper.transMeta.findNextSteps(any(StepMeta.class))).thenReturn(stepMetas);
    when(mockHelper.stepMeta.getStepPartitioningMeta()).thenReturn(stepPartitioningMeta);
    when(stepPartitioningMeta.getPartitioner()).thenReturn(partitioner);
    when(partitioner.getNrPartitions()).thenReturn(2);
    Object object0 = "name0";
    ValueMetaInterface meta0 = new ValueMetaString(object0.toString());
    Object object1 = "name1";
    ValueMetaInterface meta2 = new ValueMetaString(object1.toString());
    RowMetaInterface rowMeta0 = new RowMeta();
    rowMeta0.addValueMeta(meta0);
    Object[] objects0 = { object0 };
    RowMetaInterface rowMeta1 = new RowMeta();
    rowMeta1.addValueMeta(meta2);
    Object[] objects1 = { object1 };
    when(stepPartitioningMeta.getPartition(rowMeta0, objects0)).thenReturn(0);
    when(stepPartitioningMeta.getPartition(rowMeta1, objects1)).thenReturn(1);
    BlockingRowSet[] rowSet = { new BlockingRowSet(2), new BlockingRowSet(2), new BlockingRowSet(2), new BlockingRowSet(2) };
    List<RowSet> outputRowSets = new ArrayList<RowSet>();
    outputRowSets.addAll(Arrays.asList(rowSet));
    BaseStep baseStep = new BaseStep(mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans);
    baseStep.setStopped(false);
    baseStep.setRepartitioning(StepPartitioningMeta.PARTITIONING_METHOD_SPECIAL);
    baseStep.setOutputRowSets(outputRowSets);
    baseStep.putRow(rowMeta0, objects0);
    baseStep.putRow(rowMeta1, objects1);
    assertEquals(object0, baseStep.getOutputRowSets().get(0).getRow()[0]);
    assertEquals(object1, baseStep.getOutputRowSets().get(1).getRow()[0]);
    assertEquals(object0, baseStep.getOutputRowSets().get(2).getRow()[0]);
    assertEquals(object1, baseStep.getOutputRowSets().get(3).getRow()[0]);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ArrayList(java.util.ArrayList) QueueRowSet(org.pentaho.di.core.QueueRowSet) SingleRowRowSet(org.pentaho.di.core.SingleRowRowSet) RowSet(org.pentaho.di.core.RowSet) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) BasePartitioner(org.pentaho.di.trans.BasePartitioner) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NonAccessibleFileObject(org.pentaho.di.core.fileinput.NonAccessibleFileObject) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Test(org.junit.Test)

Example 63 with LogChannelInterface

use of org.pentaho.di.core.logging.LogChannelInterface in project pentaho-kettle by pentaho.

the class SniffStepServletIT method testSniffStepServletEscapesHtmlWhenTransFound.

@Test
public void testSniffStepServletEscapesHtmlWhenTransFound() throws ServletException, IOException {
    KettleLogStore.init();
    HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
    Trans mockTrans = mock(Trans.class);
    TransMeta mockTransMeta = mock(TransMeta.class);
    StepInterface mockStepInterface = mock(StepInterface.class);
    List<StepInterface> stepInterfaces = new ArrayList<StepInterface>();
    stepInterfaces.add(mockStepInterface);
    LogChannelInterface mockChannelInterface = mock(LogChannelInterface.class);
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    when(mockHttpServletRequest.getContextPath()).thenReturn(SniffStepServlet.CONTEXT_PATH);
    when(mockHttpServletRequest.getParameter(anyString())).thenReturn(ServletTestUtils.BAD_STRING);
    when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
    when(mockTransformationMap.getTransformation(any(CarteObjectEntry.class))).thenReturn(mockTrans);
    when(mockTrans.getLogChannel()).thenReturn(mockChannelInterface);
    when(mockTrans.getLogChannelId()).thenReturn("test");
    when(mockTrans.getTransMeta()).thenReturn(mockTransMeta);
    when(mockTransMeta.getMaximum()).thenReturn(new Point(10, 10));
    when(mockTrans.findBaseSteps(ServletTestUtils.BAD_STRING)).thenReturn(stepInterfaces);
    sniffStepServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) StepInterface(org.pentaho.di.trans.step.StepInterface) StringWriter(java.io.StringWriter) TransMeta(org.pentaho.di.trans.TransMeta) ArrayList(java.util.ArrayList) HttpServletResponse(javax.servlet.http.HttpServletResponse) Point(org.pentaho.di.core.gui.Point) Trans(org.pentaho.di.trans.Trans) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 64 with LogChannelInterface

use of org.pentaho.di.core.logging.LogChannelInterface in project pentaho-kettle by pentaho.

the class StopJobServletIT method testStopJobServletEscapesHtmlWhenTransFound.

@Test
public void testStopJobServletEscapesHtmlWhenTransFound() throws ServletException, IOException {
    KettleLogStore.init();
    HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
    Job mockJob = mock(Job.class);
    JobMeta mockJobMeta = mock(JobMeta.class);
    LogChannelInterface mockLogChannelInterface = mock(LogChannelInterface.class);
    mockJob.setName(ServletTestUtils.BAD_STRING);
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    when(mockHttpServletRequest.getContextPath()).thenReturn(StopJobServlet.CONTEXT_PATH);
    when(mockHttpServletRequest.getParameter(anyString())).thenReturn(ServletTestUtils.BAD_STRING);
    when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
    when(mockJobMap.getJob(any(CarteObjectEntry.class))).thenReturn(mockJob);
    when(mockJob.getLogChannelId()).thenReturn(ServletTestUtils.BAD_STRING);
    when(mockJob.getLogChannel()).thenReturn(mockLogChannelInterface);
    when(mockJob.getJobMeta()).thenReturn(mockJobMeta);
    when(mockJobMeta.getMaximum()).thenReturn(new Point(10, 10));
    stopJobServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JobMeta(org.pentaho.di.job.JobMeta) StringWriter(java.io.StringWriter) HttpServletResponse(javax.servlet.http.HttpServletResponse) Point(org.pentaho.di.core.gui.Point) Job(org.pentaho.di.job.Job) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 65 with LogChannelInterface

use of org.pentaho.di.core.logging.LogChannelInterface in project pentaho-kettle by pentaho.

the class JobEntryWriteToLogTest method verifyErrorMessageForParentJobLogLevel.

private void verifyErrorMessageForParentJobLogLevel(LogLevel parentJobLogLevel, VerificationMode mode) {
    jobEntry.setLogMessage("TEST");
    jobEntry.setEntryLogLevel(LogLevel.ERROR);
    doReturn(parentJobLogLevel).when(parentJob).getLogLevel();
    jobEntry.setParentJob(parentJob);
    LogChannelInterface logChannel = spy(jobEntry.createLogChannel());
    doReturn(logChannel).when(jobEntry).createLogChannel();
    jobEntry.evaluate(new Result());
    verify(logChannel, mode).logError("TEST" + Const.CR);
}
Also used : LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Result(org.pentaho.di.core.Result)

Aggregations

LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)85 Test (org.junit.Test)53 PrintWriter (java.io.PrintWriter)29 TransMeta (org.pentaho.di.trans.TransMeta)29 HttpServletRequest (javax.servlet.http.HttpServletRequest)27 HttpServletResponse (javax.servlet.http.HttpServletResponse)27 StringWriter (java.io.StringWriter)26 Point (org.pentaho.di.core.gui.Point)26 Trans (org.pentaho.di.trans.Trans)23 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)19 Job (org.pentaho.di.job.Job)17 JobMeta (org.pentaho.di.job.JobMeta)15 KettleException (org.pentaho.di.core.exception.KettleException)12 ArrayList (java.util.ArrayList)9 Matchers.anyString (org.mockito.Matchers.anyString)7 LogChannel (org.pentaho.di.core.logging.LogChannel)6 AbstractMeta (org.pentaho.di.base.AbstractMeta)5 Repository (org.pentaho.di.repository.Repository)5 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)5 ExtensionPointWrapper (org.pentaho.di.ui.core.events.dialog.extension.ExtensionPointWrapper)5