DSV:Custome Scenario Provider - NullPointerException

时间:2015-07-09 06:33:02

标签: ilog jrules ibm-odm

我正在尝试为Rule Designer创建自定义方案提供程序,并创建了插件以通过“运行配置”执行它。我能够创建插件并运行DVS Runner;但是,我在IlrDVSRunner 中收到 NullPointerException。我无法通过各种方式解决异常问题。任何帮助将受到高度赞赏。

MotorScenarioProvider.java

public class MotorScenarioProvider implements IlrScenarioProvider, Serializable {
private static final long serialVersionUID = 20150702L;

public MotorScenarioProvider() {
    super();
    System.out.println("MotorScenarioProvider - Constructor");
}

public void initialize(IlrScenarioSuiteExecutionContext context)
        throws IlrInitializationException {
    System.out.println("MotorScenarioProvider - Initialize");
}

public int getScenarioCount() throws IlrScenarioProviderException {
    System.out.println("MotorScenarioProvider - getScenarioCount");
    return 1;
}

public IlrScenario getScenarioAt(int indx)
        throws IlrScenarioProviderException {
    System.out.println("MotorScenarioProvider - getScenarioAt");

    IlrScenarioImpl scenario = new IlrScenarioImpl();
    Map<String, Object> inputParameters = new HashMap<String, Object>();

    //Setting Blank Scenario for testing purpose
    scenario.setName("Scenario 1");
    inputParameters.put("req", new Object());
    inputParameters.put("req", new Object());
    scenario.setInputParameters(inputParameters);

    return scenario;
}

MotorScenarioProviderRunner.java

public class MotorScenarioProviderRunner extends IlrDVSRunner {
/**
 * Create a DVS scenario suite descriptor
 * 
 * @return The scenario suite descriptor
 */
public IlrScenarioSuiteDescriptor createScenarioSuiteDescriptor() {
    IlrScenarioSuiteDescriptorFactory scenarioSuiteDescriptorFactory = new IlrScenarioSuiteDescriptorFactory();
    IlrScenarioFormatDescriptor formatDescriptor = IlrScenarioFormatDescriptorFactory
            .getInstance().createScenarioFormatDescriptor();
    formatDescriptor
        .setScenarioProviderClassName(MotorScenarioProvider.class.getName());
    IlrScenarioSuiteDescriptor suiteDescriptor = scenarioSuiteDescriptorFactory
            .createScenarioSuiteDescriptor(formatDescriptor);
    suiteDescriptor.setKPIEnabled(false);
    suiteDescriptor.setTestEnabled(true);
    suiteDescriptor.setProductionRulesetArchive(new IlrRulesetArchive());
    System.out.println("MotorScenarioProviderRunner: createScenarioSuiteDescriptor");

    suiteDescriptor.add("SCENARIO_NAME", "Scenario 1");

    return suiteDescriptor;
}

/**
 * The main method run from the {@link IlrDVSLaunchConfigurationDelegate}
 * launch method.
 * 
 * @param args
 *            The args needed to run the scenarios and build the scenario
 *            suite descriptor.
 */
public static void main(String[] args) {
    MotorScenarioProviderRunner runner = new MotorScenarioProviderRunner();
    String[] data = runner.extractCustomArgs(args);
    // TODO read the custom parameters from the 'data' attribute and not
    // from the 'args' attribute
    System.out.println("MotorScenarioProviderRunner: main");

    try {
        IlrScenarioSuiteDescriptor scenarioSuite = runner
                .createScenarioSuiteDescriptor();

        if(scenarioSuite == null)
            System.out.println("scenarioSuite is NULL");
        if(args == null)
            System.out.println("args is NULL");

        runner.run(args, scenarioSuite); **//EXCEPTION OCCURS HERE**
    } catch (IOException e) {
        e.printStackTrace();
    }
} }

2 个答案:

答案 0 :(得分:0)

问题是您尚未加载规则集存档。

而不是:

suiteDescriptor.setProductionRulesetArchive(new IlrRulesetArchive());

使用以下内容:

JarInputStream is = new JarInputStream(new FileInputStream(rulesetJar));
IlrRulesetArchive ruleset = IlrRulesetArchive.extractArchive(new IlrJarArchiveLoader(is));
suiteDescriptor.setProductionRulesetArchive(ruleset);

答案 1 :(得分:0)

我想出了解决方法。

实际上,IlrDVSRunner.Run方法会查找启动配置的类型,即从启动配置中自动插入的 custum args 中的3位运行或调试。

custom args 中的第一个arg是我们要提供给DVS Runner的自定义数据。在我的例子中,它是我的场景提供程序类,它将数据添加到场景中。因此,当我更新启动配置以将文本框添加到我的自定义方案提供程序时提供方案提供程序类名称时,最终我最终得到了解决方案我的问题。

以下是我的XML Scenario Provider,可以直接在 Rule Designer 中使用运行\ debug XML:XML Scenario Provider

感谢所有