Search in sources :

Example 1 with Params

use of org.pentaho.di.base.Params in project pentaho-kettle by pentaho.

the class Pan method main.

public static void main(String[] a) throws Exception {
    try {
        KettleClientEnvironment.getInstance().setClient(KettleClientEnvironment.ClientType.PAN);
        KettleEnvironment.init();
        Locale.setDefault(LanguageChoice.getInstance().getDefaultLocale());
        List<String> args = new ArrayList<>();
        for (int i = 0; i < a.length; i++) {
            if (a[i].length() > 0) {
                args.add(a[i]);
            }
        }
        // The options:
        StringBuilder optionRepname, optionUsername, optionTrustUser, optionPassword, optionTransname, optionDirname;
        StringBuilder optionFilename, optionLoglevel, optionLogfile, optionLogfileOld, optionListdir;
        StringBuilder optionListtrans, optionListrep, optionExprep, optionNorep, optionSafemode;
        StringBuilder optionVersion, optionJarFilename, optionListParam, optionMetrics, initialDir;
        StringBuilder optionResultSetStepName, optionResultSetCopyNumber;
        StringBuilder optionBase64Zip, optionUuid;
        NamedParams optionParams = new NamedParamsDefault();
        CommandLineOption maxLogLinesOption = new CommandLineOption("maxloglines", BaseMessages.getString(PKG, "Pan.CmdLine.MaxLogLines"), new StringBuilder());
        CommandLineOption maxLogTimeoutOption = new CommandLineOption("maxlogtimeout", BaseMessages.getString(PKG, "Pan.CmdLine.MaxLogTimeout"), new StringBuilder());
        CommandLineOption[] options = new CommandLineOption[] { new CommandLineOption("rep", BaseMessages.getString(PKG, "Pan.ComdLine.RepName"), optionRepname = new StringBuilder()), new CommandLineOption("user", BaseMessages.getString(PKG, "Pan.ComdLine.RepUsername"), optionUsername = new StringBuilder()), new CommandLineOption("trustuser", BaseMessages.getString(PKG, "Pan.ComdLine.RepUsername"), optionTrustUser = new StringBuilder()), new CommandLineOption("pass", BaseMessages.getString(PKG, "Pan.ComdLine.RepPassword"), optionPassword = new StringBuilder()), new CommandLineOption("trans", BaseMessages.getString(PKG, "Pan.ComdLine.TransName"), optionTransname = new StringBuilder()), new CommandLineOption("dir", BaseMessages.getString(PKG, "Pan.ComdLine.RepDir"), optionDirname = new StringBuilder()), new CommandLineOption("file", BaseMessages.getString(PKG, "Pan.ComdLine.XMLTransFile"), optionFilename = new StringBuilder()), new CommandLineOption("level", BaseMessages.getString(PKG, "Pan.ComdLine.LogLevel"), optionLoglevel = new StringBuilder()), new CommandLineOption("logfile", BaseMessages.getString(PKG, "Pan.ComdLine.LogFile"), optionLogfile = new StringBuilder()), new CommandLineOption("log", BaseMessages.getString(PKG, "Pan.ComdLine.LogOldFile"), optionLogfileOld = new StringBuilder(), false, true), new CommandLineOption("listdir", BaseMessages.getString(PKG, "Pan.ComdLine.ListDirRep"), optionListdir = new StringBuilder(), true, false), new CommandLineOption("listtrans", BaseMessages.getString(PKG, "Pan.ComdLine.ListTransDir"), optionListtrans = new StringBuilder(), true, false), new CommandLineOption("listrep", BaseMessages.getString(PKG, "Pan.ComdLine.ListReps"), optionListrep = new StringBuilder(), true, false), new CommandLineOption("exprep", BaseMessages.getString(PKG, "Pan.ComdLine.ExpObjectsXML"), optionExprep = new StringBuilder(), true, false), new CommandLineOption("norep", BaseMessages.getString(PKG, "Pan.ComdLine.NoRep"), optionNorep = new StringBuilder(), true, false), new CommandLineOption("safemode", BaseMessages.getString(PKG, "Pan.ComdLine.SafeMode"), optionSafemode = new StringBuilder(), true, false), new CommandLineOption("version", BaseMessages.getString(PKG, "Pan.ComdLine.Version"), optionVersion = new StringBuilder(), true, false), new CommandLineOption("jarfile", BaseMessages.getString(PKG, "Pan.ComdLine.JarFile"), optionJarFilename = new StringBuilder(), false, true), new CommandLineOption("param", BaseMessages.getString(PKG, "Pan.ComdLine.Param"), optionParams, false), new CommandLineOption("listparam", BaseMessages.getString(PKG, "Pan.ComdLine.ListParam"), optionListParam = new StringBuilder(), true, false), new CommandLineOption("initialDir", null, initialDir = new StringBuilder(), false, true), new CommandLineOption("stepname", "ResultSetStepName", optionResultSetStepName = new StringBuilder(), false, true), new CommandLineOption("copynum", "ResultSetCopyNumber", optionResultSetCopyNumber = new StringBuilder(), false, true), new CommandLineOption("zip", "Base64Zip", optionBase64Zip = new StringBuilder(), false, true), new CommandLineOption("uuid", "UUID", optionUuid = new StringBuilder(), false, true), new CommandLineOption("metrics", BaseMessages.getString(PKG, "Pan.ComdLine.Metrics"), optionMetrics = new StringBuilder(), true, false), maxLogLinesOption, maxLogTimeoutOption };
        if (args.size() == 2) {
            // 2 internal hidden argument (flag and value)
            CommandLineOption.printUsage(options);
            exitJVM(CommandExecutorCodes.Pan.CMD_LINE_PRINT.getCode());
        }
        // Parse the options...
        if (!CommandLineOption.parseArguments(args, options, log)) {
            log.logError(BaseMessages.getString(PKG, "Pan.Error.CommandLineError"));
            exitJVM(CommandExecutorCodes.Pan.ERROR_LOADING_STEPS_PLUGINS.getCode());
        }
        Kitchen.configureLogging(maxLogLinesOption, maxLogTimeoutOption);
        String kettleRepname = Const.getEnvironmentVariable(Const.KETTLE_REPOSITORY, null);
        String kettleUsername = Const.getEnvironmentVariable(Const.KETTLE_USER, null);
        String kettlePassword = Const.getEnvironmentVariable(Const.KETTLE_PASSWORD, null);
        if (kettleRepname != null && kettleRepname.length() > 0) {
            optionRepname = new StringBuilder(kettleRepname);
        }
        if (kettleUsername != null && kettleUsername.length() > 0) {
            optionUsername = new StringBuilder(kettleUsername);
        }
        if (kettlePassword != null && kettlePassword.length() > 0) {
            optionPassword = new StringBuilder(kettlePassword);
        }
        if (Utils.isEmpty(optionLogfile) && !Utils.isEmpty(optionLogfileOld)) {
            // if the old style of logging name is filled in, and the new one is not
            // overwrite the new by the old
            optionLogfile = optionLogfileOld;
        }
        if (!Utils.isEmpty(optionLogfile)) {
            // PDI-18724: this throws an exception if the given log file is not accessible
            fileLoggingEventListener = new FileLoggingEventListener(optionLogfile.toString(), true);
            KettleLogStore.getAppender().addLoggingEventListener(fileLoggingEventListener);
        } else {
            fileLoggingEventListener = null;
        }
        if (!Utils.isEmpty(optionLoglevel)) {
            log.setLogLevel(LogLevel.getLogLevelForCode(optionLoglevel.toString()));
            log.logMinimal(BaseMessages.getString(PKG, "Pan.Log.Loglevel", log.getLogLevel().getDescription()));
        }
        // 
        if (log.isDebug()) {
            System.out.println("Arguments:");
            for (int i = 0; i < options.length; i++) {
                System.out.println(Const.rightPad(options[i].getOption(), 12) + " : " + options[i].getArgument());
            }
            System.out.println("");
        }
        if (getCommandExecutor() == null) {
            // init
            setCommandExecutor(new PanCommandExecutor(PKG, log));
        }
        if (!Utils.isEmpty(optionVersion)) {
            getCommandExecutor().printVersion();
            if (a.length == 1) {
                exitJVM(CommandExecutorCodes.Pan.KETTLE_VERSION_PRINT.getCode());
            }
        }
        Params.Builder builder = optionUuid.length() > 0 ? new Params.Builder(optionUuid.toString()) : new Params.Builder();
        Params transParams = (builder).blockRepoConns(optionNorep.toString()).repoName(optionRepname.toString()).repoUsername(optionUsername.toString()).trustRepoUser(optionTrustUser.toString()).repoPassword(optionPassword.toString()).inputDir(optionDirname.toString()).inputFile(optionTransname.toString()).listRepoFiles(optionListtrans.toString()).listRepoDirs(optionListdir.toString()).exportRepo(optionExprep.toString()).localFile(optionFilename.toString()).localJarFile(optionJarFilename.toString()).localInitialDir(initialDir.toString()).listRepos(optionListrep.toString()).safeMode(optionSafemode.toString()).metrics(optionMetrics.toString()).listFileParams(optionListParam.toString()).logLevel("").maxLogLines("").maxLogTimeout("").logFile("").oldLogFile("").version("").resultSetStepName(optionResultSetStepName.toString()).resultSetCopyNumber(optionResultSetCopyNumber.toString()).base64Zip(optionBase64Zip.toString()).namedParams(optionParams).build();
        Result result = getCommandExecutor().execute(transParams, args.toArray(new String[args.size()]));
        exitJVM(result.getExitStatus());
    } catch (Throwable t) {
        t.printStackTrace();
        exitJVM(CommandExecutorCodes.Pan.UNEXPECTED_ERROR.getCode());
    }
}
Also used : NamedParamsDefault(org.pentaho.di.core.parameters.NamedParamsDefault) NamedParams(org.pentaho.di.core.parameters.NamedParams) FileLoggingEventListener(org.pentaho.di.core.logging.FileLoggingEventListener) ArrayList(java.util.ArrayList) Params(org.pentaho.di.base.Params) NamedParams(org.pentaho.di.core.parameters.NamedParams) Result(org.pentaho.di.core.Result)

