Package net.ssehub.easy.dslCore.test
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classAbstractTest.EqualitySetup<R extends net.ssehub.easy.basics.modelManagement.IModel>Setup data needed to compare test results for equality. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final net.ssehub.easy.basics.progress.ProgressObserver -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringassertNamingAndVersion(AbstractTest.EqualitySetup<R> data, TranslationResult<R> result) Asserts the naming and the version inresult.protected StringcheckEqualsAndPrepareMessage(String fileAsString, Writer model) Asserts the equality of two strings containing models and, if needed, emits the location where the strings are not equal.protected StringcheckEqualsAndPrepareMessage(String fileAsString, Writer model, boolean trimModel) Asserts the equality of two strings containing models and, if needed, emits the location where the strings are not equal.protected booleancheckEqualsAndPrint(String fileAsString, String modelAsString) Asserts the equality of two strings containing models and, if needed, prints the location where the strings are not equal.protected booleancheckEqualsAndPrint(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.protected StringcheckErrorCodes(List<Message> messages, List<Message> warnings, int... expectedErrorCodes) Asserts that the expected error codes match the errors stored inresult.protected StringcheckErrorCodes(TranslationResult<R> result, List<Message> warnings, int... expectedErrorCodes) Asserts that the expected error codes match the errors stored inresult.protected static StringcheckWarnings(List<Message> warnings, int... expectedWarnings) Returns the message for missing expected warnings.static FiledetermineTestDataDir(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 directorytestdata).protected Stringfile2String(File file) Turns a file into a string for comparison.private booleanhandleReplacementComment(StringWithPosition expected, StringWithPosition actual) Handles a replacement comment, i.e.private booleanCompare and handle possible line ends for equality over windows and linux conventions.protected intCompares two strings containing models and, if needed, returns the location where the strings are not equal.private static final booleanReturns whether the given character is a line end.private static final booleanReturns whether the given character is a whitespace but not a line end.protected static voidPerforms the resource initialization.static StringTurns a list of messages into a readable string.
-
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
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 directorytestdata).- 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 inresult.- Parameters:
result- the result from parsing and analyzing a projectwarnings- the warnings that occurred, to be modified as a side effect, may be nullexpectedErrorCodes- the allowed / expected error codes- Returns:
- the error message if the codes do not match,
nullelse
-
checkErrorCodes
protected String checkErrorCodes(List<Message> messages, List<Message> warnings, int... expectedErrorCodes) Asserts that the expected error codes match the errors stored inresult.- Parameters:
messages- the actual messages to be analyzedwarnings- the warnings that occurred, to be modified as a side effect, may be nullexpectedErrorCodes- the allowed / expected error codes- Returns:
- the error message if the codes do not match,
nullelse
-
file2String
Turns a file into a string for comparison. Iffileis somewhat temporary and you want to delete it, callSystem.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 thatfilecannot be found/read
-
isLineEnd
Returns whether the given character is a line end.- Parameters:
ch- the character to test- Returns:
trueif it is a line end,falseelse
-
isWhitespaceButNotLineEnd
Returns whether the given character is a whitespace but not a line end.- Parameters:
ch- the character to test- Returns:
trueif it is a whitespace but not a line end,falseelse
-
isEqual
Compares two strings containing models and, if needed, returns the location where the strings are not equal.- Parameters:
fileAsString- the file as a stringmodelAsString- the model as a string- Returns:
- the position in
fileAsStringwhere the inequality occurs, a negative value if the model contains more data, no problem if return value same/larger than length offileAsString
-
handleWindowsLinuxLineEnd
Compare and handle possible line ends for equality over windows and linux conventions. Ifs1ands2are at line ends, advance the positions over line ends- Parameters:
s1- the first string to be compareds2- the second string to be compared- Returns:
trueifs1ands2are at line ends and both were advanced,falseif nothing changed
-
handleReplacementComment
Handles a replacement comment, i.e. //* occurred inexpected. The current position inactualwill be compared toexpectedand if equal, the current and the next line inexpectedas well as the current line inactualwill be consumed- Parameters:
expected- the expected stringactual- the actual string- Returns:
trueif the comment is handled,falseif a comparison problem occurred and the lines are not considered to be equal.
-
checkEqualsAndPrint
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 stringmodelAsString- the model as a string- Returns:
trueif both are considered as equal,falseelse- 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 toSystem.err.println().- Parameters:
fileAsString- the file as a stringmodelAsString- the model as a stringwriter- A writer, which should be used for printing out a detailed error message- Returns:
trueif both are considered as equal,falseelse
-
checkEqualsAndPrepareMessage
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 stringmodel- 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 stringmodel- the model as a string in the writertrimModel- 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
Returns the message for missing expected warnings.- Parameters:
warnings- the warnings to checkexpectedWarnings- 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 inresult.- Parameters:
data- the data describing the setupresult- the data obtained from parsing- Returns:
- the message to be used in assertions
-
toString
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
-