diff options
Diffstat (limited to '')
5 files changed, 607 insertions, 0 deletions
diff --git a/java/sca/otest/newlayout/tuscany-java-caa-test-runner/pom.xml b/java/sca/otest/newlayout/tuscany-java-caa-test-runner/pom.xml new file mode 100644 index 0000000000..ec18a3cd2e --- /dev/null +++ b/java/sca/otest/newlayout/tuscany-java-caa-test-runner/pom.xml @@ -0,0 +1,190 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-sca</artifactId> + <version>2.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>tuscany-otests-sca-j-caa-tests</artifactId> + <name>Apache Tuscany SCA Specification Tests for SCA-J CAA</name> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-node-impl</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-node-impl-osgi</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-node-launcher-equinox</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-implementation-java-runtime</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-ws-axis2</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-jetty</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <!-- dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-otests-asm-General</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-otests-asm-General_Java</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency --> + + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.5</version> + </dependency> + + <dependency> + <groupId>com.sun.xml.ws</groupId> + <artifactId>jaxws-rt</artifactId> + <version>2.1.7</version> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.5</version> + <scope>test</scope> + </dependency> + + </dependencies> + + + + <build> + <finalName>${artifactId}</finalName> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-antrun-plugin</artifactId> + <version>1.3</version> + + <dependencies> + <dependency> + <groupId>ant</groupId> + <artifactId>ant-trax</artifactId> + <version>1.6.5</version> + </dependency> + </dependencies> + + <executions> + <execution> + <id>copy-files-from-svn</id> + <phase>generate-resources</phase> + <goals> + <goal>run</goal> + </goals> + <configuration> + <tasks> + <ant antfile="../build.xml"> + <property name="from.dir" value="../sca-java-caa/Test_Client_JavaCAA/src/main/resources"/> + <property name="to.dir" value="src/main/resources"/> + <target name="copyResourceDir"/> + </ant> + <ant antfile="../build.xml"> + <property name="from.dir" value="../sca-java-caa/Test_Client_JavaCAA/src/main/java"/> + <property name="to.dir" value="src/test/java"/> + <target name="copySourceDir"/> + </ant> + <ant antfile="../build.xml"> + <property name="from.dir" value="../sca-assembly/Test_Client/src/main/java/testClient"/> + <property name="to.dir" value="src/test/java/testClient"/> + <target name="copySourceDir"/> + </ant> + <ant antfile="../build.xml"> + <property name="from.file" value="../sca-assembly/Test_Client/src/main/java/client/BaseJAXWSTestCase.java"/> + <property name="to.file" value="src/test/java/client/BaseJAXWSTestCase.java"/> + <target name="copyFile"/> + </ant> + <ant antfile="../build.xml"> + <property name="from.file" value="../sca-assembly/Test_Client/src/main/java/client/RuntimeBridge.java"/> + <property name="to.file" value="src/test/java/client/RuntimeBridge.java"/> + <target name="copyFile"/> + </ant> + <ant antfile="../build.xml"> + <property name="from.file" value="../sca-assembly/Test_Client/src/main/java/client/TestConfiguration.java"/> + <property name="to.file" value="src/test/java/client/TestConfiguration.java"/> + <target name="copyFile"/> + </ant> + <ant antfile="../build.xml"> + <property name="from.file" value="../sca-assembly/Test_Client/src/main/java/client/TuscanyRuntimeBridge.java"/> + <property name="to.file" value="src/test/java/client/TuscanyRuntimeBridge.java"/> + <target name="copyFile"/> + </ant> + </tasks> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <version>1.3</version> + <executions> + <execution> + <id>add-test-source</id> + <phase>generate-sources</phase> + <goals> + <goal>add-test-source</goal> + </goals> + <configuration> + <sources> + <source>src/test/tjava</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/resources/oasis-sca-tests.properties b/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/resources/oasis-sca-tests.properties new file mode 100644 index 0000000000..9bd40612ee --- /dev/null +++ b/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/resources/oasis-sca-tests.properties @@ -0,0 +1,30 @@ +# 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=POJO + +# The class to use as the Runtime Bridge for the SCA runtime under test +#org.oasis.sca.tests.assembly.runtime_bridge=org.apache.tuscany.sca.otest.TuscanyOSGiRuntimeBridge +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-java-caa/%1/target/%1.zip + diff --git a/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/resources/tuscany-oasis-sca-tests-errors.properties b/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/resources/tuscany-oasis-sca-tests-errors.properties new file mode 100644 index 0000000000..b830911614 --- /dev/null +++ b/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/resources/tuscany-oasis-sca-tests-errors.properties @@ -0,0 +1,52 @@ +# 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_4002=org.oasisopen.sca.ServiceRuntimeException: [Composite: {http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: TestComponent1] - Duplicate service name: Component = TestComponent1 Service = Service1 +ASM_4003=org.oasisopen.sca.ServiceRuntimeException: [Composite: {http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: TestComponent1] - Duplicate reference name: Component = TestComponent1 Reference = Reference1 +ASM_4004=org.oasisopen.sca.ServiceRuntimeException: [Composite: {http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: TestComponent1] - Duplicate property name: Component = TestComponent1 Property = propertyName +ASM_4007=org.apache.tuscany.sca.contribution.processor.ContributionReadException: Error: property has both @type and @element attribute values - propertyName +ASM_4008=org.oasisopen.sca.ServiceRuntimeException: [Composite: {http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: TestComponent1] - [ASM_4008] No value configured on a mustSupply property: Component = TestComponent1 Property = propertyName +ASM_5004=org.oasisopen.sca.ServiceRuntimeException: [Composite: {http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: TestClient] - Too many targets on reference: reference1 +ASM_5005=org.oasisopen.sca.ServiceRuntimeException: [Composite: {http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: TestComponent1] - Duplicate service name: Component = TestComponent1 Service = Service1 +ASM_5006=org.oasisopen.sca.ServiceRuntimeException: [Composite: {http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: TestComponent1] - Component type service not found for component service (missing @Remotable annotation?): Component = TestComponent1 Service = InvalidName +ASM_5007=org.oasisopen.sca.ServiceRuntimeException: [Composite: {http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: TestComponent1] - Duplicate reference name: Component = TestComponent1 Reference = Reference1 +ASM_5008=org.oasisopen.sca.ServiceRuntimeException: [Composite: {http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: TestComponent1] - Component type reference not found for component reference: Component = TestComponent1 Reference = InvalidName +ASM_5009=org.oasisopen.sca.ServiceRuntimeException: [Composite: {http://docs.oasis-open.org/ns/opencsa/sca/200903}] - Duplicate component name: Composite = {http://docs.oasis-open.org/ns/opencsa/sca/200903} Component = TestComponent1 +ASM_5010=org.oasisopen.sca.ServiceRuntimeException: [Composite: {http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: TestComponent1] - Component service interface incompatible with implementation service interface: Component = TestComponent1 Service = Service1 +ASM_5014=org.oasisopen.sca.ServiceRuntimeException: [Composite: {http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: TestComponent1] - Component reference multiplicity incompatible with reference multiplicity: Component = TestComponent1 Reference = Reference1 +ASM_5023=OASIS issue opened +ASM_5024=org.oasisopen.sca.ServiceRuntimeException: [Composite: {http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: TestComponent1, Reference: Reference1] - Composite {http://docs.oasis-open.org/ns/opencsa/sca/200903} Component TestComponent1 Reference Reference1 must not specify endpoints using both target attribute and with binding uri attribute +ASM_5027=org.oasisopen.sca.ServiceRuntimeException: [Composite: {http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: TestComponent1] - Duplicate component property name: Component = TestComponent1 Property = serviceName +ASM_5028=org.oasisopen.sca.ServiceRuntimeException: [Composite: {http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: TestComponent1] - Property not found for component property: Component = TestComponent1 Property = randomName +ASM_5029=org.oasisopen.sca.ServiceRuntimeException: [Composite: {http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: TestComponent1] - The property component TestComponent1 property complexType has many values but its "many" attribute is set to false +ASM_5030=org.oasisopen.sca.ServiceRuntimeException: [Contribution: ASM_5030, Artifact: Test_ASM_5030.composite] - ASM50033: value attribute exists for the property element +ASM_5035=org.apache.tuscany.sca.contribution.processor.ContributionReadException: Error: property has both @type and @element attribute values - complexType +ASM_5036=org.oasisopen.sca.ServiceRuntimeException: [Composite: {http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: TEST_ASM_5036Component1] - [ASM_5036] The property component TEST_ASM_5036Component1 property complexType has XSD type {http://docs.oasis-open.org/ns/opencsa/scatests/200903}ComplexType2 while its component type property has the XSD type {http://docs.oasis-open.org/ns/opencsa/scatests/200903}ComplexType1 +ASM_5037=org.oasisopen.sca.ServiceRuntimeException: [Composite: {http://docs.oasis-open.org/ns/opencsa/sca/200903}, Component: TEST_ASM_5037Component1] - Property not found for component property: Component = TEST_ASM_5037Component1 Property = bogusName +ASM_6016=Unknown error message - need to determine the correct error message for this testcase +ASM_6020=Unknown error message - need to determine the correct error message for this testcase +ASM_6023=Unknown error message - need to determine the correct error message for this testcase +ASM_6024=org.oasisopen.sca.ServiceRuntimeException: [Composite: http://tuscany.apache.org/xmlns/sca/1.1] - Component implementation not resolved: Component = TestComponent1 Uri = null +ASM_6030=Unknown error message - need to determine the correct error message for this testcase +ASM_7002=Unknown error message - need to determine the correct error message for this testcase +ASM_7003=Unknown error message - need to determine the correct error message for this testcase +ASM_8007=org.oasisopen.sca.ServiceRuntimeException: [Composite: http://tuscany.apache.org/xmlns/sca/1.1] - Component service interface incompatible with implementation service interface: Component = TestComponent2 Service = Service1 +ASM_8008=org.oasisopen.sca.ServiceRuntimeException: [Composite: http://tuscany.apache.org/xmlns/sca/1.1] - Component reference interface incompatible with implementation reference interface: Component = TestComponent1 Reference = Reference1 +ASM_8009=org.oasisopen.sca.ServiceRuntimeException: [Composite: http://tuscany.apache.org/xmlns/sca/1.1] - Component reference interface incompatible with implementation reference interface: Component = TEST_ASM_8009Component1 Reference = Reference1 +ASM_8018=org.oasisopen.sca.ServiceRuntimeException: [Composite: http://tuscany.apache.org/xmlns/sca/1.1] - Component service interface incompatible with implementation service interface: Component = TestClient Service = TestInvocation +ASM_10001=org.oasisopen.sca.ServiceRuntimeException: [] - Duplicate intent {http://docs.oasis-open.org/ns/opencsa/scatests/200903}Fred found in domain + diff --git a/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyOSGiRuntimeBridge.java b/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyOSGiRuntimeBridge.java new file mode 100644 index 0000000000..afea19fe0b --- /dev/null +++ b/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyOSGiRuntimeBridge.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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +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; + protected Properties expectedErrorMessages; + + public TuscanyOSGiRuntimeBridge() { + // read test error mapping + expectedErrorMessages = new Properties(); + try { + InputStream propertiesStream = this.getClass().getResourceAsStream("/tuscany-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 = 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 void checkError(String testName, Throwable ex) throws Throwable { + String expectedMessage = expectedErrorMessages.getProperty(testName); + String receivedMessage = ex.getMessage(); + + if (expectedMessage == null){ + fail("Null expected error message for test " + testName + + "Please add message to oasis-sca-tests-errors.properties"); + } + + if (receivedMessage == null){ + fail("Null received error message for test " + testName); + } + + int messageStart = receivedMessage.indexOf("] - "); + + if (messageStart < 0){ + fail("Message separator not found for test " + testName); + } + + receivedMessage = receivedMessage.substring(messageStart + 4); + + assertEquals( expectedMessage, receivedMessage ); + + return; + } + +} // end class TuscanyRuntimeBridge diff --git a/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyRuntimeBridge.java b/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyRuntimeBridge.java new file mode 100644 index 0000000000..8ceb44e976 --- /dev/null +++ b/java/sca/otest/newlayout/tuscany-java-caa-test-runner/src/test/tjava/org/apache/tuscany/sca/otest/TuscanyRuntimeBridge.java @@ -0,0 +1,171 @@ +/* + * 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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +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 org.apache.tuscany.sca.node.impl.NodeImpl; + +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("/tuscany-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(); + + // For debugging + // print out the composites that have been read in success cases + // System.out.println(((NodeImpl)node).dumpDomainComposite()); + } 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 void checkError(String testName, Throwable ex) throws Throwable { + + String expectedMessage = expectedErrorMessages.getProperty(testName); + String receivedMessage = ex.getMessage(); + + if (expectedMessage == null){ + 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 + + // 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 + + assertEquals( expectedMessage, receivedMessage ); + + return; + + } + +} // end class TuscanyRuntimeBridge |