Search in sources :

Example 36 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class TransExecutionConfigurationTest method testConnectRepository.

@Test
public void testConnectRepository() throws KettleException {
    TransExecutionConfiguration transExecConf = new TransExecutionConfiguration();
    final RepositoriesMeta repositoriesMeta = mock(RepositoriesMeta.class);
    final RepositoryMeta repositoryMeta = mock(RepositoryMeta.class);
    final Repository repository = mock(Repository.class);
    final String mockRepo = "mockRepo";
    final boolean[] connectionSuccess = { false };
    Repository initialRepo = mock(Repository.class);
    transExecConf.setRepository(initialRepo);
    KettleLogStore.init();
    // Create mock repository plugin
    MockRepositoryPlugin mockRepositoryPlugin = mock(MockRepositoryPlugin.class);
    when(mockRepositoryPlugin.getIds()).thenReturn(new String[] { "mockRepo" });
    when(mockRepositoryPlugin.matches("mockRepo")).thenReturn(true);
    when(mockRepositoryPlugin.getName()).thenReturn("mock-repository");
    when(mockRepositoryPlugin.getClassMap()).thenAnswer(new Answer<Map<Class<?>, String>>() {

        @Override
        public Map<Class<?>, String> answer(InvocationOnMock invocation) throws Throwable {
            Map<Class<?>, String> dbMap = new HashMap<Class<?>, String>();
            dbMap.put(Repository.class, repositoryMeta.getClass().getName());
            return dbMap;
        }
    });
    List<PluginInterface> registeredPlugins = PluginRegistry.getInstance().getPlugins(RepositoryPluginType.class);
    for (PluginInterface registeredPlugin : registeredPlugins) {
        PluginRegistry.getInstance().removePlugin(RepositoryPluginType.class, registeredPlugin);
    }
    PluginRegistry.getInstance().registerPlugin(RepositoryPluginType.class, mockRepositoryPlugin);
    // Define valid connection criteria
    when(repositoriesMeta.findRepository(anyString())).thenAnswer(new Answer<RepositoryMeta>() {

        @Override
        public RepositoryMeta answer(InvocationOnMock invocation) throws Throwable {
            return mockRepo.equals(invocation.getArguments()[0]) ? repositoryMeta : null;
        }
    });
    when(mockRepositoryPlugin.loadClass(Repository.class)).thenReturn(repository);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            if ("username".equals(invocation.getArguments()[0]) && "password".equals(invocation.getArguments()[1])) {
                connectionSuccess[0] = true;
            } else {
                connectionSuccess[0] = false;
                throw new KettleException("Mock Repository connection failed");
            }
            return null;
        }
    }).when(repository).connect(anyString(), anyString());
    // Ignore repository not found in RepositoriesMeta
    transExecConf.connectRepository(repositoriesMeta, "notFound", "username", "password");
    assertEquals("Repository Changed", initialRepo, transExecConf.getRepository());
    // Ignore failed attempt to connect
    transExecConf.connectRepository(repositoriesMeta, mockRepo, "username", "");
    assertEquals("Repository Changed", initialRepo, transExecConf.getRepository());
    // Save repository if connection passes
    transExecConf.connectRepository(repositoriesMeta, mockRepo, "username", "password");
    assertEquals("Repository didn't change", repository, transExecConf.getRepository());
    assertTrue("Repository not connected", connectionSuccess[0]);
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) ClassLoadingPluginInterface(org.pentaho.di.core.plugins.ClassLoadingPluginInterface) Mockito.anyString(org.mockito.Mockito.anyString) RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Repository(org.pentaho.di.repository.Repository) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RepositoriesMeta(org.pentaho.di.repository.RepositoriesMeta) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 37 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class KettleLifecycleSupportTest method createLifecycleListener.

private KettleLifecycleListener createLifecycleListener() throws org.pentaho.di.core.exception.KettlePluginException {
    PluginInterface pluginInterface = mock(PluginInterface.class);
    KettleLifecycleListener kettleLifecycleListener = mock(KettleLifecycleListener.class);
    registeredPlugins.add(pluginInterface);
    when(registry.loadClass(pluginInterface, KettleLifecycleListener.class)).thenReturn(kettleLifecycleListener);
    when(registry.loadClass(pluginInterface)).thenReturn(kettleLifecycleListener);
    if (!typeListenerRegistration.getAllValues().isEmpty()) {
        typeListenerRegistration.getValue().pluginAdded(pluginInterface);
    }
    return kettleLifecycleListener;
}
Also used : PluginInterface(org.pentaho.di.core.plugins.PluginInterface)

