Search in sources :

Example 81 with LogChannelInterface

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

the class GetTransStatusServletIT method testGetTransStatusServletEscapesHtmlWhenTransFound.

@Test
public void testGetTransStatusServletEscapesHtmlWhenTransFound() 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);
    LogChannelInterface mockChannelInterface = mock(LogChannelInterface.class);
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    when(mockHttpServletRequest.getContextPath()).thenReturn(GetTransStatusServlet.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.getTransMeta()).thenReturn(mockTransMeta);
    when(mockTransMeta.getMaximum()).thenReturn(new Point(10, 10));
    getTransStatusServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(out.toString().contains(ServletTestUtils.BAD_STRING));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) StringWriter(java.io.StringWriter) TransMeta(org.pentaho.di.trans.TransMeta) 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 82 with LogChannelInterface

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

the class GetJobStatusServletIT method testGetJobStatusServletEscapesHtmlWhenTransFound.

@Test
public void testGetJobStatusServletEscapesHtmlWhenTransFound() 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(GetJobStatusServlet.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.getLogChannel()).thenReturn(mockLogChannelInterface);
    when(mockJob.getJobMeta()).thenReturn(mockJobMeta);
    when(mockJobMeta.getMaximum()).thenReturn(new Point(10, 10));
    getJobStatusServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(out.toString().contains(ServletTestUtils.BAD_STRING));
}
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 83 with LogChannelInterface

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

the class SpoonTest method prepareSetSaveTests.

private static void prepareSetSaveTests(Spoon spoon, LogChannelInterface log, SpoonPerspective spoonPerspective, AbstractMeta metaData, boolean repIsNull, boolean basicLevel, String perspectiveID, boolean saveToRepository, boolean saveXMLFile, String fileType, String filename, boolean objectIdIsNull, boolean canSave) throws Exception {
    TabMapEntry mockTabMapEntry = mock(TabMapEntry.class);
    TabItem mockTabItem = mock(TabItem.class);
    Repository mockRepository = mock(Repository.class);
    DelegatingMetaStore mockMetaStore = mock(DelegatingMetaStore.class);
    spoon.rep = repIsNull ? null : mockRepository;
    spoon.metaStore = mockMetaStore;
    spoon.delegates = mock(SpoonDelegates.class);
    spoon.delegates.tabs = mock(SpoonTabsDelegate.class);
    spoon.props = mock(PropsUI.class);
    doReturn(mock(LogChannelInterface.class)).when(spoon).getLog();
    doReturn(perspectiveID).when(spoonPerspective).getId();
    doReturn(basicLevel).when(log).isBasic();
    doReturn(basicLevel).when(log).isDetailed();
    doReturn(mockTabMapEntry).when(spoon.delegates.tabs).findTabMapEntry(any());
    doReturn(mockTabItem).when(mockTabMapEntry).getTabItem();
    doReturn(saveToRepository).when(spoon).saveToRepository(metaData, true);
    doReturn(saveXMLFile).when(spoon).saveXMLFile(metaData, false);
    if (objectIdIsNull) {
        doReturn(null).when(metaData).getObjectId();
    } else {
        doReturn(new ObjectId() {

            @Override
            public String getId() {
                return "objectId";
            }
        }).when(metaData).getObjectId();
    }
    // saveFile
    doReturn(filename).when(metaData).getFilename();
    doReturn(canSave).when(metaData).canSave();
    doReturn(false).when(spoon.props).useDBCache();
    doReturn(saveToRepository).when(spoon).saveToRepository(metaData);
    doReturn(saveXMLFile).when(spoon).save(metaData, filename, false);
    doReturn(fileType).when(metaData).getFileType();
}
Also used : TabItem(org.pentaho.xul.swt.tab.TabItem) Repository(org.pentaho.di.repository.Repository) ObjectId(org.pentaho.di.repository.ObjectId) DelegatingMetaStore(org.pentaho.metastore.stores.delegate.DelegatingMetaStore) Matchers.anyString(org.mockito.Matchers.anyString) SpoonDelegates(org.pentaho.di.ui.spoon.delegates.SpoonDelegates) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) SpoonTabsDelegate(org.pentaho.di.ui.spoon.delegates.SpoonTabsDelegate) PropsUI(org.pentaho.di.ui.core.PropsUI)

Example 84 with LogChannelInterface

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

the class SelectionAdapterFileDialogTest method testWidgetSelectedHelper.

@Test
public void testWidgetSelectedHelper() {
    // SETUP
    LogChannelInterface log = mock(LogChannelInterface.class);
    StringBuilder textVar = new StringBuilder();
    AbstractMeta meta = mock(AbstractMeta.class);
    RepositoryUtility repositoryUtility = mock(RepositoryUtility.class);
    ExtensionPointWrapper extensionPointWrapper = mock(ExtensionPointWrapper.class);
    SelectionAdapterOptions options = new SelectionAdapterOptions(SelectionOperation.FILE);
    SelectionEvent event = mock(SelectionEvent.class);
    String testPath = "/home/devuser/some/path";
    when(meta.environmentSubstitute(testPath)).thenReturn(testPath);
    SelectionAdapterFileDialog testInstance1 = createTestInstance(log, textVar, meta, options, repositoryUtility, extensionPointWrapper);
    testInstance1.setText(testPath);
    testInstance1.widgetSelected(event);
    assertEquals(testInstance1.getText(), testPath);
}
Also used : ExtensionPointWrapper(org.pentaho.di.ui.core.events.dialog.extension.ExtensionPointWrapper) AbstractMeta(org.pentaho.di.base.AbstractMeta) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Test(org.junit.Test)

Example 85 with LogChannelInterface

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

the class SelectionAdapterFileDialogTest method createTestInstance.

protected SelectionAdapterFileDialog createTestInstance() {
    LogChannelInterface log = mock(LogChannelInterface.class);
    StringBuilder textWidget = new StringBuilder();
    AbstractMeta meta = mock(AbstractMeta.class);
    RepositoryUtility repositoryUtility = mock(RepositoryUtility.class);
    ExtensionPointWrapper extensionPointWrapper = mock(ExtensionPointWrapper.class);
    SelectionAdapterOptions options = new SelectionAdapterOptions(SelectionOperation.FILE, new String[] {}, "");
    return createTestInstance(log, textWidget, meta, options, repositoryUtility, extensionPointWrapper);
}
Also used : ExtensionPointWrapper(org.pentaho.di.ui.core.events.dialog.extension.ExtensionPointWrapper) AbstractMeta(org.pentaho.di.base.AbstractMeta) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface)

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