use of org.pentaho.di.ui.spoon.Spoon in project pentaho-kettle by pentaho.
the class SpoonJobDelegateTest method testGetJobEntryDialogClass.
@Test
public void testGetJobEntryDialogClass() throws KettlePluginException {
PluginRegistry registry = PluginRegistry.getInstance();
PluginMockInterface plugin = mock(PluginMockInterface.class);
when(plugin.getIds()).thenReturn(new String[] { "mockJobPlugin" });
when(plugin.matches("mockJobPlugin")).thenReturn(true);
when(plugin.getName()).thenReturn("mockJobPlugin");
JobEntryInterface jobEntryInterface = mock(JobEntryInterface.class);
when(jobEntryInterface.getDialogClassName()).thenReturn(String.class.getName());
when(plugin.getClassMap()).thenReturn(new HashMap<Class<?>, String>() {
{
put(JobEntryInterface.class, jobEntryInterface.getClass().getName());
put(JobEntryDialogInterface.class, JobEntryDialogInterface.class.getName());
}
});
registry.registerPlugin(JobEntryPluginType.class, plugin);
SpoonJobDelegate delegate = mock(SpoonJobDelegate.class);
Spoon spoon = mock(Spoon.class);
delegate.spoon = spoon;
delegate.log = mock(LogChannelInterface.class);
when(spoon.getShell()).thenReturn(mock(Shell.class));
doCallRealMethod().when(delegate).getJobEntryDialog(any(JobEntryInterface.class), any(JobMeta.class));
JobMeta meta = mock(JobMeta.class);
// verify that dialog class is requested from plugin
try {
// exception is expected here
delegate.getJobEntryDialog(jobEntryInterface, meta);
} catch (Throwable ignore) {
verify(jobEntryInterface, never()).getDialogClassName();
}
// verify that the deprecated way is still valid
when(plugin.getClassMap()).thenReturn(new HashMap<Class<?>, String>() {
{
put(JobEntryInterface.class, jobEntryInterface.getClass().getName());
}
});
try {
// exception is expected here
delegate.getJobEntryDialog(jobEntryInterface, meta);
} catch (Throwable ignore) {
verify(jobEntryInterface, times(1)).getDialogClassName();
}
// cleanup
registry.removePlugin(JobEntryPluginType.class, plugin);
}
use of org.pentaho.di.ui.spoon.Spoon in project pentaho-kettle by pentaho.
the class SpoonStepsDelegateTest method testGetStepDialogClass.
@Test
public void testGetStepDialogClass() throws Exception {
PluginMockInterface plugin = mock(PluginMockInterface.class);
when(plugin.getIds()).thenReturn(new String[] { "mockPlugin" });
when(plugin.matches("mockPlugin")).thenReturn(true);
when(plugin.getName()).thenReturn("mockPlugin");
StepMetaInterface meta = mock(StepMetaInterface.class);
when(meta.getDialogClassName()).thenReturn(String.class.getName());
when(plugin.getClassMap()).thenReturn(new HashMap<Class<?>, String>() {
{
put(StepMetaInterface.class, meta.getClass().getName());
put(StepDialogInterface.class, StepDialogInterface.class.getName());
}
});
PluginRegistry.getInstance().registerPlugin(StepPluginType.class, plugin);
SpoonStepsDelegate delegate = mock(SpoonStepsDelegate.class);
Spoon spoon = mock(Spoon.class);
delegate.spoon = spoon;
delegate.log = mock(LogChannelInterface.class);
when(spoon.getShell()).thenReturn(mock(Shell.class));
doCallRealMethod().when(delegate).getStepDialog(any(StepMetaInterface.class), any(TransMeta.class), any(String.class));
TransMeta trans = mock(TransMeta.class);
// verify that dialog class is requested from plugin
try {
// exception is expected here
delegate.getStepDialog(meta, trans, "");
} catch (Throwable ignore) {
verify(meta, never()).getDialogClassName();
}
// verify that the deprecated way is still valid
when(plugin.getClassMap()).thenReturn(new HashMap<Class<?>, String>() {
{
put(StepMetaInterface.class, meta.getClass().getName());
}
});
try {
// exception is expected here
delegate.getStepDialog(meta, trans, "");
} catch (Throwable ignore) {
verify(meta, times(1)).getDialogClassName();
}
// cleanup
PluginRegistry.getInstance().removePlugin(StepPluginType.class, plugin);
}
use of org.pentaho.di.ui.spoon.Spoon in project pentaho-kettle by pentaho.
the class ModelerHelper method getInstance.
public static ModelerHelper getInstance() {
if (instance == null) {
instance = new ModelerHelper();
Spoon spoon = ((Spoon) SpoonFactory.getInstance());
spoon.addSpoonMenuController(instance);
}
return instance;
}
use of org.pentaho.di.ui.spoon.Spoon in project pentaho-kettle by pentaho.
the class StarModelerPerspective method generateSqlJobButton.
protected void generateSqlJobButton(StarDomain starDomain) {
final Spoon spoon = Spoon.getInstance();
List<DatabaseMeta> sharedDatabases = SharedDatabaseUtil.loadSharedDatabases();
// TODO: validate presence of repository, repository directory
//
JobGenerator jobGenerator = new JobGenerator(starDomain, spoon.rep, new RepositoryDirectory(), sharedDatabases, defaultLocale);
try {
JobMeta jobMeta = jobGenerator.generateSqlJob();
spoon.addJobGraph(jobMeta);
SpoonPerspectiveManager.getInstance().activatePerspective(MainSpoonPerspective.class);
} catch (Exception e) {
new ErrorDialog(spoon.getShell(), BaseMessages.getString(PKG, "StarModelerPerspective.ErrorGeneratingSqlJob.Title"), BaseMessages.getString(PKG, "StarModelerPerspective.ErrorGeneratingSqlJob.Message"), e);
}
}
use of org.pentaho.di.ui.spoon.Spoon in project pentaho-kettle by pentaho.
the class RepositoryConnectController method connectToRepository.
public void connectToRepository(RepositoryMeta repositoryMeta, String username, String password) throws KettleException {
final Repository repository = loadRepositoryObject(repositoryMeta.getId());
repository.init(repositoryMeta);
repositoryConnect(repository, username, password);
if (username != null) {
getPropsUI().setLastRepositoryLogin(username);
}
Spoon spoon = spoonSupplier.get();
Runnable execute = () -> {
if (spoon.getRepository() != null) {
spoon.closeRepository();
} else {
spoon.closeAllJobsAndTransformations(true);
}
spoon.setRepository(repository);
setConnectedRepository(repositoryMeta);
fireListeners();
};
if (spoon.getShell() != null) {
spoon.getShell().getDisplay().asyncExec(execute);
} else {
execute.run();
}
}
Aggregations