Example 2 with Params

use of org.pentaho.di.base.Params in project pentaho-kettle by pentaho.

the class PanCommandExecutorTest method testTransformationInitializationErrorExtensionPointCalled.

@Test
public void testTransformationInitializationErrorExtensionPointCalled() throws Throwable {
    boolean kettleXMLExceptionThrown = false;
    Trans trans = null;
    PluginMockInterface pluginInterface = mock(PluginMockInterface.class);
    when(pluginInterface.getName()).thenReturn(KettleExtensionPoint.TransformationFinish.id);
    when(pluginInterface.getMainType()).thenReturn((Class) ExtensionPointInterface.class);
    when(pluginInterface.getIds()).thenReturn(new String[] { "extensionpointId" });
    ExtensionPointInterface extensionPoint = mock(ExtensionPointInterface.class);
    when(pluginInterface.loadClass(ExtensionPointInterface.class)).thenReturn(extensionPoint);
    PluginRegistry.addPluginType(ExtensionPointPluginType.getInstance());
    PluginRegistry.getInstance().registerPlugin(ExtensionPointPluginType.class, pluginInterface);
    Params params = mock(Params.class);
    when(params.getRepoName()).thenReturn("");
    when(params.getLocalInitialDir()).thenReturn("");
    when(params.getLocalFile()).thenReturn(FAIL_ON_INIT_KTR);
    when(params.getLocalJarFile()).thenReturn("");
    when(params.getBase64Zip()).thenReturn(BASE64_FAIL_ON_INIT_KTR);
    try {
        trans = mockedPanCommandExecutor.loadTransFromFilesystem("", FAIL_ON_INIT_KTR, "", BASE64_FAIL_ON_INIT_KTR);
    } catch (KettleXMLException e) {
        kettleXMLExceptionThrown = true;
    }
    PanCommandExecutor panCommandExecutor = new PanCommandExecutor(PanCommandExecutor.class);
    panCommandExecutor.execute(params);
    Assert.assertTrue(kettleXMLExceptionThrown);
    verify(extensionPoint, times(1)).callExtensionPoint(any(LogChannelInterface.class), same(trans));
}
Also used : KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) Params(org.pentaho.di.base.Params) Trans(org.pentaho.di.trans.Trans) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) ExtensionPointInterface(org.pentaho.di.core.extension.ExtensionPointInterface) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with Params

