Package dev.galasa.textscan
Interface ILogScanner
public interface ILogScanner
Provides utility text scanning routines for tests and Managers to use, intended for use with logs or batch jobs etc.
The scanner will remember where the last scan got to, so the next search will continue from that point.
You can obtain an implementation of this interface using the
The scanner will remember where the last scan got to, so the next search will continue from that point.
You can obtain an implementation of this interface using the
LogScanner
annotation.
You will need a separate object per log you will be scanning.-
Method Summary
Modifier and TypeMethodDescriptionSets the checkpoint to the end of the current loglong
Returns the current position of the checkpoint.reset()
Resets this scanner so it can be reusedResets the checkpoint back to zeroConvenience method for scan(Pattern.Compile("\Q" + searchString + "\E"), Pattern.Compile("\Q" + failString + "\E"), count)Search the log for regex patterns.scanForMatch
(String searchString, String failString, int occurrance) Convenience method for scanForMatch(Pattern.Compile("\Q" + searchString + "\E"), Pattern.Compile("\Q" + searchString + "\E"), occurrence)scanForMatch
(Pattern searchPattern, Pattern failPattern, int occurrance) Search the log for regex patterns.scanForMatchSinceCheckpoint
(String searchString, String failString, int occurrance) Convenience method for scanForMatchSinceCheckpoint(Pattern.Compile("\Q" + searchString + "\E"), Pattern.Compile("\Q" + searchString + "\E"), occurrence)scanForMatchSinceCheckpoint
(Pattern searchPattern, Pattern failPattern, int occurrance) Search the log for regex patterns, from the last checkpoint.scanSinceCheckpoint
(String searchString, String failString, int count) Convenience method for scanSinceCheckpoint(Pattern.Compile("\Q" + searchString + "\E"), Pattern.Compile("\Q" + failString + "\E"), count)scanSinceCheckpoint
(Pattern searchPattern, Pattern failPattern, int count) Search the log for regex patterns, from the last checkpoint.setCheckpoint
(long checkpoint) Manually set a checkpoint to the supplied valuesetScannable
(ITextScannable scannable) Set the scannable that will be used with this scanner and will updateUpdate the scannable.
-
Method Details
-
setScannable
Set the scannable that will be used with this scanner and will update- Parameters:
scannable
- The scannable to be associated with this scanner- Returns:
- this interface for fluent use
- Throws:
TextScanException
- If a scannable has already been set, updateText called or is null, or the first update fails
-
updateScannable
Update the scannable.- Returns:
- this interface for fluent use
- Throws:
TextScanException
-
reset
ILogScanner reset()Resets this scanner so it can be reused- Returns:
- this interface for fluent use
-
checkpoint
Sets the checkpoint to the end of the current log- Returns:
- this interface for fluent use
- Throws:
TextScanException
-
setCheckpoint
Manually set a checkpoint to the supplied value- Returns:
- this interface for fluent use
- Throws:
TextScanException
-
resetCheckpoint
ILogScanner resetCheckpoint()Resets the checkpoint back to zero- Returns:
- this interface for fluent use
-
getCheckpoint
long getCheckpoint()Returns the current position of the checkpoint. A value of -1 means theITextScannable
has not been checkpointed- Returns:
- the current checkpoint
-
scan
ILogScanner scan(Pattern searchPattern, Pattern failPattern, int count) throws FailTextFoundException, MissingTextException, IncorrectOccurrencesException, TextScanException Search the log for regex patterns. It will search initially search for any occurrence of the failPattern before searching for the searchPattern. The search will find at least "count" number of searchPatterns in the text.
NOTE: This method will scan from the start of the log, it will not use the checkpoint- Parameters:
searchPattern
- The regex to search forfailPattern
- Failure regex to search for, can be null meaning no fail searchcount
- at least how many occurrences of the searchPattern must exist- Returns:
- This log scanner for fluent calls
- Throws:
FailTextFoundException
- If the failurePattern was foundMissingTextException
- If no occurrences of the searchPattern was foundIncorrectOccurrencesException
- If insufficient occurrences were found, if there are zero occurrences, then MissingTextException will be thrownTextScanException
- If any other problem found
-
scan
ILogScanner scan(String searchString, String failString, int count) throws FailTextFoundException, MissingTextException, IncorrectOccurrencesException, TextScanException Convenience method for scan(Pattern.Compile("\Q" + searchString + "\E"), Pattern.Compile("\Q" + failString + "\E"), count)- Parameters:
searchString
- The text to search forfailString
- Failure text to search for, can be null meaning no fail searchcount
- at least how many occurrences of the searchText must exist- Returns:
- This log scanner for fluent calls
- Throws:
FailTextFoundException
- If the failText was foundMissingTextException
- If no occurrences of the searchText was foundIncorrectOccurrencesException
- If insufficient occurrences were found, if there are zero occurrences, then MissingTextException will be thrownTextScanException
- If any other problem found
-
scanSinceCheckpoint
ILogScanner scanSinceCheckpoint(Pattern searchPattern, Pattern failPattern, int count) throws FailTextFoundException, MissingTextException, IncorrectOccurrencesException, TextScanException Search the log for regex patterns, from the last checkpoint. It will search initially search for any occurrence of the failPattern before searching for the searchPattern. The search will find at least "count" number of searchPatterns in the text.
NOTE: This method will scan from the start of the log, it will not use the checkpoint- Parameters:
searchPattern
- The regex to search forfailPattern
- Failure regex to search for, can be null meaning no fail searchcount
- At least how many occurrences of the searchPattern must exist- Returns:
- This log scanner for fluent calls
- Throws:
FailTextFoundException
- If the failurePattern was foundMissingTextException
- If no occurrences of the searchPattern was foundIncorrectOccurrencesException
- If insufficient occurrences were found, if there are zero occurrences, then MissingTextException will be thrownTextScanException
- If any other problem found
-
scanSinceCheckpoint
ILogScanner scanSinceCheckpoint(String searchString, String failString, int count) throws FailTextFoundException, MissingTextException, IncorrectOccurrencesException, TextScanException Convenience method for scanSinceCheckpoint(Pattern.Compile("\Q" + searchString + "\E"), Pattern.Compile("\Q" + failString + "\E"), count)- Parameters:
searchString
- The text to search forfailString
- Failure text to search for, can be null meaning no fail searchcount
- at least how many occurrences of the searchString must exist- Returns:
- This log scanner for fluent calls
- Throws:
FailTextFoundException
- If the failString was foundMissingTextException
- If no occurrences of the searchString was foundIncorrectOccurrencesException
- If insufficient occurrences were found, if there are zero occurrences, then MissingTextException will be thrownTextScanException
- If any other problem found
-
scanForMatch
String scanForMatch(Pattern searchPattern, Pattern failPattern, int occurrance) throws MissingTextException, IncorrectOccurrencesException, TextScanException Search the log for regex patterns. It will search initially search for any occurrence of the failPattern before searching for the searchPattern. The search will find at least "count" number of searchPatterns in the text. Useful for returning the actual value of the searchPattern- Parameters:
searchPattern
- The regex to search forfailPattern
- Failure regex to search for, can be null meaning no fail searchoccurrance
- The occurrence to be returned- Returns:
- The text of the searchPattern found
- Throws:
MissingTextException
- The searchPattern was not found at allIncorrectOccurrencesException
- If the specified occurrence was not foundTextScanException
- If any other problem found
-
scanForMatch
String scanForMatch(String searchString, String failString, int occurrance) throws MissingTextException, IncorrectOccurrencesException, TextScanException Convenience method for scanForMatch(Pattern.Compile("\Q" + searchString + "\E"), Pattern.Compile("\Q" + searchString + "\E"), occurrence)- Parameters:
searchString
- The text to search forfailString
- Failure text to search for, can be null meaning no fail searchoccurrance
- The occurrence to be returned- Returns:
- The text of the searchPattern found
- Throws:
MissingTextException
- The searchPattern was not found at allIncorrectOccurrencesException
- If the specified occurrence was not foundTextScanException
- If any other problem found
-
scanForMatchSinceCheckpoint
String scanForMatchSinceCheckpoint(Pattern searchPattern, Pattern failPattern, int occurrance) throws MissingTextException, IncorrectOccurrencesException, TextScanException Search the log for regex patterns, from the last checkpoint. It will search initially search for any occurrence of the failPattern before searching for the searchPattern. The search will find at least "count" number of searchPatterns in the text. Useful for returning the actual value of the searchPattern- Parameters:
searchPattern
- The regex to search forfailPattern
- Failure regex to search for, can be null meaning no fail searchoccurrance
- The occurrence to be returned- Returns:
- The text of the searchPattern found
- Throws:
MissingTextException
- The searchPattern was not found at allIncorrectOccurrencesException
- If the specified occurrence was not foundTextScanException
- If any other problem found
-
scanForMatchSinceCheckpoint
String scanForMatchSinceCheckpoint(String searchString, String failString, int occurrance) throws MissingTextException, IncorrectOccurrencesException, TextScanException Convenience method for scanForMatchSinceCheckpoint(Pattern.Compile("\Q" + searchString + "\E"), Pattern.Compile("\Q" + searchString + "\E"), occurrence)- Parameters:
searchString
- The text to search forfailString
- Failure text to search for, can be null meaning no fail searchoccurrance
- The occurrence to be returned- Returns:
- The text of the searchPattern found
- Throws:
MissingTextException
- The searchString was not found at allIncorrectOccurrencesException
- If the specified occurrence was not foundTextScanException
- If any other problem found
-