Search in sources :

Example 1 with LogChannelInterface

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

the class BaseRuntimeExtensionPointTest method testTransCreateExecutionProfile.

@Test
public void testTransCreateExecutionProfile() throws Exception {
    Trans trans = Mockito.mock(Trans.class);
    IExecutionProfile profile = extensionPoint.createExecutionProfile(null, trans);
    assertEquals(profile, TransLineageHolderMap.getInstance().getLineageHolder(trans).getExecutionProfile());
    assertNull(profile.getExecutionData().getLoggingChannelId());
    // reset the execution profile
    TransLineageHolderMap.getInstance().getLineageHolder(trans).setExecutionProfile(null);
    final String logChannelId = "channel-id";
    LogChannelInterface logChannelInterface = Mockito.mock(LogChannelInterface.class);
    when(logChannelInterface.getLogChannelId()).thenReturn(logChannelId);
    profile = extensionPoint.createExecutionProfile(logChannelInterface, trans);
    assertEquals(logChannelId, profile.getExecutionData().getLoggingChannelId());
}
Also used : IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) Trans(org.pentaho.di.trans.Trans) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Test(org.junit.Test)

Example 2 with LogChannelInterface

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

the class GetStatusServletTest method setupForTransDroppedFromMap.

private void setupForTransDroppedFromMap(HttpServletRequest mockHttpServletRequest, HttpServletResponse mockHttpServletResponse, StringWriter out) throws IOException {
    KettleLogStore.init();
    Trans mockTrans = mock(Trans.class);
    TransMeta mockTransMeta = mock(TransMeta.class);
    LogChannelInterface mockChannelInterface = mock(LogChannelInterface.class);
    PrintWriter printWriter = new PrintWriter(out);
    CarteObjectEntry carteObjectEntry1 = new CarteObjectEntry("name1", "testTranId1");
    CarteObjectEntry carteObjectEntry2 = new CarteObjectEntry("name2", "testTranId2");
    when(mockHttpServletRequest.getContextPath()).thenReturn(GetStatusServlet.CONTEXT_PATH);
    when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
    Job mockJob = mock(Job.class);
    when(mockTransformationMap.getTransformationObjects()).thenReturn(Arrays.asList(carteObjectEntry1, carteObjectEntry2));
    when(mockTransformationMap.getTransformation(carteObjectEntry1)).thenReturn(// Would have done this anyways but this line is to show it is required
    null);
    when(mockTransformationMap.getTransformation(carteObjectEntry2)).thenReturn(mockTrans);
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) Job(org.pentaho.di.job.Job) Trans(org.pentaho.di.trans.Trans) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) PrintWriter(java.io.PrintWriter)

Example 3 with LogChannelInterface

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

the class PrepareExecutionTransServletTest method testPauseTransServletEscapesHtmlWhenTransFound.

@Test
@PrepareForTest({ Encode.class })
public void testPauseTransServletEscapesHtmlWhenTransFound() throws ServletException, IOException {
    KettleLogStore.init();
    HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
    Trans mockTrans = mock(Trans.class);
    TransConfiguration mockTransConf = mock(TransConfiguration.class);
    TransMeta mockTransMeta = mock(TransMeta.class);
    TransExecutionConfiguration mockTransExecutionConf = mock(TransExecutionConfiguration.class);
    LogChannelInterface mockChannelInterface = mock(LogChannelInterface.class);
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    PowerMockito.spy(Encode.class);
    when(mockHttpServletRequest.getContextPath()).thenReturn(PrepareExecutionTransServlet.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(mockTransformationMap.getConfiguration(any(CarteObjectEntry.class))).thenReturn(mockTransConf);
    when(mockTransConf.getTransExecutionConfiguration()).thenReturn(mockTransExecutionConf);
    when(mockTrans.getLogChannel()).thenReturn(mockChannelInterface);
    when(mockTrans.getTransMeta()).thenReturn(mockTransMeta);
    when(mockTransMeta.getMaximum()).thenReturn(new Point(10, 10));
    prepareExecutionTransServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
    PowerMockito.verifyStatic(atLeastOnce());
    Encode.forHtml(anyString());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) TransExecutionConfiguration(org.pentaho.di.trans.TransExecutionConfiguration) 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) TransConfiguration(org.pentaho.di.trans.TransConfiguration) 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)