use of org.pentaho.di.base.Params in project pentaho-kettle by pentaho.

the class KitchenCommandExecutorTest method testExecuteWithInvalidRepository.

@Test
public void testExecuteWithInvalidRepository() {
    // Create Mock Objects
    Params params = mock(Params.class);
    KitchenCommandExecutor kitchenCommandExecutor = new KitchenCommandExecutor(Kitchen.class);
    PowerMockito.mockStatic(BaseMessages.class);
    // Mock returns
    when(params.getRepoName()).thenReturn("NoExistingRepository");
    when(BaseMessages.getString(any(Class.class), anyString(), anyVararg())).thenReturn("");
    try {
        Result result = kitchenCommandExecutor.execute(params, null);
        Assert.assertEquals(CommandExecutorCodes.Kitchen.COULD_NOT_LOAD_JOB.getCode(), result.getExitStatus());
    } catch (Throwable throwable) {
        Assert.fail();
    }
}
Also used : Params(org.pentaho.di.base.Params) Result(org.pentaho.di.core.Result) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with Params

use of org.pentaho.di.base.Params in project pentaho-kettle by pentaho.

the class Kitchen method main.

public static void main(String[] a) throws Exception {
    final ExecutorService executor = ExecutorUtil.getExecutor();
    final RepositoryPluginType repositoryPluginType = RepositoryPluginType.getInstance();
    Locale.setDefault(LanguageChoice.getInstance().getDefaultLocale());
    final Future<Map.Entry<KettlePluginException, Future<KettleException>>> repositoryRegisterFuture = executor.submit(new Callable<Map.Entry<KettlePluginException, Future<KettleException>>>() {

        @Override
        public Map.Entry<KettlePluginException, Future<KettleException>> call() throws Exception {
            PluginRegistry.addPluginType(repositoryPluginType);
            try {
                KettleClientEnvironment.getInstance().setClient(KettleClientEnvironment.ClientType.KITCHEN);
                KettleClientEnvironment.init();
            } catch (KettlePluginException e) {
                return new AbstractMap.SimpleImmutableEntry<KettlePluginException, Future<KettleException>>(e, null);
            }
            Future<KettleException> kettleEnvironmentInitFuture = executor.submit(new Callable<KettleException>() {

                @Override
                public KettleException call() throws Exception {
                    try {
                        KettleClientEnvironment.getInstance().setClient(KettleClientEnvironment.ClientType.KITCHEN);
                        KettleEnvironment.init();
                    } catch (KettleException e) {
                        return e;
                    }
                    return null;
                }
            });
            return new AbstractMap.SimpleImmutableEntry<KettlePluginException, Future<KettleException>>(null, kettleEnvironmentInitFuture);
        }
    });
    List<String> args = new ArrayList<String>();
    for (int i = 0; i < a.length; i++) {
        if (a[i].length() > 0) {
            args.add(a[i]);
        }
    }
    DelegatingMetaStore metaStore = new DelegatingMetaStore();
    metaStore.addMetaStore(MetaStoreConst.openLocalPentahoMetaStore());
    metaStore.setActiveMetaStoreName(metaStore.getName());
    StringBuilder optionRepname, optionUsername, optionTrustUser, optionPassword, optionJobname, optionDirname, initialDir;
    StringBuilder optionFilename, optionLoglevel, optionLogfile, optionLogfileOld, optionListdir;
    StringBuilder optionListjobs, optionListrep, optionNorep, optionVersion, optionListParam, optionExport, optionBase64Zip, optionUuid;
    NamedParams optionParams = new NamedParamsDefault();
    NamedParams customOptions = new NamedParamsDefault();
    CommandLineOption maxLogLinesOption = new CommandLineOption("maxloglines", BaseMessages.getString(PKG, "Kitchen.CmdLine.MaxLogLines"), new StringBuilder());
    CommandLineOption maxLogTimeoutOption = new CommandLineOption("maxlogtimeout", BaseMessages.getString(PKG, "Kitchen.CmdLine.MaxLogTimeout"), new StringBuilder());
    CommandLineOption[] options = new CommandLineOption[] { new CommandLineOption("rep", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepName"), optionRepname = new StringBuilder()), new CommandLineOption("user", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepUsername"), optionUsername = new StringBuilder()), new CommandLineOption("trustuser", BaseMessages.getString(PKG, "Kitchen.ComdLine.RepUsername"), optionTrustUser = new StringBuilder()), new CommandLineOption("pass", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepPassword"), optionPassword = new StringBuilder()), new CommandLineOption("job", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepJobName"), optionJobname = new StringBuilder()), new CommandLineOption("dir", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepDir"), optionDirname = new StringBuilder()), new CommandLineOption("file", BaseMessages.getString(PKG, "Kitchen.CmdLine.XMLJob"), optionFilename = new StringBuilder()), new CommandLineOption("level", BaseMessages.getString(PKG, "Kitchen.CmdLine.LogLevel"), optionLoglevel = new StringBuilder()), new CommandLineOption("logfile", BaseMessages.getString(PKG, "Kitchen.CmdLine.LogFile"), optionLogfile = new StringBuilder()), new CommandLineOption("log", BaseMessages.getString(PKG, "Kitchen.CmdLine.LogFileOld"), optionLogfileOld = new StringBuilder(), false, true), new CommandLineOption("listdir", BaseMessages.getString(PKG, "Kitchen.CmdLine.ListDir"), optionListdir = new StringBuilder(), true, false), new CommandLineOption("listjobs", BaseMessages.getString(PKG, "Kitchen.CmdLine.ListJobsDir"), optionListjobs = new StringBuilder(), true, false), new CommandLineOption("listrep", BaseMessages.getString(PKG, "Kitchen.CmdLine.ListAvailableReps"), optionListrep = new StringBuilder(), true, false), new CommandLineOption("norep", BaseMessages.getString(PKG, "Kitchen.CmdLine.NoRep"), optionNorep = new StringBuilder(), true, false), new CommandLineOption("version", BaseMessages.getString(PKG, "Kitchen.CmdLine.Version"), optionVersion = new StringBuilder(), true, false), new CommandLineOption("param", BaseMessages.getString(PKG, "Kitchen.ComdLine.Param"), optionParams, false), new CommandLineOption("listparam", BaseMessages.getString(PKG, "Kitchen.ComdLine.ListParam"), optionListParam = new StringBuilder(), true, false), new CommandLineOption("export", BaseMessages.getString(PKG, "Kitchen.ComdLine.Export"), optionExport = new StringBuilder(), true, false), new CommandLineOption("initialDir", null, initialDir = new StringBuilder(), false, true), new CommandLineOption("zip", "Base64Zip", optionBase64Zip = new StringBuilder(), false, true), new CommandLineOption("uuid", "UUID", optionUuid = new StringBuilder(), false, true), new CommandLineOption("custom", BaseMessages.getString(PKG, "Kitchen.ComdLine.Custom"), customOptions, false), maxLogLinesOption, maxLogTimeoutOption };
    if (args.size() == 2) {
        // 2 internal hidden argument (flag and value)
        CommandLineOption.printUsage(options);
        exitJVM(9);
    }
    LogChannelInterface log = new LogChannel(STRING_KITCHEN);
    CommandLineOption.parseArguments(args, options, log);
    configureLogging(maxLogLinesOption, maxLogTimeoutOption);
    String kettleRepname = Const.getEnvironmentVariable("KETTLE_REPOSITORY", null);
    String kettleUsername = Const.getEnvironmentVariable("KETTLE_USER", null);
    String kettlePassword = Const.getEnvironmentVariable("KETTLE_PASSWORD", null);
    if (!Utils.isEmpty(kettleRepname)) {
        optionRepname = new StringBuilder(kettleRepname);
    }
    if (!Utils.isEmpty(kettleUsername)) {
        optionUsername = new StringBuilder(kettleUsername);
    }
    if (!Utils.isEmpty(kettlePassword)) {
        optionPassword = new StringBuilder(kettlePassword);
    }
    if (Utils.isEmpty(optionLogfile) && !Utils.isEmpty(optionLogfileOld)) {
        // if the old style of logging name is filled in, and the new one is not
        // overwrite the new by the old
        optionLogfile = optionLogfileOld;
    }
    Map.Entry<KettlePluginException, Future<KettleException>> repositoryRegisterResults = repositoryRegisterFuture.get();
    // It's a singleton map with one key-value pair (a Pair collection)
    KettlePluginException repositoryRegisterException = repositoryRegisterResults.getKey();
    if (repositoryRegisterException != null) {
        throw repositoryRegisterException;
    }
    Future<KettleException> kettleInitFuture = repositoryRegisterResults.getValue();
    if (!Utils.isEmpty(optionLogfile)) {
        fileAppender = new FileLoggingEventListener(optionLogfile.toString(), true);
        KettleLogStore.getAppender().addLoggingEventListener(fileAppender);
    } else {
        fileAppender = null;
    }
    if (!Utils.isEmpty(optionLoglevel)) {
        log.setLogLevel(LogLevel.getLogLevelForCode(optionLoglevel.toString()));
        log.logMinimal(BaseMessages.getString(PKG, "Kitchen.Log.LogLevel", log.getLogLevel().getDescription()));
    }
    // Start the action...
    // 
    Result result = new Result();
    try {
        if (getCommandExecutor() == null) {
            // init
            setCommandExecutor(new KitchenCommandExecutor(PKG, log, kettleInitFuture));
        }
        if (!Utils.isEmpty(optionVersion)) {
            getCommandExecutor().printVersion();
            if (a.length == 1) {
                exitJVM(CommandExecutorCodes.Pan.KETTLE_VERSION_PRINT.getCode());
            }
        }
        Params.Builder builder = optionUuid.length() > 0 ? new Params.Builder(optionUuid.toString()) : new Params.Builder();
        Params jobParams = (builder).blockRepoConns(optionNorep.toString()).repoName(optionRepname.toString()).repoUsername(optionUsername.toString()).trustRepoUser(optionTrustUser.toString()).repoPassword(optionPassword.toString()).inputDir(optionDirname.toString()).inputFile(optionJobname.toString()).listRepoFiles(optionListjobs.toString()).listRepoDirs(optionListdir.toString()).exportRepo(optionExport.toString()).localFile(optionFilename.toString()).localJarFile("").localInitialDir(initialDir.toString()).listRepos(optionListrep.toString()).listFileParams(optionListParam.toString()).logLevel("").maxLogLines("").maxLogTimeout("").logFile("").oldLogFile("").version("").resultSetStepName("").resultSetCopyNumber("").base64Zip(optionBase64Zip.toString()).namedParams(optionParams).customNamedParams(customOptions).build();
        result = getCommandExecutor().execute(jobParams, args.toArray(new String[args.size()]));
    } catch (Throwable t) {
        t.printStackTrace();
        result.setExitStatus(CommandExecutorCodes.Pan.UNEXPECTED_ERROR.getCode());
    } finally {
        if (fileAppender != null) {
            fileAppender.close();
            KettleLogStore.getAppender().removeLoggingEventListener(fileAppender);
        }
    }
    exitJVM(result.getExitStatus());
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) NamedParams(org.pentaho.di.core.parameters.NamedParams) RepositoryPluginType(org.pentaho.di.core.plugins.RepositoryPluginType) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) Result(org.pentaho.di.core.Result) AbstractMap(java.util.AbstractMap) CommandLineOption(org.pentaho.di.pan.CommandLineOption) NamedParamsDefault(org.pentaho.di.core.parameters.NamedParamsDefault) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) FileLoggingEventListener(org.pentaho.di.core.logging.FileLoggingEventListener) LogChannel(org.pentaho.di.core.logging.LogChannel) Params(org.pentaho.di.base.Params) NamedParams(org.pentaho.di.core.parameters.NamedParams) DelegatingMetaStore(org.pentaho.metastore.stores.delegate.DelegatingMetaStore) KettleException(org.pentaho.di.core.exception.KettleException) ExecutionException(java.util.concurrent.ExecutionException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Map(java.util.Map) AbstractMap(java.util.AbstractMap)

Example 5 with Params

use of org.pentaho.di.base.Params in project pentaho-kettle by pentaho.

the class KitchenCommandExecutorTest method testJobFailOnInitializationExtensionPointCall.

@Test
public void testJobFailOnInitializationExtensionPointCall() throws Throwable {
    boolean kettleXMLExceptionThrown = false;
    Job job = null;
    PluginMockInterface pluginInterface = mock(PluginMockInterface.class);
    when(pluginInterface.getName()).thenReturn(KettleExtensionPoint.JobFinish.id);
    when(pluginInterface.getMainType()).thenReturn((Class) ExtensionPointInterface.class);
    when(pluginInterface.getIds()).thenReturn(new String[] { "extensionpointId" });
    ExtensionPointInterface extensionPoint = mock(ExtensionPointInterface.class);
    when(pluginInterface.loadClass(ExtensionPointInterface.class)).thenReturn(extensionPoint);
    PluginRegistry.addPluginType(ExtensionPointPluginType.getInstance());
    PluginRegistry.getInstance().registerPlugin(ExtensionPointPluginType.class, pluginInterface);
    String fullPath = getClass().getResource("brokenjob.kjb").getPath();
    Params params = mock(Params.class);
    when(params.getRepoName()).thenReturn("");
    when(params.getLocalInitialDir()).thenReturn("");
    when(params.getLocalFile()).thenReturn(fullPath);
    when(params.getLocalJarFile()).thenReturn("");
    when(params.getBase64Zip()).thenReturn("");
    try {
        job = mockedKitchenCommandExecutor.loadJobFromFilesystem("", fullPath, "");
    } catch (KettleXMLException e) {
        kettleXMLExceptionThrown = true;
    }
    KitchenCommandExecutor kitchenCommandExecutor = new KitchenCommandExecutor(KitchenCommandExecutor.class);
    Result result = kitchenCommandExecutor.execute(params);
    Assert.assertTrue(kettleXMLExceptionThrown);
    verify(extensionPoint, times(1)).callExtensionPoint(any(LogChannelInterface.class), same(job));
}
Also used : KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) Params(org.pentaho.di.base.Params) Matchers.anyString(org.mockito.Matchers.anyString) Job(org.pentaho.di.job.Job) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) ExtensionPointInterface(org.pentaho.di.core.extension.ExtensionPointInterface) Result(org.pentaho.di.core.Result) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Params (org.pentaho.di.base.Params)8 Result (org.pentaho.di.core.Result)7 Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)5 ExtensionPointInterface (org.pentaho.di.core.extension.ExtensionPointInterface)4 Matchers.anyString (org.mockito.Matchers.anyString)3 Trans (org.pentaho.di.trans.Trans)3 ArrayList (java.util.ArrayList)2 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)2 FileLoggingEventListener (org.pentaho.di.core.logging.FileLoggingEventListener)2 NamedParams (org.pentaho.di.core.parameters.NamedParams)2 NamedParamsDefault (org.pentaho.di.core.parameters.NamedParamsDefault)2 AbstractMap (java.util.AbstractMap)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 KettleException (org.pentaho.di.core.exception.KettleException)1