DSV:客户场景提供程序 - NullPointerException

DSV : Custome Scenario Provider - NullPointerException

我正在尝试为 Rule Designer 创建 Custom Scenario Provider 并创建了一个 Plug-in 以通过 运行 配置。我能够创建插件和 运行 DVS 运行ner;但是,我在 IlrDVS运行ner 中收到 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();
    }
} }

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

而不是:

suiteDescriptor.setProductionRulesetArchive(new IlrRulesetArchive());

按照以下方式使用:

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

我找到了解决方法。

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

自定义参数中的第一个参数是我们要提供给 DVS 运行ner 的自定义数据。在我的例子中,是我的 Scenario Provider class 将数据添加到场景中。因此,当我更新启动配置以放置 Text-Box 时,它将为我的自定义场景提供 Scenario Provider class 名称供应商,最终我解决了我的问题。

这是我的 XML 场景提供程序,可直接在 Rule Designer 中用于 run\debug XMLs : XML Scenario Provider

感谢大家