update message checking routine to match JSE version
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1034422 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5ce019743f
commit
328da86576
1 changed files with 77 additions and 8 deletions
|
@ -21,6 +21,8 @@ package org.apache.tuscany.sca.otest;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
@ -30,6 +32,8 @@ import org.apache.tuscany.sca.node.equinox.launcher.Contribution;
|
|||
import org.apache.tuscany.sca.node.equinox.launcher.ContributionLocationHelper;
|
||||
import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher;
|
||||
|
||||
import testClient.TestException_Exception;
|
||||
|
||||
import client.RuntimeBridge;
|
||||
import client.TestConfiguration;
|
||||
|
||||
|
@ -121,30 +125,95 @@ public class TuscanyOSGiRuntimeBridge implements RuntimeBridge {
|
|||
} // end method stopContribution
|
||||
|
||||
|
||||
public void checkError(String testName, Throwable ex) throws Throwable {
|
||||
public void checkError(String testName, Throwable ex) throws Throwable {
|
||||
|
||||
String expectedMessage = expectedErrorMessages.getProperty(testName);
|
||||
String receivedMessage = ex.getMessage();
|
||||
String receivedMessage = getErrorMessage(ex);//ex.getMessage();
|
||||
|
||||
if (expectedMessage == null){
|
||||
writeMissingMessage(testName, ex);
|
||||
fail("Null expected error message for test " + testName +
|
||||
"Please add message to oasis-sca-tests-errors.properties");
|
||||
}
|
||||
} // end if
|
||||
|
||||
if (receivedMessage == null){
|
||||
ex.printStackTrace();
|
||||
fail("Null received error message for test " + testName);
|
||||
} // end if
|
||||
|
||||
if (expectedMessage.startsWith("*")) {
|
||||
// allow using * to ignore a message comparison
|
||||
return;
|
||||
}
|
||||
|
||||
int messageStart = receivedMessage.indexOf("] - ");
|
||||
// Deal with the case where the message has variable parts within it
|
||||
// marked with the characters ***. Here we tokenize the expected string
|
||||
// and make sure all the individual parts are present in the results string
|
||||
String expectedMessageParts[] = expectedMessage.split("\\*\\*\\*");
|
||||
|
||||
if (messageStart < 0){
|
||||
fail("Message separator not found for test " + testName);
|
||||
if (expectedMessageParts.length > 1){
|
||||
int foundParts = 0;
|
||||
for(int i = 0; i < expectedMessageParts.length; i++){
|
||||
if (receivedMessage.indexOf(expectedMessageParts[i]) > -1 ){
|
||||
foundParts++;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundParts == expectedMessageParts.length){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
receivedMessage = receivedMessage.substring(messageStart + 4);
|
||||
// Deal with the case where the end of the message is variable (eg contains absolute filenames)
|
||||
// and where the only relevant part is the start of the message - in this case the expected
|
||||
// message only contains the stem section which is unchanging...
|
||||
if( receivedMessage.length() > expectedMessage.length() ) {
|
||||
// Truncate the received message to the length of the expected message
|
||||
receivedMessage = receivedMessage.substring(0, expectedMessage.length() );
|
||||
} // end if
|
||||
|
||||
if (!expectedMessage.equals(receivedMessage)) {
|
||||
writeIncorrectMessage(testName, expectedMessage, receivedMessage);
|
||||
}
|
||||
|
||||
assertEquals( expectedMessage, receivedMessage );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void writeMissingMessage(String testName, Throwable ex) {
|
||||
try {
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter("target/OTestMissingMsgs.txt", true));
|
||||
out.write(testName + "=*");
|
||||
out.newLine();
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeIncorrectMessage(String testName, String expected, String received) {
|
||||
try {
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter("target/OTestIncorrectMsgs.txt", true));
|
||||
out.write(testName); out.newLine();
|
||||
out.write(" " + expected); out.newLine();
|
||||
out.write(" " + received); out.newLine();
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
protected String getErrorMessage(Throwable ex) {
|
||||
String errorMessage = null;
|
||||
|
||||
if (ex instanceof TestException_Exception) {
|
||||
TestException_Exception te = (TestException_Exception) ex;
|
||||
errorMessage = te.getFaultInfo().getMessage();
|
||||
} else {
|
||||
errorMessage = ex.getMessage();
|
||||
}
|
||||
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
} // end class TuscanyRuntimeBridge
|
||||
|
|
Loading…
Reference in a new issue