自定义场景提供程序- NullPointerException



我试图为规则设计器创建自定义场景提供程序,并创建了插件以通过运行配置执行它。我能够创建插件并运行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();
    }
} }

问题是您还没有加载规则集存档。

代替:

suiteDescriptor.setProductionRulesetArchive(new IlrRulesetArchive());

使用类似这样的内容:

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

我找到解决办法了。

实际上,IlrDVSRunner。运行方法查找启动配置的类型,即在自定义参数中自动插入的3处运行或调试。

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

这是我的XML场景提供程序,可用于运行debug XML直接在规则设计器: XML场景提供程序

Thanks to all

相关内容

  • 没有找到相关文章

最新更新