From 992895003cb0c5f57425d4c49b98a6fb5e155857 Mon Sep 17 00:00:00 2001 From: slaws Date: Wed, 23 Sep 2009 09:43:01 +0000 Subject: add tuscany test runner back into the new test layout git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@818023 13f79535-47bb-0310-9956-ffa450edef68 --- .../otest/newlayout/tuscany-test-runner/pom.xml | 153 +++++++++++++++++++ .../resources/oasis-sca-tests-errors.properties | 19 +++ .../src/test/resources/oasis-sca-tests.properties | 32 ++++ .../sca/otest/TuscanyOSGiRuntimeBridge.java | 128 ++++++++++++++++ .../tuscany/sca/otest/TuscanyRuntimeBridge.java | 164 +++++++++++++++++++++ 5 files changed, 496 insertions(+) create mode 100644 java/sca/otest/newlayout/tuscany-test-runner/pom.xml create mode 100644 java/sca/otest/newlayout/tuscany-test-runner/src/test/resources/oasis-sca-tests-errors.properties create mode 100644 java/sca/otest/newlayout/tuscany-test-runner/src/test/resources/oasis-sca-tests.properties create mode 100644 java/sca/otest/newlayout/tuscany-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyOSGiRuntimeBridge.java create mode 100644 java/sca/otest/newlayout/tuscany-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyRuntimeBridge.java diff --git a/java/sca/otest/newlayout/tuscany-test-runner/pom.xml b/java/sca/otest/newlayout/tuscany-test-runner/pom.xml new file mode 100644 index 0000000000..752fb9a0f5 --- /dev/null +++ b/java/sca/otest/newlayout/tuscany-test-runner/pom.xml @@ -0,0 +1,153 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-SNAPSHOT + ../pom.xml + + tuscany-otests-asm-tests + Apache Tuscany SCA Specification Tests + + + + org.apache.tuscany.sca + tuscany-node-impl + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-node-impl-osgi + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-ws-axis2 + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-otests-asm-General + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-otests-asm-General_Java + 2.0-SNAPSHOT + + + + javax.servlet + servlet-api + 2.5 + + + + com.sun.xml.ws + jaxws-rt + 2.1.7 + + + + junit + junit + 4.5 + test + + + + + + + + ${artifactId} + + + org.apache.maven.plugins + maven-antrun-plugin + 1.3 + + + + ant + ant-trax + 1.6.5 + + + + + + copy-files-from-svn + generate-resources + + run + + + + + + + + + + + + + + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.3 + + + add-test-source + generate-sources + + add-test-source + + + + src/test/tjava + + + + + + + + diff --git a/java/sca/otest/newlayout/tuscany-test-runner/src/test/resources/oasis-sca-tests-errors.properties b/java/sca/otest/newlayout/tuscany-test-runner/src/test/resources/oasis-sca-tests-errors.properties new file mode 100644 index 0000000000..ddc07053da --- /dev/null +++ b/java/sca/otest/newlayout/tuscany-test-runner/src/test/resources/oasis-sca-tests-errors.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +ASM_10001=Duplicate intent {http://docs.oasis-open.org/ns/opencsa/scatests/200903}Fred found in domain + diff --git a/java/sca/otest/newlayout/tuscany-test-runner/src/test/resources/oasis-sca-tests.properties b/java/sca/otest/newlayout/tuscany-test-runner/src/test/resources/oasis-sca-tests.properties new file mode 100644 index 0000000000..e964f7fc7e --- /dev/null +++ b/java/sca/otest/newlayout/tuscany-test-runner/src/test/resources/oasis-sca-tests.properties @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# OASIS SCA Assembly test properties +# The implementation type to use for Assembly test suite +# org.oasis.sca.tests.assembly.lang=BPEL +org.oasis.sca.tests.assembly.lang=Java + +# The class to use as the Runtime Bridge for the SCA runtime under test +# - use client.TuscanyRuntimeBridge for the OSGi runtime +# - use tuscany.TuscanyRuntimeBridge for the Java runtime +# org.oasis.sca.tests.assembly.runtime_bridge=client.TuscanyRuntimeBridge +org.oasis.sca.tests.assembly.runtime_bridge=org.apache.tuscany.sca.otest.TuscanyRuntimeBridge + +# The location of the contributions for the test suite +# %1 represents the placement of the name of each contribution into the location URI +org.oasis.sca.tests.assembly.contribution.location=../sca-assembly/%1/target/%1.zip + diff --git a/java/sca/otest/newlayout/tuscany-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyOSGiRuntimeBridge.java b/java/sca/otest/newlayout/tuscany-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyOSGiRuntimeBridge.java new file mode 100644 index 0000000000..d0290ffdb7 --- /dev/null +++ b/java/sca/otest/newlayout/tuscany-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyOSGiRuntimeBridge.java @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.otest; + +import org.apache.tuscany.sca.node.Node; +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 client.RuntimeBridge; +import client.TestConfiguration; + + +/** + * An implementation of the Runtime Bridge for the Apache Tuscany SCA runtime (version 2.x) + * + */ +public class TuscanyOSGiRuntimeBridge implements RuntimeBridge { + + static final String CONTRIBUTION_LOCATION_PROPKEY = "OASIS_TESTENV_CONTRIBUTION_LOCATION"; + + protected NodeLauncher launcher; + protected Node node; + TestConfiguration testConfiguration = null; + + public TuscanyOSGiRuntimeBridge() { + + } + + public TestConfiguration getTestConfiguration() { + return testConfiguration; + } + + public void setTestConfiguration(TestConfiguration testConfiguration) { + this.testConfiguration = testConfiguration; + } + + public boolean startContribution(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); + for (int i = 0; i < contributions.length; i++) { + contributions[i] = new Contribution(contributionNames[i], contributionURIs[i]); + } // end for + + node = launcher.createNode(testConfiguration.getComposite(), contributions); + System.out.println("SCA Node API ClassLoader: " + node.getClass().getClassLoader()); + // Start the node + node.start(); + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + throw e; + } // end try + + return true; + } // end method startContribution + + /** + * Gets the location of the Contributions as URIs + * @param contributionLocation - a location pattern URI, which contains one or more "%1" + * substrings, which are substituted with the name of the contribution to get the URI of + * the contribution + * @return the contribution locations as an array of Strings + */ + protected String[] getContributionURIs(String contributionLocation) throws Exception { + String[] locations; + locations = testConfiguration.getContributionNames(); + + if (locations != null && contributionLocation != null) { + + for (int i = 0; i < locations.length; i++) { + String aLocation = contributionLocation.replaceAll("%1", locations[i]); + + locations[i] = aLocation; + } // end for + } else { + if (locations == null) { + // No contribution specified - throw an Exception + throw new Exception("Unable to start SCA runtime - no contribution supplied - error"); + } else { + // No contribution location supplied - throw an Exception + throw new Exception("Unable to start SCA runtime - no contribution location supplied - error"); + } // end if + } // end if + + return locations; + } // end getContributionURI + + public void stopContribution() { + if (node != null) { + node.stop(); + node.destroy(); + } // end if + if (launcher != null) { + launcher.destroy(); + } // end if + } // end method stopContribution + + public String getContributionLocation(Class testClass) { + return ContributionLocationHelper.getContributionLocation(testConfiguration.getTestClass()); + } // end method getContributionLocation + + public boolean checkError(String testName, Throwable exception) { + // TODO Auto-generated method stub + return true; + } + +} // end class TuscanyRuntimeBridge diff --git a/java/sca/otest/newlayout/tuscany-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyRuntimeBridge.java b/java/sca/otest/newlayout/tuscany-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyRuntimeBridge.java new file mode 100644 index 0000000000..98aaa2ef7b --- /dev/null +++ b/java/sca/otest/newlayout/tuscany-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyRuntimeBridge.java @@ -0,0 +1,164 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.otest; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.ContributionLocationHelper; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +import client.RuntimeBridge; +import client.TestConfiguration; + +/** + * An implementation of the Runtime Bridge for the Apache Tuscany SCA runtime (version 2.x) + * + */ +public class TuscanyRuntimeBridge implements RuntimeBridge { + + static final String CONTRIBUTION_LOCATION_PROPKEY = "OASIS_TESTENV_CONTRIBUTION_LOCATION"; + + protected NodeFactory launcher; + protected Node node; + protected Properties expectedErrorMessages; + + TestConfiguration testConfiguration = null; + + public TuscanyRuntimeBridge() { + // read test error mapping + expectedErrorMessages = new Properties(); + try { + InputStream propertiesStream = this.getClass().getResourceAsStream("/oasis-sca-tests-errors.properties"); + expectedErrorMessages.load(propertiesStream); + } catch (IOException e) { + System.out.println("Unable to read oasis-sca-tests-errors.properties file"); + } + } + + public TestConfiguration getTestConfiguration() { + return testConfiguration; + } + + public void setTestConfiguration(TestConfiguration testConfiguration) { + this.testConfiguration = testConfiguration; + } + + public boolean startContribution(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); + for (int i = 0; i < contributions.length; i++) { + contributions[i] = new Contribution(contributionNames[i], contributionURIs[i]); + } // end for + + node = launcher.createNode(testConfiguration.getComposite(), contributions); + // Start the node + node.start(); + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + throw e; + } // end try + + return true; + } // end method startContribution + + /** + * Gets the location of the Contributions as URIs + * @param contributionLocation - a location pattern URI, which contains one or more "%1" + * substrings, which are substituted with the name of the contribution to get the URI of + * the contribution + * @return the contribution locations as an array of Strings + */ + protected String[] getContributionURIs(String contributionLocation) throws Exception { + String[] locations; + locations = testConfiguration.getContributionNames(); + + if (locations != null && contributionLocation != null) { + + for (int i = 0; i < locations.length; i++) { + String aLocation = contributionLocation.replaceAll("%1", locations[i]); + + locations[i] = aLocation; + } // end for + } else { + if (locations == null) { + // No contribution specified - throw an Exception + throw new Exception("Unable to start SCA runtime - no contribution supplied - error"); + } else { + // No contribution location supplied - throw an Exception + throw new Exception("Unable to start SCA runtime - no contribution location supplied - error"); + } // end if + } // end if + + return locations; + } // end getContributionURI + + public void stopContribution() { + if (node != null) { + node.stop(); + node.destroy(); + } // end if + if (launcher != null) { + launcher.destroy(); + } // end if + } // end method stopContribution + + public String getContributionLocation(Class testClass) { + return ContributionLocationHelper.getContributionLocation(testConfiguration.getTestClass()); + } // end method getContributionLocation + + public boolean checkError(String testName, Throwable ex){ + String expectedMessage = expectedErrorMessages.getProperty(testName); + String receivedMessage = ex.getMessage(); + + if (expectedMessage == null){ + System.out.println("Null expected error message for test " + testName); + System.out.println("Please add message to oasis-sca-tests-errors.properties"); + return false; + } + + if (receivedMessage == null){ + System.out.println("Null received error message for test " + testName); + return false; + } + + int messageStart = receivedMessage.indexOf("] - "); + + if (messageStart < 0){ + System.out.println("Message separator not found for test " + testName); + } + + receivedMessage = receivedMessage.substring(messageStart + 4); + + if (receivedMessage.startsWith(expectedMessage)){ + return true; + } else { + return false; + } + } + +} // end class TuscanyRuntimeBridge -- cgit v1.2.3