Package net.ssehub.easy.dslCore.test
Class AbstractTest<R extends 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 IModel> extends java.lang.ObjectAn 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 Classes Modifier and Type Class Description protected static classAbstractTest.EqualitySetup<R extends IModel>Setup data needed to compare test results for equality.
-
Field Summary
Fields Modifier and Type Field Description protected static ProgressObserverOBSERVER
-
Constructor Summary
Constructors Constructor Description AbstractTest()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringassertNamingAndVersion(AbstractTest.EqualitySetup<R> data, TranslationResult<R> result)Asserts the naming and the version inresult.protected java.lang.StringcheckEqualsAndPrepareMessage(java.lang.String fileAsString, java.io.Writer model)Asserts the equality of two strings containing models and, if needed, emits the location where the strings are not equal.protected java.lang.StringcheckEqualsAndPrepareMessage(java.lang.String fileAsString, java.io.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(java.lang.String fileAsString, java.lang.String modelAsString)Asserts the equality of two strings containing models and, if needed, prints the location where the strings are not equal.protected booleancheckEqualsAndPrint(java.lang.String fileAsString, java.lang.String modelAsString, java.io.PrintWriter writer)Asserts the equality of two strings containing models and, if needed, prints the location where the strings are not equal.protected java.lang.StringcheckErrorCodes(java.util.List<Message> messages, java.util.List<Message> warnings, int... expectedErrorCodes)Asserts that the expected error codes match the errors stored inresult.protected java.lang.StringcheckErrorCodes(TranslationResult<R> result, java.util.List<Message> warnings, int... expectedErrorCodes)Asserts that the expected error codes match the errors stored inresult.protected static java.lang.StringcheckWarnings(java.util.List<Message> warnings, int... expectedWarnings)Returns the message for missing expected warnings.static java.io.FiledetermineTestDataDir(java.lang.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 java.lang.Stringfile2String(java.io.File file)Turns a file into a string for comparison.private booleanhandleReplacementComment(StringWithPosition expected, StringWithPosition actual)Handles a replacement comment, i.e.private booleanhandleWindowsLinuxLineEnd(StringWithPosition s1, StringWithPosition s2)Compare and handle possible line ends for equality over windows and linux conventions.protected intisEqual(java.lang.String fileAsString, java.lang.String modelAsString)Compares two strings containing models and, if needed, returns the location where the strings are not equal.private static booleanisLineEnd(java.lang.Character ch)Returns whether the given character is a line end.private static booleanisWhitespaceButNotLineEnd(java.lang.Character ch)Returns whether the given character is a whitespace but not a line end.protected static voidresourceInitialization()Performs the resource initialization.static java.lang.StringtoString(java.util.List<Message> messages)Turns a list of messages into a readable string.
-
-
-
Field Detail
-
OBSERVER
protected static final ProgressObserver OBSERVER
-
-
Method Detail
-
resourceInitialization
protected static void resourceInitialization()
Performs the resource initialization.
-
determineTestDataDir
public static java.io.File determineTestDataDir(java.lang.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).- Parameters:
property- the JVM property to read out- Returns:
- the actual directory as file
-
checkErrorCodes
protected java.lang.String checkErrorCodes(TranslationResult<R> result, java.util.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 java.lang.String checkErrorCodes(java.util.List<Message> messages, java.util.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
protected java.lang.String file2String(java.io.File file) throws java.io.IOExceptionTurns 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:
java.io.IOException- in case thatfilecannot be found/read
-
isLineEnd
private static final boolean isLineEnd(java.lang.Character ch)
Returns whether the given character is a line end.- Parameters:
ch- the character to test- Returns:
trueif it is a line end,falseelse
-
isWhitespaceButNotLineEnd
private static final boolean isWhitespaceButNotLineEnd(java.lang.Character ch)
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
protected int isEqual(java.lang.String fileAsString, java.lang.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 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
private boolean handleWindowsLinuxLineEnd(StringWithPosition s1, StringWithPosition s2)
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
private boolean handleReplacementComment(StringWithPosition expected, StringWithPosition actual)
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
protected boolean checkEqualsAndPrint(java.lang.String fileAsString, java.lang.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 stringmodelAsString- the model as a string- Returns:
trueif both are considered as equal,falseelse- See Also:
checkEqualsAndPrint(String, String, PrintWriter)
-
checkEqualsAndPrint
protected boolean checkEqualsAndPrint(java.lang.String fileAsString, java.lang.String modelAsString, java.io.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 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
protected java.lang.String checkEqualsAndPrepareMessage(java.lang.String fileAsString, java.io.Writer model) throws java.io.IOExceptionAsserts 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:
java.io.IOException- in case of (internal) IO problems- See Also:
checkEqualsAndPrint(String, String, PrintWriter)
-
checkEqualsAndPrepareMessage
protected java.lang.String checkEqualsAndPrepareMessage(java.lang.String fileAsString, java.io.Writer model, boolean trimModel) throws java.io.IOExceptionAsserts 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:
java.io.IOException- in case of (internal) IO problems- See Also:
checkEqualsAndPrint(String, String, PrintWriter)
-
checkWarnings
protected static java.lang.String checkWarnings(java.util.List<Message> warnings, int... expectedWarnings)
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 java.lang.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
public static java.lang.String toString(java.util.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
-
-