Exemplo n.º 1
0
  public ProcessingResult process(Resource resource) {
    EventRecorder eventRecorder = new EventRecorder();
    stubTarget = new StubTarget();
    if (fixture == null) {
      fixture = new Fixture(new DummyFixture());
      withResource(new Resource("/spec/concordion/Dummy.html"), "<html/>");
    } else {
      withResource(
          new ClassNameBasedSpecificationLocator("html").locateSpecification(fixture), "<html/>");
    }
    ConcordionBuilder concordionBuilder =
        new ConcordionBuilder()
            .withAssertEqualsListener(eventRecorder)
            .withThrowableListener(eventRecorder)
            .withSource(stubSource)
            .withEvaluatorFactory(evaluatorFactory)
            .withTarget(stubTarget)
            .withFixture(fixture);

    fixtureExtensionLoader.addExtensions(fixture, concordionBuilder);
    if (extension != null) {
      extension.addTo(concordionBuilder);
    }
    Concordion concordion = null;
    try {
      concordion = concordionBuilder.build();
    } catch (UnableToBuildConcordionException e) {
      throw new RuntimeException("Test rig failed to build concordion", e);
    }

    try {

      ResultSummary resultSummary = null;
      concordion.override(resource, fixture);
      List<String> examples = concordion.getExampleNames();
      if (!examples.isEmpty()) {
        for (String example : examples) {
          resultSummary = concordion.processExample(example);
        }
      }
      concordion.finish();

      String xml = stubTarget.getWrittenString(resource);
      return new ProcessingResult(resultSummary, eventRecorder, xml);
    } catch (IOException e) {
      throw new RuntimeException("Test rig failed to process specification", e);
    }
  }
Exemplo n.º 2
0
  public ResultSummary run(Object fixture) throws IOException {

    ConcordionRunOutput runOutput = cachedRunResults.startRun(fixture.getClass());
    ResultSummary actualResultSummary =
        runOutput == null ? null : runOutput.getActualResultSummary();

    ResultSummary postProcessedResultSummary =
        runOutput == null ? null : runOutput.getPostProcessedResultSummary();

    String additionalInformation = null;
    if (runOutput == null) {
      ConcordionBuilder concordionBuilder = new ConcordionBuilder().withFixture(fixture);
      fixtureExtensionLoader.addExtensions(fixture, concordionBuilder);

      try {
        actualResultSummary = concordionBuilder.build().process(fixture);
        // we want to make sure all the annotations are considered when storing the result summary

        postProcessedResultSummary =
            cachedRunResults.convertForCache(actualResultSummary, fixture.getClass());

        cachedRunResults.finishRun(
            fixture.getClass(), actualResultSummary, postProcessedResultSummary);

      } catch (RuntimeException e) {
        // the run failed miserably. Tell the cache that the run failed
        cachedRunResults.failRun(fixture.getClass());
        throw e;
      }

    } else {
      additionalInformation = "From cache: ";
    }

    printResultSummary(fixture, actualResultSummary, additionalInformation);

    return actualResultSummary.getMeaningfulResultSummary(fixture);
  }