You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2010/02/24 01:13:15 UTC

svn commit: r915607 - in /tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes: ./ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/tuscany/ src/main/java/org/apache/tuscany/sca/ src/main/java/org/apache/tuscany/sca/itest/ src...

Author: rfeng
Date: Wed Feb 24 00:13:14 2010
New Revision: 915607

URL: http://svn.apache.org/viewvc?rev=915607&view=rev
Log:
Add an itest to cover various combinations of local/remote interfaces, pbv/pbr, node factories/nodes, classloaders

Added:
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/
      - copied from r910277, tuscany/sca-java-2.x/trunk/itest/nodes/one-jvm-tribes/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Client.java   (with props)
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/ClientImpl.java   (with props)
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Customer.java   (with props)
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Local.java   (with props)
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/LocalServiceImpl.java   (with props)
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Remote.java   (with props)
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/RemoteServiceImpl.java   (with props)
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/apache/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/apache/tuscany/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/apache/tuscany/sca/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/apache/tuscany/sca/itest/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/apache/tuscany/sca/itest/bindingsca/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/apache/tuscany/sca/itest/bindingsca/Client.composite   (with props)
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/apache/tuscany/sca/itest/bindingsca/Service.composite   (with props)
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/BindingSCATestCase.java   (with props)
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ClientNodeSharedCustomerTestCase.java   (with props)
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ClientNodeSharedLocalTestCase.java   (with props)
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ServiceNode.java   (with props)
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/TestCaseRunner.java   (with props)
Removed:
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/itest/
Modified:
    tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/pom.xml

Modified: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/pom.xml?rev=915607&r1=910277&r2=915607&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/pom.xml (original)
+++ tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/pom.xml Wed Feb 24 00:13:14 2010
@@ -25,30 +25,31 @@
         <version>2.0-SNAPSHOT</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
-    <artifactId>itest-nodes-one-jvm-tribes</artifactId>
-    <name>Apache Tuscany SCA iTest Nodes One JVM Using Tribes Registry</name>
+    <artifactId>itest-nodes-binding-sca-tribes</artifactId>
+    <name>Apache Tuscany SCA iTest Nodes binding.sca Using Tribes Registry</name>
 
     <dependencies>
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>itest-nodes-helloworld-iface</artifactId>
+            <artifactId>tuscany-sca-client-impl</artifactId>
             <version>2.0-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>tuscany-sca-client-impl</artifactId>
+            <artifactId>tuscany-endpoint-tribes</artifactId>
             <version>2.0-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>tuscany-endpoint-tribes</artifactId>
+            <artifactId>tuscany-binding-sca-axis2-runtime</artifactId>
             <version>2.0-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>tuscany-binding-sca-runtime-rmi</artifactId>
+            <artifactId>tuscany-host-jetty</artifactId>
             <version>2.0-SNAPSHOT</version>
-        </dependency>
+            <scope>runtime</scope>
+        </dependency>        
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-node-impl</artifactId>