Example 38 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class Encr method init.

public static void init(String encoderPluginId) throws KettleException {
    if (Utils.isEmpty(encoderPluginId)) {
        throw new KettleException("Unable to initialize the two way password encoder: No encoder plugin type specified.");
    }
    PluginRegistry registry = PluginRegistry.getInstance();
    PluginInterface plugin = registry.findPluginWithId(TwoWayPasswordEncoderPluginType.class, encoderPluginId);
    if (plugin == null) {
        throw new KettleException("Unable to find plugin with ID '" + encoderPluginId + "'");
    }
    encoder = (TwoWayPasswordEncoderInterface) registry.loadClass(plugin);
    // Load encoder specific options...
    // 
    encoder.init();
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface)

Example 39 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class ExtensionPointMap method reset.

public void reset() {
    lock.writeLock().lock();
    try {
        extensionPointPluginMap.clear();
        registry.addPluginListener(ExtensionPointPluginType.class, new PluginTypeListener() {

            @Override
            public void pluginAdded(Object serviceObject) {
                addExtensionPoint((PluginInterface) serviceObject);
            }

            @Override
            public void pluginRemoved(Object serviceObject) {
                removeExtensionPoint((PluginInterface) serviceObject);
            }

            @Override
            public void pluginChanged(Object serviceObject) {
                removeExtensionPoint((PluginInterface) serviceObject);
                addExtensionPoint((PluginInterface) serviceObject);
            }
        });
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : PluginTypeListener(org.pentaho.di.core.plugins.PluginTypeListener) PluginInterface(org.pentaho.di.core.plugins.PluginInterface)

Example 40 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.

the class KettleClientEnvironment method init.

public static synchronized void init(List<PluginTypeInterface> pluginsToLoad) throws KettleException {
    if (initialized != null) {
        return;
    }
    if (KettleClientEnvironment.instance == null) {
        KettleClientEnvironment.instance = new KettleClientEnvironment();
    }
    createKettleHome();
    // Read the kettle.properties file before anything else
    // 
    EnvUtil.environmentInit();
    // Initialize the logging back-end.
    // 
    KettleLogStore.init();
    // 
    if (!"Y".equalsIgnoreCase(System.getProperty(Const.KETTLE_DISABLE_CONSOLE_LOGGING, "N"))) {
        KettleLogStore.getAppender().addLoggingEventListener(new ConsoleLoggingEventListener());
    }
    KettleLogStore.getAppender().addLoggingEventListener(new Slf4jLoggingEventListener());
    // Load plugins
    // 
    pluginsToLoad.forEach(PluginRegistry::addPluginType);
    PluginRegistry.init();
    List<PluginInterface> logginPlugins = PluginRegistry.getInstance().getPlugins(LoggingPluginType.class);
    initLogginPlugins(logginPlugins);
    String passwordEncoderPluginID = Const.NVL(EnvUtil.getSystemProperty(Const.KETTLE_PASSWORD_ENCODER_PLUGIN), "Kettle");
    Encr.init(passwordEncoderPluginID);
    initialized = new Boolean(true);
}
Also used : Slf4jLoggingEventListener(org.pentaho.di.core.logging.Slf4jLoggingEventListener) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) LoggingPluginInterface(org.pentaho.di.core.logging.LoggingPluginInterface) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) ConsoleLoggingEventListener(org.pentaho.di.core.logging.ConsoleLoggingEventListener)

Aggregations

PluginInterface (org.pentaho.di.core.plugins.PluginInterface)99 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)45 KettleException (org.pentaho.di.core.exception.KettleException)24 ArrayList (java.util.ArrayList)17 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)14 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)12 TransMeta (org.pentaho.di.trans.TransMeta)11 StepMeta (org.pentaho.di.trans.step.StepMeta)11 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)10 Test (org.junit.Test)9 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)9 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)8 Point (org.pentaho.di.core.gui.Point)8 JobMeta (org.pentaho.di.job.JobMeta)8 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)7 TransHopMeta (org.pentaho.di.trans.TransHopMeta)7 TreeItem (org.eclipse.swt.widgets.TreeItem)6 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)6 LongObjectId (org.pentaho.di.repository.LongObjectId)6 ObjectId (org.pentaho.di.repository.ObjectId)6