summaryrefslogtreecommitdiffstats
path: root/otest
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-11-12 15:33:54 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-11-12 15:33:54 +0000
commit328da86576c9493d6dc82721029725d1993809cd (patch)
tree02db31318700b91a0bfc98cb812c6e1c562fc728 /otest
parent5ce019743f6bf975afcb3edfb29b6e547453504f (diff)
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
Diffstat (limited to 'otest')
-rw-r--r--otest/newlayout/tuscany-policy-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyOSGiRuntimeBridge.java85
1 files changed, 77 insertions, 8 deletions
diff --git a/otest/newlayout/tuscany-policy-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyOSGiRuntimeBridge.java b/otest/newlayout/tuscany-policy-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyOSGiRuntimeBridge.java
index 6f7af61cee..16bd27abae 100644
--- a/otest/newlayout/tuscany-policy-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyOSGiRuntimeBridge.java
+++ b/otest/newlayout/tuscany-policy-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyOSGiRuntimeBridge.java
@@ -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