if (null == ex) {
if (expectedMsgPattern == null) {
// No error expected, and no error happened.
return;
} else {
throw new AssertionFailedError(
"Expected query to throw exception, but it did not; "
+ "query [" + ras.source
+ "]; expected [" + expectedMsgPattern + "]");
}
}
Throwable actualException = ex;
String actualMessage = actualException.getMessage();
int actualLine = -1;
int actualColumn = -1;
int actualEndLine = 100;
int actualEndColumn = 99;
// Search for a SqlParseException -- with its position set -- somewhere
// in the stack.
MdxParseException mpe = null;
for (Throwable x = ex; x != null; x = x.getCause()) {
if ((x instanceof MdxParseException)
&& (((MdxParseException) x).getRegion() != null))
{
mpe = (MdxParseException) x;
break;
}
if (x.getCause() == x) {
break;
}
}
if (mpe != null) {
final ParseRegion region = mpe.getRegion();
actualLine = region.getStartLine();
actualColumn = region.getStartColumn();
actualEndLine = region.getEndLine();
actualEndColumn = region.getEndColumn();
actualException = mpe;
actualMessage = actualException.getMessage();
} else {
final String message = ex.getMessage();
if (message != null) {
Matcher matcher = lineColTwicePattern.matcher(message);
if (matcher.matches()) {
actualLine = Integer.parseInt(matcher.group(1));
actualColumn = Integer.parseInt(matcher.group(2));
actualEndLine = Integer.parseInt(matcher.group(3));
actualEndColumn = Integer.parseInt(matcher.group(4));
actualMessage = matcher.group(5);
} else {
matcher = lineColPattern.matcher(message);
if (matcher.matches()) {
actualLine = Integer.parseInt(matcher.group(1));
actualColumn = Integer.parseInt(matcher.group(2));
}
}
}
}
if (null == expectedMsgPattern) {
if (null != actualException) {
actualException.printStackTrace();
fail(
"Validator threw unexpected exception"
+ "; query [" + ras.source
+ "]; exception [" + actualMessage
+ "]; pos [line " + actualLine
+ " col " + actualColumn
+ " thru line " + actualLine
+ " col " + actualColumn + "]");
}
} else if (null != expectedMsgPattern) {
if (null == actualException) {
fail(
"Expected validator to throw "
+ "exception, but it did not; query [" + ras.source
+ "]; expected [" + expectedMsgPattern + "]");
} else {
if ((actualColumn <= 0)
|| (actualLine <= 0)
|| (actualEndColumn <= 0)
|| (actualEndLine <= 0))
{
throw new AssertionFailedError(
"Error did not have position: "
+ " actual pos [line " + actualLine
+ " col " + actualColumn
+ " thru line " + actualEndLine
+ " col " + actualEndColumn + "]");
}
String sqlWithCarets =
new ParseRegion(
actualLine,
actualColumn,
actualEndLine,
actualEndColumn).annotate(ras.source);
if (ras.region == null) {
throw new AssertionFailedError(
"todo: add carets to sql: " + sqlWithCarets);
}
if ((actualMessage == null)
|| !actualMessage.matches(expectedMsgPattern))
{