Added: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Client.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Client.java?rev=915607&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Client.java (added)
+++ tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Client.java Wed Feb 24 00:13:14 2010
@@ -0,0 +1,29 @@
+/*
+ * 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.itest.bindingsca;
+
+/**
+ * 
+ */
+public interface Client {
+    String getName(String id);
+
+    String create(String name);
+}

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Client.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Client.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/ClientImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/ClientImpl.java?rev=915607&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/ClientImpl.java (added)
+++ tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/ClientImpl.java Wed Feb 24 00:13:14 2010
@@ -0,0 +1,48 @@
+/*
+ * 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.itest.bindingsca;
+
+import org.oasisopen.sca.annotation.Reference;
+import org.oasisopen.sca.annotation.Service;
+
+/**
+ * 
+ */
+@Service(Client.class)
+public class ClientImpl implements Client {
+    @Reference
+    protected Local local;
+
+    @Reference
+    protected Remote remote;
+
+    public String getName(String id) {
+        Customer customer = remote.getCustomer(id);
+        customer.dump("Client.getName()");
+        return local.getName(customer);
+    }
+
+    public String create(String name) {
+        String id = remote.generateId();
+        Customer customer = remote.createCustomer(id, name);
+        customer.dump("Client.create()");
+        return remote.getId(customer);
+    }
+}

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/ClientImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/ClientImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Customer.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Customer.java?rev=915607&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Customer.java (added)
+++ tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Customer.java Wed Feb 24 00:13:14 2010
@@ -0,0 +1,70 @@
+/*
+ * 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.itest.bindingsca;
+
+/**
+ * 
+ */
+public class Customer {
+    private String id;
+    private String name;
+
+    public Customer() {
+    }
+
+    /**
+     * @param id
+     * @param name
+     */
+    public Customer(String id, String name) {
+        super();
+        this.id = id;
+        this.name = name;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public String toString() {
+        return "Customer [id=" + id + ", name=" + name + "]";
+    }
+
+    public void dump(String prefix) {
+        System.out.print(prefix);
+        System.out.print(": ");
+        System.out.print(toString());
+        System.out.println(" @" + System.identityHashCode(this));
+        System.out.println(getClass().getClassLoader());
+    }
+}

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Customer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Customer.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Local.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Local.java?rev=915607&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Local.java (added)
+++ tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Local.java Wed Feb 24 00:13:14 2010
@@ -0,0 +1,27 @@
+/*
+ * 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.itest.bindingsca;
+
+/**
+ * 
+ */
+public interface Local {
+    String getName(Customer customer);
+}

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Local.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Local.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/LocalServiceImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/LocalServiceImpl.java?rev=915607&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/LocalServiceImpl.java (added)
+++ tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/LocalServiceImpl.java Wed Feb 24 00:13:14 2010
@@ -0,0 +1,38 @@
+/*
+ * 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.itest.bindingsca;
+
+import org.oasisopen.sca.annotation.Service;
+
+/**
+ * 
+ */
+@Service(Local.class)
+public class LocalServiceImpl implements Local {
+
+    public String getName(Customer customer) {
+        if (customer == null) {
+            return null;
+        }
+        customer.dump("Local.getName()");
+        return customer.getName();
+    }
+
+}

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/LocalServiceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/LocalServiceImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Remote.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Remote.java?rev=915607&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Remote.java (added)
+++ tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Remote.java Wed Feb 24 00:13:14 2010
@@ -0,0 +1,36 @@
+/*
+ * 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.itest.bindingsca;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * 
+ */
+@Remotable
+public interface Remote {
+    String generateId();
+
+    String getId(Customer customer);
+
+    Customer getCustomer(String id);
+
+    Customer createCustomer(String id, String name);
+}

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Remote.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Remote.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/RemoteServiceImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/RemoteServiceImpl.java?rev=915607&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/RemoteServiceImpl.java (added)
+++ tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/RemoteServiceImpl.java Wed Feb 24 00:13:14 2010
@@ -0,0 +1,61 @@
+/*
+ * 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.itest.bindingsca;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.oasisopen.sca.annotation.AllowsPassByReference;
+import org.oasisopen.sca.annotation.Scope;
+import org.oasisopen.sca.annotation.Service;
+
+/**
+ * 
+ */
+@Service(Remote.class)
+@Scope("COMPOSITE")
+public class RemoteServiceImpl implements Remote {
+    private Map<String, Customer> customers = new HashMap<String, Customer>();
+
+    public String generateId() {
+        return UUID.randomUUID().toString();
+    }
+
+    @AllowsPassByReference
+    public String getId(Customer customer) {
+        customer.dump("Remote.getId()");
+        return customer.getId();
+    }
+
+    public Customer getCustomer(String id) {
+        Customer customer = customers.get(id);
+        customer.dump("Remote.getCustomer()");
+        return customer;
+    }
+
+    public Customer createCustomer(String id, String name) {
+        Customer customer = new Customer(id, name);
+        customer.dump("Remote.createCustomer()");
+        customers.put(id, customer);
+        return customer;
+    }
+
+}

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/RemoteServiceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/RemoteServiceImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/apache/tuscany/sca/itest/bindingsca/Client.composite
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/apache/tuscany/sca/itest/bindingsca/Client.composite?rev=915607&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/apache/tuscany/sca/itest/bindingsca/Client.composite (added)
+++ tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/apache/tuscany/sca/itest/bindingsca/Client.composite Wed Feb 24 00:13:14 2010
@@ -0,0 +1,30 @@
+<?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
+    * 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.
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" 
+    targetNamespace="http://client"
+    name="Client">
+
+    <component name="ClientComponent">
+        <implementation.java class="org.apache.tuscany.sca.itest.bindingsca.ClientImpl" />
+        <reference name="local" target="LocalComponent" />
+        <reference name="remote" target="RemoteComponent" />
+    </component>
+
+
+</composite>
\ No newline at end of file

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/apache/tuscany/sca/itest/bindingsca/Client.composite
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/apache/tuscany/sca/itest/bindingsca/Client.composite
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/apache/tuscany/sca/itest/bindingsca/Service.composite
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/apache/tuscany/sca/itest/bindingsca/Service.composite?rev=915607&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/apache/tuscany/sca/itest/bindingsca/Service.composite (added)
+++ tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/apache/tuscany/sca/itest/bindingsca/Service.composite Wed Feb 24 00:13:14 2010
@@ -0,0 +1,31 @@
+<?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
+    * 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.
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" 
+    targetNamespace="http://service"
+    name="Service">
+
+    <component name="LocalComponent">
+        <implementation.java class="org.apache.tuscany.sca.itest.bindingsca.LocalServiceImpl" />
+    </component>
+
+    <component name="RemoteComponent">
+        <implementation.java class="org.apache.tuscany.sca.itest.bindingsca.RemoteServiceImpl" />
+    </component>
+    
+</composite>
\ No newline at end of file

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/apache/tuscany/sca/itest/bindingsca/Service.composite
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/main/resources/org/apache/tuscany/sca/itest/bindingsca/Service.composite
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/BindingSCATestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/BindingSCATestCase.java?rev=915607&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/BindingSCATestCase.java (added)
+++ tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/BindingSCATestCase.java Wed Feb 24 00:13:14 2010
@@ -0,0 +1,134 @@
+/*
+ * 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.itest.bindingsca;
+
+import java.io.File;
+
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
+import org.junit.Assert;
+import org.junit.Test;
+import org.oasisopen.sca.SCARuntimeException;
+
+/**
+ * Test binding.sca in the same classloader
+ */
+public class BindingSCATestCase {
+    private static final String DOMAIN_URI = "my-domain";
+    private static final String REGISTRY_URI = "tribes://228.0.0.100:50000";
+    private static final String PKG = "org/apache/tuscany/sca/itest/bindingsca/";
+    private static final String CLIENT = "Client.composite";
+    private static final String SERVICE = "Service.composite";
+    private static final String ROOT = new File("target/classes/" + PKG).toURI().toString();
+
+    /**
+     * One NodeFactory and two nodes
+     */
+    @Test
+    public void testOneFactoryTwoNodes() {
+        NodeFactory factory1 = NodeFactory.getInstance();
+        Node node1 = createClientNode(factory1);
+        Node node2 = createServiceNode(factory1);
+        node1.start();
+        node2.start();
+        runClient(node1);
+        node2.stop();
+        node1.stop();
+        factory1.destroy();
+    }
+
+    /**
+     * Create the service node
+     * @param factory
+     * @return
+     */
+    static Node createServiceNode(NodeFactory factory) {
+        NodeConfiguration config2 =
+            factory.createNodeConfiguration().setDomainURI(DOMAIN_URI).setURI("node2").addContribution("c2", ROOT)
+                .addDeploymentComposite("c2", SERVICE).setDomainRegistryURI(REGISTRY_URI);
+        Node node2 = factory.createNode(config2);
+        return node2;
+    }
+
+    /**
+     * Create the client node
+     * @param factory
+     * @return
+     */
+    static Node createClientNode(NodeFactory factory) {
+        NodeConfiguration config1 =
+            factory.createNodeConfiguration().setDomainURI(DOMAIN_URI).setURI("node1").addContribution("c1", ROOT)
+                .addDeploymentComposite("c1", CLIENT).setDomainRegistryURI(REGISTRY_URI);
+        Node node1 = factory.createNode(config1);
+        return node1;
+    }
+
+    /**
+     * Two node factories and two nodes
+     */
+    @Test
+    public void testTwoFactoriesTwoNodes() {
+        NodeFactory factory1 = NodeFactory.newInstance();
+        Node node1 = createClientNode(factory1);
+        NodeFactory factory2 = NodeFactory.newInstance();
+        Node node2 = createServiceNode(factory2);
+        node1.start();
+        node2.start();
+        try {
+            runClient(node1);
+            Assert.fail("SCARuntimeException should have been thrown.");
+        } catch (SCARuntimeException e) {
+            // ignore
+        }
+        node2.stop();
+        node1.stop();
+        factory2.destroy();
+        factory1.destroy();
+    }
+
+    /**
+     * Run the client
+     * @param node
+     */
+    static void runClient(Node node) {
+        Client client = node.getService(Client.class, "ClientComponent/Client");
+        String id = client.create("Ray");
+        Assert.assertEquals("Ray", client.getName(id));
+    }
+
+    /**
+     * One node factory and one node for both composites
+     */
+    @Test
+    public void testOneFactoryOneNode() {
+        NodeFactory factory = NodeFactory.getInstance();
+        NodeConfiguration config1 =
+            factory.createNodeConfiguration().setDomainURI(DOMAIN_URI).setURI("node1").addContribution("c1", ROOT)
+                .addDeploymentComposite("c1", CLIENT).addDeploymentComposite("c1", SERVICE);
+
+        Node node1 = factory.createNode(config1);
+        node1.start();
+        runClient(node1);
+        node1.stop();
+        factory.destroy();
+    }
+
+}

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/BindingSCATestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/BindingSCATestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ClientNodeSharedCustomerTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ClientNodeSharedCustomerTestCase.java?rev=915607&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ClientNodeSharedCustomerTestCase.java (added)
+++ tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ClientNodeSharedCustomerTestCase.java Wed Feb 24 00:13:14 2010
@@ -0,0 +1,58 @@
+/*
+ * 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.itest.bindingsca;
+
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * This shows how to test the Calculator service component.
+ */
+public class ClientNodeSharedCustomerTestCase {
+    private static Node clientNode;
+    private static TestCaseRunner runner;
+
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        runner = new TestCaseRunner(ServiceNode.class, Remote.class.getName(), RemoteServiceImpl.class.getName());
+        runner.beforeClass();
+        NodeFactory factory = NodeFactory.getInstance();
+        clientNode = BindingSCATestCase.createClientNode(factory).start();
+        Thread.sleep(1000);
+    }
+
+    @Test
+    public void testClient() throws Exception {
+        BindingSCATestCase.runClient(clientNode);
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() throws Exception {
+        if (clientNode != null) {
+            clientNode.stop();
+        }
+        if (runner != null) {
+            runner.afterClass();
+        }
+    }
+}

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ClientNodeSharedCustomerTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ClientNodeSharedCustomerTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ClientNodeSharedLocalTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ClientNodeSharedLocalTestCase.java?rev=915607&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ClientNodeSharedLocalTestCase.java (added)
+++ tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ClientNodeSharedLocalTestCase.java Wed Feb 24 00:13:14 2010
@@ -0,0 +1,60 @@
+/*
+ * 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.itest.bindingsca;
+
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * This shows how to test the Calculator service component.
+ */
+public class ClientNodeSharedLocalTestCase {
+    private static Node clientNode;
+    private static TestCaseRunner runner;
+
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        runner =
+            new TestCaseRunner(ServiceNode.class, Remote.class.getName(), RemoteServiceImpl.class.getName(),
+                               Customer.class.getName());
+        runner.beforeClass();
+        NodeFactory factory = NodeFactory.getInstance();
+        clientNode = BindingSCATestCase.createClientNode(factory).start();
+        Thread.sleep(1000);
+    }
+
+    @Test
+    public void testClient() throws Exception {
+        BindingSCATestCase.runClient(clientNode);
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() throws Exception {
+        if (clientNode != null) {
+            clientNode.stop();
+        }
+        if (runner != null) {
+            runner.afterClass();
+        }
+    }
+}

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ClientNodeSharedLocalTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ClientNodeSharedLocalTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ServiceNode.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ServiceNode.java?rev=915607&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ServiceNode.java (added)
+++ tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ServiceNode.java Wed Feb 24 00:13:14 2010
@@ -0,0 +1,48 @@
+/*
+ * 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.itest.bindingsca;
+
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ * This shows how to test the Calculator service component.
+ */
+public class ServiceNode {
+    private static Node serviceNode;
+
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        /*        System.setProperty("org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint.enabled",
+                                   "false");
+        */
+        NodeFactory factory = NodeFactory.getInstance();
+        serviceNode = BindingSCATestCase.createServiceNode(factory).start();
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() throws Exception {
+        if (serviceNode != null) {
+            serviceNode.stop();
+        }
+    }
+}

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ServiceNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/ServiceNode.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/TestCaseRunner.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/TestCaseRunner.java?rev=915607&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/TestCaseRunner.java (added)
+++ tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/TestCaseRunner.java Wed Feb 24 00:13:14 2010
@@ -0,0 +1,329 @@
+/*
+ * 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.itest.bindingsca;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A helper class that can be used to run an SCA JUnit test case. The test case will run in an isolated class loader.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestCaseRunner {
+
+    private ClassLoader classLoader;
+    private Class<?> testSuiteClass;
+    private Object testSuite;
+    private Class<?> testResultClass;
+    private Class<?> testCaseClass;
+    private Object testCase;
+
+    private Class<?> beforeAnnotation;
+    private Class<?> beforeClassAnnotation;
+    private Class<?> afterAnnotation;
+    private Class<?> afterClassAnnotation;
+    private Class<?> junit4AdapterClass;
+    private Class<?> junit3TestCaseClass;
+
+    /**
+     * Constructs a new TestCase runner.
+     *
+     * @param testClass
+     */
+    public TestCaseRunner(Class<?> testClass, String... isolatedClasses) {
+        try {
+            ClassLoader tccl = setupClassLoader(testClass, isolatedClasses);
+
+            try {
+                // Thread.currentThread().setContextClassLoader(classLoader);
+                // Allow privileged access to set class loader. Requires RuntimePermission
+                // setContextClassLoader in security policy.
+                final ClassLoader finalClassLoader = classLoader;
+                AccessController.doPrivileged(new PrivilegedAction<Object>() {
+                    public Object run() {
+                        Thread.currentThread().setContextClassLoader(finalClassLoader);
+                        return null;
+                    }
+                });
+
+                testCaseClass = Class.forName(testClass.getName(), true, classLoader);
+                testCase = testCaseClass.newInstance();
+                ClassLoader testClassLoader = testCaseClass.getClassLoader();
+
+                junit3TestCaseClass = Class.forName("junit.framework.TestCase", true, testClassLoader);
+
+                testSuiteClass = Class.forName("junit.framework.TestSuite", true, testClassLoader);
+                Constructor<?> testSuiteConstructor = testSuiteClass.getConstructor(Class.class);
+                testSuite = testSuiteConstructor.newInstance(testCaseClass);
+
+                testResultClass = Class.forName("junit.framework.TestResult", true, testClassLoader);
+
+                try {
+                    beforeAnnotation = Class.forName("org.junit.Before", true, testClassLoader);
+                    afterAnnotation = Class.forName("org.junit.After", true, testClassLoader);
+                    beforeClassAnnotation = Class.forName("org.junit.BeforeClass", true, testClassLoader);
+                    afterClassAnnotation = Class.forName("org.junit.AfterClass", true, testClassLoader);
+                    junit4AdapterClass = Class.forName("junit.framework.JUnit4TestAdapter", true, testClassLoader);
+                } catch (Exception e) {
+                    // Unexpected
+                    throw new AssertionError(e);
+                }
+            } catch (Throwable e) {
+                e.printStackTrace();
+            } finally {
+                // Thread.currentThread().setContextClassLoader(tccl);
+                // Allow privileged access to set class loader. Requires RuntimePermission
+                // setContextClassLoader in security policy.
+                final ClassLoader finaltccl = tccl;
+                AccessController.doPrivileged(new PrivilegedAction<Object>() {
+                    public Object run() {
+                        Thread.currentThread().setContextClassLoader(finaltccl);
+                        return null;
+                    }
+                });
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private ClassLoader setupClassLoader(Class<?> testClass, String... isolatedClasses) {
+        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+        classLoader = testClass.getClassLoader();
+        if (classLoader instanceof URLClassLoader) {
+            URL[] urls = ((URLClassLoader)classLoader).getURLs();
+            classLoader = new ClassLoaderImpl(urls, classLoader, isolatedClasses);
+        } else if (classLoader == tccl || classLoader.getParent() == tccl) {
+            classLoader = new URLClassLoader(new URL[0], classLoader);
+        } else {
+            classLoader = tccl;
+        }
+        return tccl;
+    }
+
+    /**
+     * Run the test case
+     */
+    public void run() {
+        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+        try {
+            // Thread.currentThread().setContextClassLoader(classLoader);
+            // Allow privileged access to set class loader. Requires RuntimePermission
+            // setContextClassLoader in security policy.
+            final ClassLoader finalClassLoader = classLoader;
+            AccessController.doPrivileged(new PrivilegedAction<Object>() {
+                public Object run() {
+                    Thread.currentThread().setContextClassLoader(finalClassLoader);
+                    return null;
+                }
+            });
+
+            if (junit3TestCaseClass.isAssignableFrom(testCaseClass)) {
+                Object testResult = testResultClass.newInstance();
+                Method runMethod = testSuiteClass.getMethod("run", testResultClass);
+                runMethod.invoke(testSuite, testResult);
+            } else {
+                Object junit4Adapter = junit4AdapterClass.getConstructor(Class.class).newInstance(testCaseClass);
+                Object testResult = testResultClass.newInstance();
+                Method runMethod = junit4AdapterClass.getMethod("run", testResultClass);
+                runMethod.invoke(junit4Adapter, testResult);
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            // Thread.currentThread().setContextClassLoader(tccl);
+            // Allow privileged access to set class loader. Requires RuntimePermission
+            // setContextClassLoader in security policy.
+            final ClassLoader finaltccl = tccl;
+            AccessController.doPrivileged(new PrivilegedAction<Object>() {
+                public Object run() {
+                    Thread.currentThread().setContextClassLoader(finaltccl);
+                    return null;
+                }
+            });
+        }
+    }
+
+    /**
+     * Invoke the setUp method
+     */
+    public void setUp() {
+        execute("setUp");
+    }
+
+    /**
+     * Invoke the before methods
+     */
+    public void before() {
+        execute(beforeAnnotation);
+    }
+
+    /**
+     * Invoke the beforeClass methods
+     */
+    public void beforeClass() {
+        execute(beforeClassAnnotation);
+    }
+
+    /**
+     * Invoke the tearDown method
+     */
+    public void tearDown() {
+        execute("tearDown");
+    }
+
+    /**
+     * Invoke the after methods
+     */
+    public void after() {
+        execute(afterAnnotation);
+    }
+
+    /**
+     * Invoke the afterClass methods
+     */
+    public void afterClass() {
+        execute(afterClassAnnotation);
+    }
+
+    /**
+     * Invoke the specified test method.
+     */
+    public void run(String methodName) {
+        execute(methodName);
+    }
+
+    /**
+     * Invoke the methods annotated with the specified annotation.
+     */
+    private void execute(Class<?> annotationClass) {
+        if (annotationClass == null) {
+            throw new RuntimeException(new NoSuchMethodException());
+        }
+        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+        try {
+            // Thread.currentThread().setContextClassLoader(classLoader);
+            // Allow privileged access to set class loader. Requires RuntimePermission
+            // setContextClassLoader in security policy.
+            final ClassLoader finalClassLoader = classLoader;
+            AccessController.doPrivileged(new PrivilegedAction<Object>() {
+                public Object run() {
+                    Thread.currentThread().setContextClassLoader(finalClassLoader);
+                    return null;
+                }
+            });
+
+            for (Method method : testCaseClass.getDeclaredMethods()) {
+                for (Annotation annotation : method.getAnnotations()) {
+                    if (annotation.annotationType() == annotationClass) {
+                        method.invoke(testCase);
+                    }
+                }
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            // Thread.currentThread().setContextClassLoader(tccl);
+            // Allow privileged access to set class loader. Requires RuntimePermission
+            // setContextClassLoader in security policy.
+            final ClassLoader finaltccl = tccl;
+            AccessController.doPrivileged(new PrivilegedAction<Object>() {
+                public Object run() {
+                    Thread.currentThread().setContextClassLoader(finaltccl);
+                    return null;
+                }
+            });
+        }
+    }
+
+    /**
+     * Invoke the specified method
+     */
+    private void execute(String methodName) {
+        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+        try {
+            // Thread.currentThread().setContextClassLoader(classLoader);
+            // Allow privileged access to set class loader. Requires RuntimePermission
+            // setContextClassLoader in security policy.
+            final ClassLoader finalClassLoader = classLoader;
+            AccessController.doPrivileged(new PrivilegedAction<Object>() {
+                public Object run() {
+                    Thread.currentThread().setContextClassLoader(finalClassLoader);
+                    return null;
+                }
+            });
+            Method setUpMethod = testCaseClass.getDeclaredMethod(methodName);
+            setUpMethod.setAccessible(true);
+            setUpMethod.invoke(testCase);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            // Thread.currentThread().setContextClassLoader(tccl);
+            // Allow privileged access to set class loader. Requires RuntimePermission
+            // setContextClassLoader in security policy.
+            final ClassLoader finaltccl = tccl;
+            AccessController.doPrivileged(new PrivilegedAction<Object>() {
+                public Object run() {
+                    Thread.currentThread().setContextClassLoader(finaltccl);
+                    return null;
+                }
+            });
+        }
+    }
+
+    public static class ClassLoaderImpl extends URLClassLoader {
+        private Set<String> isolatedClasses = new HashSet<String>();
+
+        /**
+         * @param urls
+         * @param parent
+         */
+        public ClassLoaderImpl(URL[] urls, ClassLoader parent, String... sharedClasses) {
+            super(urls, parent);
+            this.isolatedClasses.addAll(Arrays.asList(sharedClasses));
+        }
+
+        @Override
+        protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
+            if (!isolatedClasses.contains(name)) {
+                return super.loadClass(name, resolve);
+            } else {
+                Class<?> cls = findLoadedClass(name);
+                if (cls == null) {
+                    cls = findClass(name);
+                }
+                if (resolve) {
+                    resolveClass(cls);
+                }
+                return cls;
+            }
+        }
+
+    }
+
+}

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/TestCaseRunner.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/itest/nodes/binding-sca-tribes/src/test/java/org/apache/tuscany/sca/itest/bindingsca/TestCaseRunner.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date