Search in sources :

Example 41 with LogChannelInterface

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

the class RunConfigurationDelegateTest method testUpdateLoadedJobs_Exception.

@Test
public void testUpdateLoadedJobs_Exception() throws Exception {
    JobEntryTrans trans = new JobEntryTrans();
    trans.setRunConfiguration("key");
    JobMeta meta = new JobMeta();
    meta.addJobEntry(new JobEntryCopy(trans));
    JobMeta[] jobs = new JobMeta[] { meta };
    doReturn(jobs).when(spoon).getLoadedJobs();
    DefaultRunConfiguration config = new DefaultRunConfiguration();
    config.setName("Test");
    config.setServer("localhost");
    LogChannelInterface log = mock(LogChannelInterface.class);
    doReturn(log).when(spoon).getLog();
    PowerMockito.mockStatic(ExtensionPointHandler.class);
    PowerMockito.when(ExtensionPointHandler.class, "callExtensionPoint", any(), any(), any()).thenThrow(KettleException.class);
    delegate.updateLoadedJobs("key", config);
    verify(log, times(1)).logBasic(any());
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntryTrans(org.pentaho.di.job.entries.trans.JobEntryTrans) DefaultRunConfiguration(org.pentaho.di.engine.configuration.impl.pentaho.DefaultRunConfiguration) ExtensionPointHandler(org.pentaho.di.core.extension.ExtensionPointHandler) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 42 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 43 with LogChannelInterface

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

the class LogBrowser method installLogSniffer.

public void installLogSniffer() {
    // Create a new buffer appender to the log and capture that directly...
    // 
    final AtomicInteger lastLogId = new AtomicInteger(-1);
    final AtomicBoolean busy = new AtomicBoolean(false);
    final KettleLogLayout logLayout = new KettleLogLayout(true);
    final StyleRange normalLogLineStyle = new StyleRange();
    normalLogLineStyle.foreground = GUIResource.getInstance().getColorBlue();
    final StyleRange errorLogLineStyle = new StyleRange();
    errorLogLineStyle.foreground = GUIResource.getInstance().getColorRed();
    // Refresh the log every second or so
    // 
    final Timer logRefreshTimer = new Timer("log sniffer Timer");
    TimerTask timerTask = new TimerTask() {

        public void run() {
            if (text.isDisposed()) {
                return;
            }
            text.getDisplay().asyncExec(new Runnable() {

                public void run() {
                    HasLogChannelInterface provider = logProvider.getLogChannelProvider();
                    if (provider != null && !text.isDisposed() && !busy.get() && !paused.get() && text.isVisible()) {
                        busy.set(true);
                        LogChannelInterface logChannel = provider.getLogChannel();
                        String parentLogChannelId = logChannel.getLogChannelId();
                        LoggingRegistry registry = LoggingRegistry.getInstance();
                        Date registryModDate = registry.getLastModificationTime();
                        if (childIds == null || lastLogRegistryChange == null || registryModDate.compareTo(lastLogRegistryChange) > 0) {
                            lastLogRegistryChange = registry.getLastModificationTime();
                            childIds = LoggingRegistry.getInstance().getLogChannelChildren(parentLogChannelId);
                        }
                        // See if we need to log any lines...
                        // 
                        int lastNr = KettleLogStore.getLastBufferLineNr();
                        if (lastNr > lastLogId.get()) {
                            List<KettleLoggingEvent> logLines = KettleLogStore.getLogBufferFromTo(childIds, true, lastLogId.get(), lastNr);
                            // The maximum size of the log buffer
                            // 
                            int maxSize = Props.getInstance().getMaxNrLinesInLog() * 150;
                            synchronized (text) {
                                for (int i = 0; i < logLines.size(); i++) {
                                    KettleLoggingEvent event = logLines.get(i);
                                    String line = logLayout.format(event).trim();
                                    int start = text.getText().length();
                                    int length = line.length();
                                    if (length > 0) {
                                        Format format = TextFormatter.getInstance().execute(line);
                                        text.append(format.getText());
                                        text.append(Const.CR);
                                        for (StyleRange styleRange : format.getStyleRanges()) {
                                            styleRange.start += start;
                                            text.setStyleRange(styleRange);
                                        }
                                        if (event.getLevel() == LogLevel.ERROR) {
                                            StyleRange styleRange = new StyleRange();
                                            styleRange.foreground = GUIResource.getInstance().getColorRed();
                                            styleRange.start = start;
                                            styleRange.length = length;
                                            text.setStyleRange(styleRange);
                                        } else {
                                            StyleRange styleRange = new StyleRange();
                                            styleRange.foreground = GUIResource.getInstance().getColorBlue();
                                            styleRange.start = start;
                                            styleRange.length = Math.min(20, length);
                                            text.setStyleRange(styleRange);
                                        }
                                    }
                                }
                            }
                            // Erase it all in one go
                            // This makes it a bit more efficient
                            // 
                            int size = text.getText().length();
                            if (maxSize > 0 && size > maxSize) {
                                int dropIndex = (text.getText().indexOf(Const.CR, size - maxSize)) + Const.CR.length();
                                text.replaceTextRange(0, dropIndex, "");
                            }
                            text.setSelection(text.getText().length());
                            lastLogId.set(lastNr);
                        }
                        busy.set(false);
                    }
                }
            });
        }
    };
    // Refresh every often enough
    // 
    logRefreshTimer.schedule(timerTask, Const.toInt(EnvUtil.getSystemProperty(Const.KETTLE_LOG_TAB_REFRESH_DELAY), 1000), Const.toInt(EnvUtil.getSystemProperty(Const.KETTLE_LOG_TAB_REFRESH_PERIOD), 1000));
    text.addListener(SWT.MouseDown, e -> {
        try {
            int offset = text.getOffsetAtLocation(new Point(e.x, e.y));
            StyleRange style = text.getStyleRangeAtOffset(offset);
            if (style != null && style.underline && style.underlineStyle == SWT.UNDERLINE_LINK) {
                if (Desktop.isDesktopSupported()) {
                    Desktop.getDesktop().browse(new URI((String) style.data));
                }
            }
        } catch (Exception ex) {
        // no character under event.x, event.y
        }
    });
    // Make sure the timer goes down when the widget is disposed
    // 
    text.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent event) {
            logRefreshTimer.cancel();
        }
    });
    final Menu menu = new Menu(text);
    MenuItem item = new MenuItem(menu, SWT.NONE);
    item.setText(BaseMessages.getString(PKG, "LogBrowser.CopySelectionToClipboard.MenuItem"));
    item.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            String selection = text.getSelectionText();
            if (!Utils.isEmpty(selection)) {
                GUIResource.getInstance().toClipboard(selection);
            }
        }
    });
    text.setMenu(menu);
    text.addMouseListener(new MouseAdapter() {

        public void mouseDown(MouseEvent event) {
            if (event.button == 3) {
                ConstUI.displayMenu(menu, text);
            }
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) LoggingRegistry(org.pentaho.di.core.logging.LoggingRegistry) StyleRange(org.eclipse.swt.custom.StyleRange) HasLogChannelInterface(org.pentaho.di.core.logging.HasLogChannelInterface) DisposeEvent(org.eclipse.swt.events.DisposeEvent) URI(java.net.URI) Format(org.pentaho.di.ui.core.widget.text.Format) TimerTask(java.util.TimerTask) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) KettleLoggingEvent(org.pentaho.di.core.logging.KettleLoggingEvent) Menu(org.eclipse.swt.widgets.Menu) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) KettleLogLayout(org.pentaho.di.core.logging.KettleLogLayout) Point(org.eclipse.swt.graphics.Point) Date(java.util.Date) Point(org.eclipse.swt.graphics.Point) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Timer(java.util.Timer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HasLogChannelInterface(org.pentaho.di.core.logging.HasLogChannelInterface) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface)

