Update bridge to match OASIS
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@919007 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bab0ea305e
commit
6dce7550ff
2 changed files with 38 additions and 51 deletions
|
@ -44,7 +44,6 @@ public class TuscanyOSGiRuntimeBridge implements RuntimeBridge {
|
|||
|
||||
protected NodeLauncher launcher;
|
||||
protected Node node;
|
||||
TestConfiguration testConfiguration = null;
|
||||
protected Properties expectedErrorMessages;
|
||||
|
||||
public TuscanyOSGiRuntimeBridge() {
|
||||
|
@ -58,26 +57,18 @@ public class TuscanyOSGiRuntimeBridge implements RuntimeBridge {
|
|||
}
|
||||
}
|
||||
|
||||
public TestConfiguration getTestConfiguration() {
|
||||
return testConfiguration;
|
||||
}
|
||||
|
||||
public void setTestConfiguration(TestConfiguration testConfiguration) {
|
||||
this.testConfiguration = testConfiguration;
|
||||
}
|
||||
|
||||
public boolean startContribution(String contributionLocation, String[] contributionNames) throws Exception {
|
||||
public boolean startContribution(String compositeName, String contributionLocation, String[] contributionNames) throws Exception {
|
||||
try {
|
||||
// Tuscany specific code which starts the contribution(s) holding the test
|
||||
launcher = NodeLauncher.newInstance();
|
||||
|
||||
Contribution[] contributions = new Contribution[contributionNames.length];
|
||||
String[] contributionURIs = getContributionURIs(contributionLocation);
|
||||
String[] contributionURIs = getContributionURIs(contributionLocation,contributionNames);
|
||||
for (int i = 0; i < contributions.length; i++) {
|
||||
contributions[i] = new Contribution(contributionNames[i], contributionURIs[i]);
|
||||
} // end for
|
||||
|
||||
node = launcher.createNode(testConfiguration.getComposite(), contributions);
|
||||
node = launcher.createNode(compositeName, contributions);
|
||||
System.out.println("SCA Node API ClassLoader: " + node.getClass().getClassLoader());
|
||||
// Start the node
|
||||
node.start();
|
||||
|
@ -97,17 +88,16 @@ public class TuscanyOSGiRuntimeBridge implements RuntimeBridge {
|
|||
* the contribution
|
||||
* @return the contribution locations as an array of Strings
|
||||
*/
|
||||
protected String[] getContributionURIs(String contributionLocation) throws Exception {
|
||||
String[] locations;
|
||||
locations = testConfiguration.getContributionNames();
|
||||
protected String[] getContributionURIs(String contributionLocation, String[] contributionNames) throws Exception {
|
||||
String[] locations = new String[contributionNames.length];
|
||||
|
||||
if (locations != null && contributionLocation != null) {
|
||||
|
||||
for (int i = 0; i < locations.length; i++) {
|
||||
String aLocation = contributionLocation.replaceAll("%1", locations[i]);
|
||||
String aLocation = contributionLocation.replaceAll("%1", contributionNames[i]);
|
||||
|
||||
locations[i] = aLocation;
|
||||
} // end for
|
||||
} // end for
|
||||
} else {
|
||||
if (locations == null) {
|
||||
// No contribution specified - throw an Exception
|
||||
|
@ -130,9 +120,6 @@ public class TuscanyOSGiRuntimeBridge implements RuntimeBridge {
|
|||
} // end if
|
||||
} // end method stopContribution
|
||||
|
||||
public String getContributionLocation(Class<?> testClass) {
|
||||
return ContributionLocationHelper.getContributionLocation(testConfiguration.getTestClass());
|
||||
} // end method getContributionLocation
|
||||
|
||||
public void checkError(String testName, Throwable ex) throws Throwable {
|
||||
String expectedMessage = expectedErrorMessages.getProperty(testName);
|
||||
|
|
|
@ -46,8 +46,6 @@ public class TuscanyRuntimeBridge implements RuntimeBridge {
|
|||
protected NodeFactory launcher;
|
||||
protected Node node;
|
||||
protected Properties expectedErrorMessages;
|
||||
|
||||
TestConfiguration testConfiguration = null;
|
||||
|
||||
public TuscanyRuntimeBridge() {
|
||||
// read test error mapping
|
||||
|
@ -60,26 +58,18 @@ public class TuscanyRuntimeBridge implements RuntimeBridge {
|
|||
}
|
||||
}
|
||||
|
||||
public TestConfiguration getTestConfiguration() {
|
||||
return testConfiguration;
|
||||
}
|
||||
|
||||
public void setTestConfiguration(TestConfiguration testConfiguration) {
|
||||
this.testConfiguration = testConfiguration;
|
||||
}
|
||||
|
||||
public boolean startContribution(String contributionLocation, String[] contributionNames) throws Exception {
|
||||
public boolean startContribution(String compositeName, String contributionLocation, String[] contributionNames) throws Exception {
|
||||
try {
|
||||
// Tuscany specific code which starts the contribution(s) holding the test
|
||||
launcher = NodeFactory.newInstance();
|
||||
|
||||
Contribution[] contributions = new Contribution[contributionNames.length];
|
||||
String[] contributionURIs = getContributionURIs(contributionLocation);
|
||||
String[] contributionURIs = getContributionURIs(contributionLocation, contributionNames);
|
||||
for (int i = 0; i < contributions.length; i++) {
|
||||
contributions[i] = new Contribution(contributionNames[i], contributionURIs[i]);
|
||||
} // end for
|
||||
|
||||
node = launcher.createNode(testConfiguration.getComposite(), contributions);
|
||||
node = launcher.createNode(compositeName, contributions);
|
||||
// Start the node
|
||||
node.start();
|
||||
|
||||
|
@ -102,14 +92,13 @@ public class TuscanyRuntimeBridge implements RuntimeBridge {
|
|||
* the contribution
|
||||
* @return the contribution locations as an array of Strings
|
||||
*/
|
||||
protected String[] getContributionURIs(String contributionLocation) throws Exception {
|
||||
String[] locations;
|
||||
locations = testConfiguration.getContributionNames();
|
||||
protected String[] getContributionURIs(String contributionLocation, String[] contributionNames) throws Exception {
|
||||
String[] locations = new String[contributionNames.length];
|
||||
|
||||
if (locations != null && contributionLocation != null) {
|
||||
|
||||
for (int i = 0; i < locations.length; i++) {
|
||||
String aLocation = contributionLocation.replaceAll("%1", locations[i]);
|
||||
String aLocation = contributionLocation.replaceAll("%1", contributionNames[i]);
|
||||
|
||||
locations[i] = aLocation;
|
||||
} // end for
|
||||
|
@ -134,10 +123,6 @@ public class TuscanyRuntimeBridge implements RuntimeBridge {
|
|||
launcher.destroy();
|
||||
} // end if
|
||||
} // end method stopContribution
|
||||
|
||||
public String getContributionLocation(Class<?> testClass) {
|
||||
return ContributionLocationHelper.getContributionLocation(testConfiguration.getTestClass());
|
||||
} // end method getContributionLocation
|
||||
|
||||
public void checkError(String testName, Throwable ex) throws Throwable {
|
||||
|
||||
|
@ -154,28 +139,43 @@ public class TuscanyRuntimeBridge implements RuntimeBridge {
|
|||
ex.printStackTrace();
|
||||
fail("Null received error message for test " + testName);
|
||||
} // end if
|
||||
|
||||
|
||||
if (expectedMessage.startsWith("*")) {
|
||||
// allow using * to ignore a message comparison
|
||||
return;
|
||||
}
|
||||
|
||||
// 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 (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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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() ) {
|
||||
if (receivedMessage.contains(expectedMessage)) {
|
||||
return;
|
||||
} else {
|
||||
receivedMessage = receivedMessage.substring(0, expectedMessage.length() );
|
||||
}
|
||||
return;
|
||||
// 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;
|
||||
|
@ -185,7 +185,7 @@ public class TuscanyRuntimeBridge implements RuntimeBridge {
|
|||
protected void writeMissingMessage(String testName, Throwable ex) {
|
||||
try {
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter("target/OTestMissingMsgs.txt", true));
|
||||
out.write(testName + "=* " + ex.getMessage());
|
||||
out.write(testName + "=*");
|
||||
out.newLine();
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
|
|
Loading…
Add table
Reference in a new issue