Example 4 with LogChannelInterface

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

the class ExtensionPointIntegrationTest method test.

@Test
public void test() throws Exception {
    // check that all extension points are added to the map
    assertEquals(KettleExtensionPoint.values().length, ExtensionPointMap.getInstance().getNumberOfRows());
    // check that all extension points are executed
    final LogChannelInterface log = mock(LogChannelInterface.class);
    for (KettleExtensionPoint ep : KettleExtensionPoint.values()) {
        final ExtensionPointInterface currentEP = ExtensionPointMap.getInstance().getTableValue(ep.id, "id" + ep.id);
        assertFalse(currentEP.getClass().getField(EXECUTED_FIELD_NAME).getBoolean(currentEP));
        ExtensionPointHandler.callExtensionPoint(log, ep.id, null);
        assertTrue(currentEP.getClass().getField(EXECUTED_FIELD_NAME).getBoolean(currentEP));
    }
    // check modification of extension point
    final KettleExtensionPoint jobAfterOpen = KettleExtensionPoint.JobAfterOpen;
    final ExtensionPointInterface int1 = ExtensionPointMap.getInstance().getTableValue(jobAfterOpen.id, "id" + jobAfterOpen.id);
    ExtensionPointPluginType.getInstance().registerCustom(createClassRuntime(jobAfterOpen, "Edited"), "custom", "id" + jobAfterOpen.id, jobAfterOpen.id, "no description", null);
    assertNotSame(int1, ExtensionPointMap.getInstance().getTableValue(jobAfterOpen.id, "id" + jobAfterOpen.id));
    assertEquals(KettleExtensionPoint.values().length, ExtensionPointMap.getInstance().getNumberOfRows());
    // check removal of extension point
    PluginRegistry.getInstance().removePlugin(ExtensionPointPluginType.class, PluginRegistry.getInstance().getPlugin(ExtensionPointPluginType.class, "id" + jobAfterOpen.id));
    assertTrue(ExtensionPointMap.getInstance().getTableValue(jobAfterOpen.id, "id" + jobAfterOpen.id) == null);
    assertEquals(KettleExtensionPoint.values().length - 1, ExtensionPointMap.getInstance().getNumberOfRows());
}
Also used : LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Test(org.junit.Test)

Example 5 with LogChannelInterface

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

the class ExtensionPointIntegrationTest method testExtensionPointMapConcurrency.

@Test
public void testExtensionPointMapConcurrency() throws InterruptedException {
    final LogChannelInterface log = mock(LogChannelInterface.class);
    List<Runnable> parallelTasksList = new ArrayList<>(TOTAL_THREADS_TO_RUN);
    for (int i = 0; i < TOTAL_THREADS_TO_RUN; i++) {
        parallelTasksList.add(() -> {
            KettleExtensionPoint kettleExtensionPoint = getRandomKettleExtensionPoint();
            PluginInterface pluginInterface = PluginRegistry.getInstance().getPlugin(ExtensionPointPluginType.class, "id" + kettleExtensionPoint.id);
            try {
                PluginRegistry.getInstance().removePlugin(ExtensionPointPluginType.class, pluginInterface);
                PluginRegistry.getInstance().registerPlugin(ExtensionPointPluginType.class, pluginInterface);
            } catch (KettlePluginException e) {
                e.printStackTrace();
            } catch (NullPointerException e) {
            // NullPointerException can be thrown if trying to remove a plugin that doesn't exit, discarding occurence
            }
            ExtensionPointMap.getInstance().reInitialize();
            try {
                ExtensionPointMap.getInstance().callExtensionPoint(log, kettleExtensionPoint.id, null);
            } catch (KettleException e) {
                e.printStackTrace();
            }
        });
    }
    assertConcurrent(parallelTasksList);
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) ArrayList(java.util.ArrayList) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Test(org.junit.Test)

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