0

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

2 回答 2

0

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

代替:

suiteDescriptor.setProductionRulesetArchive(new IlrRulesetArchive());

使用以下内容:

JarInputStream is = new JarInputStream(new FileInputStream(rulesetJar));
IlrRulesetArchive ruleset = IlrRulesetArchive.extractArchive(new IlrJarArchiveLoader(is));
suiteDescriptor.setProductionRulesetArchive(ruleset);
于 2015-09-14T18:41:48.183 回答
0

我想出了这个的解决方案。

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

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

这是我的 XML Scenario Provider,可用于直接在Rule Designer中运行\调试XML :XML Scenario Provider

谢谢大家

于 2015-10-20T03:50:38.020 回答