Example #1
0
  /**
   * Execute this test. Takes the model sources, parses, type checks them then takes the AST and
   * applies whatever analysis is implemented in {@link #processModel(List)}. Afterwards, results
   * are compared with {@link #compareResults(Object, Object)}. <br>
   * <br>
   * If the test is running in update mode, testUpdate(Object) is executed instead of the
   * comparison.
   *
   * @param exSource holding the example data. Provided by {@link #testData()}
   * @throws FileNotFoundException
   * @throws IOException
   * @throws ParserException
   * @throws LexException
   */
  @Test
  @Parameters(method = "testData")
  public void testCase(ExampleSourceData exSource)
      throws FileNotFoundException, IOException, ParserException, LexException {

    ExampleAstData exData = ExamplesUtility.parseTcExample(exSource);

    this.testName = exData.getExampleName();
    this.model = exData.getModel();
    this.resultPath = RESULTS_EXAMPLES + exData.getExampleName() + PathsProvider.RESULT_EXTENSION;
    this.updateResult = updateCheck();

    R actual = processModel(model);
    if (updateResult) {
      testUpdate(actual);
    } else {
      R expected = null;
      try {
        expected = deSerializeResult(resultPath);
      } catch (FileNotFoundException e) {
        Assert.fail(
            "Test "
                + testName
                + " failed. No result file found. Use \"-D"
                + getUpdatePropertyString()
                + "."
                + testName
                + "\" to create an initial one."
                + "\n The test result was: "
                + actual.toString());
      }
      this.compareResults(actual, expected);
    }
  }
Example #2
0
 /**
  * Provide test data. Provides an array of {@link ExampleSourceData}, each holding data (including
  * sources) of an Overture example.
  *
  * <p>Each entry initializes a test for a single Overture example. Test results are derived from
  * the names of the examples and ,by convention, are stored under the <code>
  * src/test/resources/examples</code> folder of each module using this test.
  *
  * @return a collection of {@link ExampleSourceData}
  * @throws ParserException
  * @throws LexException
  * @throws IOException
  * @throws URISyntaxException
  */
 public Object[] testData() throws ParserException, LexException, IOException, URISyntaxException {
   return ExamplesUtility.getExamplesAsts(getRelativeExamplesPath()).toArray();
 }