Class AbstractTest<R extends net.ssehub.easy.basics.modelManagement.IModel>

java.lang.Object
net.ssehub.easy.dslCore.test.AbstractTest<R>
Type Parameters:
R - the top-level result model class

public abstract class AbstractTest<R extends net.ssehub.easy.basics.modelManagement.IModel> extends Object
An abstract test support class for reading, parsing and comparing models. Due to architectural conventions, we avoid any jUnit dependencies in this bundle.
Author:
Holger Eichelberger
  • Field Details

    • OBSERVER

      protected static final net.ssehub.easy.basics.progress.ProgressObserver OBSERVER
  • Constructor Details

    • AbstractTest

      public AbstractTest()
  • Method Details

    • resourceInitialization

      protected static void resourceInitialization()
      Performs the resource initialization.
    • determineTestDataDir

      public static File determineTestDataDir(String property)
      Determines the actual directory with the test IVML files depending on the JVM system specified property which may contain a specific directory (or be empty -> default directory testdata).
      Parameters:
      property - the JVM property to read out
      Returns:
      the actual directory as file
    • checkErrorCodes

      protected String checkErrorCodes(TranslationResult<R> result, List<Message> warnings, int... expectedErrorCodes)
      Asserts that the expected error codes match the errors stored in result.
      Parameters:
      result - the result from parsing and analyzing a project
      warnings - the warnings that occurred, to be modified as a side effect, may be null
      expectedErrorCodes - the allowed / expected error codes
      Returns:
      the error message if the codes do not match, null else
    • checkErrorCodes

      protected String checkErrorCodes(List<Message> messages, List<Message> warnings, int... expectedErrorCodes)
      Asserts that the expected error codes match the errors stored in result.
      Parameters:
      messages - the actual messages to be analyzed
      warnings - the warnings that occurred, to be modified as a side effect, may be null
      expectedErrorCodes - the allowed / expected error codes
      Returns:
      the error message if the codes do not match, null else
    • file2String

      protected String file2String(File file) throws IOException
      Turns a file into a string for comparison. If file is somewhat temporary and you want to delete it, call System.gc(); after this method. We do not call it by default as it affects the performance of the tests.
      Parameters:
      file - the file to be turned into a string
      Returns:
      the resulting string
      Throws:
      IOException - in case that file cannot be found/read
    • isLineEnd

      private static final boolean isLineEnd(Character ch)
      Returns whether the given character is a line end.
      Parameters:
      ch - the character to test
      Returns:
      true if it is a line end, false else
    • isWhitespaceButNotLineEnd

      private static final boolean isWhitespaceButNotLineEnd(Character ch)
      Returns whether the given character is a whitespace but not a line end.
      Parameters:
      ch - the character to test
      Returns:
      true if it is a whitespace but not a line end, false else
    • isEqual

      protected int isEqual(String fileAsString, String modelAsString)
      Compares two strings containing models and, if needed, returns the location where the strings are not equal.
      Parameters:
      fileAsString - the file as a string
      modelAsString - the model as a string
      Returns:
      the position in fileAsString where the inequality occurs, a negative value if the model contains more data, no problem if return value same/larger than length of fileAsString
    • handleWindowsLinuxLineEnd

      private boolean handleWindowsLinuxLineEnd(StringWithPosition s1, StringWithPosition s2)
      Compare and handle possible line ends for equality over windows and linux conventions. If s1 and s2 are at line ends, advance the positions over line ends
      Parameters:
      s1 - the first string to be compared
      s2 - the second string to be compared
      Returns:
      true if s1 and s2 are at line ends and both were advanced, false if nothing changed
    • handleReplacementComment

      private boolean handleReplacementComment(StringWithPosition expected, StringWithPosition actual)
      Handles a replacement comment, i.e. //* occurred in expected. The current position in actual will be compared to expected and if equal, the current and the next line in expected as well as the current line in actual will be consumed
      Parameters:
      expected - the expected string
      actual - the actual string
      Returns:
      true if the comment is handled, false if a comparison problem occurred and the lines are not considered to be equal.
    • checkEqualsAndPrint

      protected boolean checkEqualsAndPrint(String fileAsString, String modelAsString)
      Asserts the equality of two strings containing models and, if needed, prints the location where the strings are not equal.
      Parameters:
      fileAsString - the file as a string
      modelAsString - the model as a string
      Returns:
      true if both are considered as equal, false else
      See Also:
    • checkEqualsAndPrint

      protected boolean checkEqualsAndPrint(String fileAsString, String modelAsString, PrintWriter writer)
      Asserts the equality of two strings containing models and, if needed, prints the location where the strings are not equal. This also adds the error cause to the given writer instead of printing it to System.err.println().
      Parameters:
      fileAsString - the file as a string
      modelAsString - the model as a string
      writer - A writer, which should be used for printing out a detailed error message
      Returns:
      true if both are considered as equal, false else
    • checkEqualsAndPrepareMessage

      protected String checkEqualsAndPrepareMessage(String fileAsString, Writer model) throws IOException
      Asserts the equality of two strings containing models and, if needed, emits the location where the strings are not equal. The model string will be trimmed before comparison.
      Parameters:
      fileAsString - the file as a string
      model - the model as a string in the writer
      Returns:
      null if no error occurred, the formatted error string else
      Throws:
      IOException - in case of (internal) IO problems
      See Also:
    • checkEqualsAndPrepareMessage

      protected String checkEqualsAndPrepareMessage(String fileAsString, Writer model, boolean trimModel) throws IOException
      Asserts the equality of two strings containing models and, if needed, emits the location where the strings are not equal.
      Parameters:
      fileAsString - the file as a string
      model - the model as a string in the writer
      trimModel - trim the model (string) on both sides before comparing it or only at the end
      Returns:
      null if no error occurred, the formatted error string else
      Throws:
      IOException - in case of (internal) IO problems
      See Also:
    • checkWarnings

      protected static String checkWarnings(List<Message> warnings, int... expectedWarnings)
      Returns the message for missing expected warnings.
      Parameters:
      warnings - the warnings to check
      expectedWarnings - the expected warnings
      Returns:
      null in case of no message, the message text else
    • assertNamingAndVersion

      protected String assertNamingAndVersion(AbstractTest.EqualitySetup<R> data, TranslationResult<R> result)
      Asserts the naming and the version in result.
      Parameters:
      data - the data describing the setup
      result - the data obtained from parsing
      Returns:
      the message to be used in assertions
    • toString

      public static String toString(List<Message> messages)
      Turns a list of messages into a readable string.
      Parameters:
      messages - the messages to be turned into a string
      Returns:
      the textual representation of the messages