Example 44 with LogChannelInterface

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

the class OpenMappingExtensionTest method setKettleLogFactoryWithMock.

private void setKettleLogFactoryWithMock() {
    LogChannelInterfaceFactory logChannelInterfaceFactory = mock(LogChannelInterfaceFactory.class);
    logChannelInterface = mock(LogChannelInterface.class);
    when(logChannelInterfaceFactory.create(any())).thenReturn(logChannelInterface);
    KettleLogStore.setLogChannelInterfaceFactory(logChannelInterfaceFactory);
}
Also used : LogChannelInterfaceFactory(org.pentaho.di.core.logging.LogChannelInterfaceFactory) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface)

Example 45 with LogChannelInterface

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

the class SniffStepServletTest method testSniffStepServletEscapesHtmlWhenTransFound.

@Test
@PrepareForTest({ Encode.class })
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);
    PowerMockito.spy(Encode.class);
    when(mockHttpServletRequest.getContextPath()).thenReturn(SniffStepServlet.CONTEXT_PATH);
    when(mockHttpServletRequest.getParameter(anyString())).thenReturn(ServletTestUtils.BAD_STRING_TO_TEST);
    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_TO_TEST)).thenReturn(stepInterfaces);
    sniffStepServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
    PowerMockito.verifyStatic(atLeastOnce());
    Encode.forHtml(anyString());
}
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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)65 Test (org.junit.Test)42 HttpServletRequest (javax.servlet.http.HttpServletRequest)27 HttpServletResponse (javax.servlet.http.HttpServletResponse)27 PrintWriter (java.io.PrintWriter)26 Point (org.pentaho.di.core.gui.Point)26 StringWriter (java.io.StringWriter)25 TransMeta (org.pentaho.di.trans.TransMeta)24 Trans (org.pentaho.di.trans.Trans)20 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)16 KettleException (org.pentaho.di.core.exception.KettleException)12 JobMeta (org.pentaho.di.job.JobMeta)12 Job (org.pentaho.di.job.Job)11 ArrayList (java.util.ArrayList)8 LogChannel (org.pentaho.di.core.logging.LogChannel)6 Matchers.anyString (org.mockito.Matchers.anyString)5 Before (org.junit.Before)4 StepInterface (org.pentaho.di.trans.step.StepInterface)4 ServletOutputStream (javax.servlet.ServletOutputStream)3 LoggingObjectInterface (org.pentaho.di.core.logging.LoggingObjectInterface)3