예제 #1
0
  private void runScenario(RunNotifier notifier, Scenario scenario) {
    Description childDescription =
        Description.createTestDescription(getClass(), scenario.getName());
    descr.addChild(childDescription);
    EachTestNotifier eachNotifier = new EachTestNotifier(notifier, childDescription);
    try {
      eachNotifier.fireTestStarted();

      // If a KieSession is not available, fail fast
      if (ksessions == null || ksessions.values().isEmpty()) {
        eachNotifier.addFailure(
            new NullKieSessionException(
                "Unable to get a Session to run tests. Check the project for build errors."));
      } else {

        KieSession ksession = getKSession(scenario.getKSessions());

        if (ksession == null) {
          String ksessionName = getKSessionName(scenario.getKSessions());
          if (ksessionName == null) {
            eachNotifier.addFailure(
                new NullPointerException(
                    "Test scenario runner could not find the default knowledge session."));
          } else {
            eachNotifier.addFailure(
                new NullPointerException(
                    "Test scenario runner could not find a stateful knowledge session with the name \'"
                        + ksessionName
                        + "\'."));
          }
        } else {
          final ScenarioRunner runner = new ScenarioRunner(ksession, maxRuleFirings);
          runner.run(scenario);
          if (!scenario.wasSuccessful()) {
            StringBuilder builder = new StringBuilder();
            for (String message : scenario.getFailureMessages()) {
              builder.append(message).append("\n");
            }
            eachNotifier.addFailedAssumption(new AssumptionViolatedException(builder.toString()));
          }

          // FLUSSSSSH!
          for (FactHandle factHandle : ksession.getFactHandles()) {
            ksession.delete(factHandle);
          }
        }
      }
    } catch (Throwable t) {
      eachNotifier.addFailure(t);
    } finally {
      // has to always be called as per junit docs
      eachNotifier.fireTestFinished();
    }
  }
예제 #2
0
  public CallMethodWidget(
      String factName,
      ScenarioParentWidget parent,
      Scenario scenario,
      CallMethod mCall,
      ExecutionTrace executionTrace,
      PackageDataModelOracle dmo) {
    super();
    this.factName = factName;
    this.parent = parent;
    this.scenario = scenario;
    this.mCall = mCall;
    this.executionTrace = executionTrace;
    this.dmo = dmo;

    this.layout = new DirtyableFlexTable();

    layout.setStyleName("model-builderInner-Background"); // NON-NLS

    if (dmo.isGlobalVariable(mCall.getVariable())) {

      List<MethodInfo> infos = dmo.getMethodInfosForGlobalVariable(mCall.getVariable());
      this.fieldCompletionTexts = new String[infos.size()];
      this.fieldCompletionValues = new String[infos.size()];
      int i = 0;
      for (MethodInfo info : infos) {
        this.fieldCompletionTexts[i] = info.getName();
        this.fieldCompletionValues[i] = info.getNameWithParameters();
        i++;
      }

      this.variableClass = (String) dmo.getGlobalVariable(mCall.getVariable());
    } else {
      FactData pattern = (FactData) scenario.getFactTypes().get(mCall.getVariable());
      if (pattern != null) {
        List<String> methodList = dmo.getMethodNames(pattern.getType());
        fieldCompletionTexts = new String[methodList.size()];
        fieldCompletionValues = new String[methodList.size()];
        int i = 0;
        for (String methodName : methodList) {
          fieldCompletionTexts[i] = methodName;
          fieldCompletionValues[i] = methodName;
          i++;
        }
        this.variableClass = pattern.getType();
        this.isBoundFact = true;
      }
    }

    doLayout();
    initWidget(this.layout);
  }
예제 #3
0
  private Widget valueEditor(final CallFieldValue val) {

    String type = "";
    if (dmo.isGlobalVariable(this.mCall.getVariable())) {
      type = dmo.getGlobalVariable(this.mCall.getVariable());
    } else {
      Map<String, String> mFactTypes = scenario.getVariableTypes();
      type = mFactTypes.get(this.mCall.getVariable());
    }

    DropDownData enums = dmo.getEnums(type, val.field, this.mCall.getCallFieldValuesMap());
    return new MethodParameterCallValueEditor(
        val,
        enums,
        executionTrace,
        scenario,
        val.type,
        new Command() {

          public void execute() {
            makeDirty();
          }
        });
  }
예제 #4
0
 protected void onDelete() {
   if (Window.confirm(TestScenarioConstants.INSTANCE.AreYouSureToRemoveCallMethod())) {
     scenario.removeFixture(mCall);
     parent.renderEditor();
   }
 }
예제 #5
0
  public CallMethodWidget(
      final String factName,
      final ScenarioParentWidget parent,
      final Scenario scenario,
      final CallMethod mCall,
      final ExecutionTrace executionTrace,
      final AsyncPackageDataModelOracle oracle) {
    super();
    this.factName = factName;
    this.parent = parent;
    this.scenario = scenario;
    this.mCall = mCall;
    this.executionTrace = executionTrace;
    this.oracle = oracle;

    this.layout = new DirtyableFlexTable();

    layout.setStyleName("model-builderInner-Background"); // NON-NLS

    if (this.oracle.isGlobalVariable(mCall.getVariable())) {

      this.oracle.getMethodInfosForGlobalVariable(
          mCall.getVariable(),
          new Callback<List<MethodInfo>>() {
            @Override
            public void callback(final List<MethodInfo> infos) {
              CallMethodWidget.this.fieldCompletionTexts = new String[infos.size()];
              CallMethodWidget.this.fieldCompletionValues = new String[infos.size()];
              int i = 0;
              for (MethodInfo info : infos) {
                CallMethodWidget.this.fieldCompletionTexts[i] = info.getName();
                CallMethodWidget.this.fieldCompletionValues[i] = info.getNameWithParameters();
                i++;
              }

              CallMethodWidget.this.variableClass =
                  (String) CallMethodWidget.this.oracle.getGlobalVariable(mCall.getVariable());
            }
          });
    } else {

      final FactData pattern = (FactData) scenario.getFactTypes().get(mCall.getVariable());
      if (pattern != null) {
        this.oracle.getMethodInfos(
            pattern.getType(),
            new Callback<List<MethodInfo>>() {
              @Override
              public void callback(final List<MethodInfo> methodInfos) {
                CallMethodWidget.this.fieldCompletionTexts = new String[methodInfos.size()];
                CallMethodWidget.this.fieldCompletionValues = new String[methodInfos.size()];
                int i = 0;
                for (MethodInfo methodInfo : methodInfos) {
                  CallMethodWidget.this.fieldCompletionTexts[i] = methodInfo.getName();
                  CallMethodWidget.this.fieldCompletionValues[i] =
                      methodInfo.getNameWithParameters();
                  i++;
                }
                CallMethodWidget.this.variableClass = pattern.getType();
                CallMethodWidget.this.isBoundFact = true;
              }
            });
      }
    }

    doLayout();
    initWidget(this.layout);
  }
예제 #6
0
 private void ifFixturesSizeZeroThenAddExecutionTrace() {
   if (scenario.getFixtures().size() == 0) {
     scenario.getFixtures().add(new ExecutionTrace());
   }
 }