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]);
}
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;
}
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();
}
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();
}
}
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);
}
Aggregations