You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by mc...@apache.org on 2008/04/09 13:23:32 UTC

svn commit: r646273 - in /incubator/tuscany/java/sca/itest/serialization: ./ src/ src/main/ src/main/java/ 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/tus...

Author: mcombellack
Date: Wed Apr  9 04:23:20 2008
New Revision: 646273

URL: http://svn.apache.org/viewvc?rev=646273&view=rev
Log:
TUSCANY-2213 - Added iTests for Serializing ServiceReferences and CallableReferences

Added:
    incubator/tuscany/java/sca/itest/serialization/   (with props)
    incubator/tuscany/java/sca/itest/serialization/pom.xml   (with props)
    incubator/tuscany/java/sca/itest/serialization/src/
    incubator/tuscany/java/sca/itest/serialization/src/main/
    incubator/tuscany/java/sca/itest/serialization/src/main/java/
    incubator/tuscany/java/sca/itest/serialization/src/main/java/org/
    incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/
    incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/
    incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/
    incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/
    incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/
    incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/ConversationalService.java
    incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/ConversationalServiceImpl.java
    incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/SCAManagedClient.java
    incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/SCAManagedClientImpl.java
    incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/StatelessService.java
    incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/StatelessServiceCallback.java
    incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/StatelessServiceImpl.java
    incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/utils/
    incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/utils/ServiceReferenceUtils.java
    incubator/tuscany/java/sca/itest/serialization/src/main/resources/
    incubator/tuscany/java/sca/itest/serialization/src/main/resources/ServiceReferenceSerializationTest.composite
    incubator/tuscany/java/sca/itest/serialization/src/test/
    incubator/tuscany/java/sca/itest/serialization/src/test/java/
    incubator/tuscany/java/sca/itest/serialization/src/test/java/org/
    incubator/tuscany/java/sca/itest/serialization/src/test/java/org/apache/
    incubator/tuscany/java/sca/itest/serialization/src/test/java/org/apache/tuscany/
    incubator/tuscany/java/sca/itest/serialization/src/test/java/org/apache/tuscany/sca/
    incubator/tuscany/java/sca/itest/serialization/src/test/java/org/apache/tuscany/sca/itest/
    incubator/tuscany/java/sca/itest/serialization/src/test/java/org/apache/tuscany/sca/itest/servicereference/
    incubator/tuscany/java/sca/itest/serialization/src/test/java/org/apache/tuscany/sca/itest/servicereference/SerializeServiceReferenceTestCase.java

Propchange: incubator/tuscany/java/sca/itest/serialization/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Apr  9 04:23:20 2008
@@ -0,0 +1,5 @@
+target
+.project
+.classpath
+.settings
+

Added: incubator/tuscany/java/sca/itest/serialization/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/serialization/pom.xml?rev=646273&view=auto
==============================================================================
--- incubator/tuscany/java/sca/itest/serialization/pom.xml (added)
+++ incubator/tuscany/java/sca/itest/serialization/pom.xml Wed Apr  9 04:23:20 2008
@@ -0,0 +1,81 @@
+<?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-itest</artifactId>
+        <version>2.0-incubating-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <artifactId>itest-serialization</artifactId>
+    <name>Apache Tuscany SCA Serialization Integration Tests</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-host-embedded</artifactId>
+            <version>2.0-incubating-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-implementation-java-runtime</artifactId>
+            <version>2.0-incubating-SNAPSHOT</version>
+            <scope>runtime</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-node-impl</artifactId>
+            <version>2.0-incubating-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-domain-impl</artifactId>
+            <version>2.0-incubating-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>        
+        
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-host-tomcat</artifactId>
+            <version>2.0-incubating-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>  
+        
+                      
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-binding-ws-axis2</artifactId>
+            <version>2.0-incubating-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>         
+        
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-binding-sca-axis2</artifactId>
+            <version>2.0-incubating-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>

Propchange: incubator/tuscany/java/sca/itest/serialization/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/itest/serialization/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/tuscany/java/sca/itest/serialization/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/ConversationalService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/ConversationalService.java?rev=646273&view=auto
==============================================================================
--- incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/ConversationalService.java (added)
+++ incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/ConversationalService.java Wed Apr  9 04:23:20 2008
@@ -0,0 +1,71 @@
+/*
+ * 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.servicereference;
+
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.annotations.Conversational;
+
+/**
+ * A very simple Conversational Service
+ *
+ * @version $Date$ $Revision$
+ */
+@Conversational
+public interface ConversationalService {
+
+    /**
+     * Default value for the user data
+     * 
+     * @See {@link #getUserData()}
+     * @See {@link #setUserData(String)}
+     */
+    String DEFAULT_USER_DATA = "NOT SET";
+
+    /**
+     * Retrieves the conversation ID for this Service
+     * 
+     * @return The conversation ID for this Service
+     */
+    Object getConversationID();
+
+    /**
+     * Creates a self reference to this Service
+     * 
+     * @return A self reference to this Service
+     */
+    ServiceReference<ConversationalService> createSelfRef();
+
+    /**
+     * Sets some user data on the instance
+     * 
+     * @param a_Data Some data
+     * 
+     * @See {@link #getUserData()}
+     */
+    void setUserData(String a_Data);
+
+    /**
+     * Gets some user data on the instance
+     * 
+     * @return Some data
+     * 
+     * @See {@link #setUserData(String)}
+     */
+    String getUserData();
+}

Added: incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/ConversationalServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/ConversationalServiceImpl.java?rev=646273&view=auto
==============================================================================
--- incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/ConversationalServiceImpl.java (added)
+++ incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/ConversationalServiceImpl.java Wed Apr  9 04:23:20 2008
@@ -0,0 +1,108 @@
+/*
+ * 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.servicereference;
+
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.annotations.Context;
+import org.osoa.sca.annotations.ConversationID;
+import org.osoa.sca.annotations.Scope;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * Simple conversational Service implementation
+ * 
+ * @version $Date$ $Revision$
+ */
+@Service(ConversationalService.class)
+@Scope("CONVERSATION")
+public class ConversationalServiceImpl implements ConversationalService {
+
+    /**
+     * The Conversation ID
+     */
+    private Object m_ConversationID;
+
+    /**
+     * Injected reference to the ComponentContext.
+     */
+    @Context
+    protected ComponentContext m_Ctx;
+
+    /**
+     * Some user data
+     */
+    private String m_UserData = DEFAULT_USER_DATA;
+
+    /**
+     * Constructor
+     */
+    public ConversationalServiceImpl() {
+    }
+
+    /**
+     * Used to inject the Conversation ID
+     * 
+     * @param a_ConversationID the Conversation ID
+     */
+    @ConversationID
+    public void setConversationID(Object a_ConversationID) {
+        m_ConversationID = a_ConversationID;
+    }
+
+    /**
+     * Retrieves the conversation ID for this Service
+     * 
+     * @return The conversation ID for this Service
+     */
+    public Object getConversationID() {
+        return m_ConversationID;
+    }
+
+    /**
+     * Creates a self reference to this Service
+     * 
+     * @return A self reference to this Service
+     */
+    public ServiceReference<ConversationalService> createSelfRef() {
+        return m_Ctx.createSelfReference(ConversationalService.class);
+    }
+
+    /**
+     * Sets some user data on the instance
+     * 
+     * @param a_Data Some data
+     * 
+     * @See {@link #getUserData()}
+     */
+    public void setUserData(String a_Data) {
+        m_UserData = a_Data;
+    }
+
+    /**
+     * Gets some user data on the instance
+     * 
+     * @return Some data
+     * 
+     * @See {@link #setUserData(String)}
+     */
+    public String getUserData() {
+        return m_UserData;
+    }
+}

Added: incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/SCAManagedClient.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/SCAManagedClient.java?rev=646273&view=auto
==============================================================================
--- incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/SCAManagedClient.java (added)
+++ incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/SCAManagedClient.java Wed Apr  9 04:23:20 2008
@@ -0,0 +1,51 @@
+/*
+ * 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.servicereference;
+
+
+/**
+ * This is a test client that is used to test Serializing and Deserializing
+ * ServiceReferences within a SCA Application
+ * 
+ * @version $Date$ $Revision$
+ */
+public interface SCAManagedClient {
+
+    /**
+     * Tests Serializing a Stateless ServiceReference
+     * 
+     * @throws Exception Test failed
+     */
+    void testSerializeStatelessServiceReference() throws Exception;
+
+    /**
+     * Tests Serializing a Conversational ServiceReference
+     * 
+     * @throws Exception Test failed
+     */
+    void testSerializeConversationalServiceReference() throws Exception;
+
+    /**
+     * Tests Serializing a Callback to a Stateless Service as managed
+     * SCA code
+     * 
+     * @throws Exception Test failed
+     */
+    void testSerializeCallbackToStatelessServiceInsideSCA() throws Exception;
+}

Added: incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/SCAManagedClientImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/SCAManagedClientImpl.java?rev=646273&view=auto
==============================================================================
--- incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/SCAManagedClientImpl.java (added)
+++ incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/SCAManagedClientImpl.java Wed Apr  9 04:23:20 2008
@@ -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.itest.servicereference;
+
+import org.apache.tuscany.sca.itest.servicereference.utils.ServiceReferenceUtils;
+import org.junit.Assert;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * This is a test client that is used to test Serializing and Deserializing
+ * ServiceReferences within a SCA Application
+ * 
+ * @version $Date$ $Revision$
+ */
+@Service(SCAManagedClient.class)
+public class SCAManagedClientImpl implements SCAManagedClient, StatelessServiceCallback {
+
+    /**
+     * Injected reference to the StatelessService
+     */
+    @Reference(name = "statelessService")
+    protected ServiceReference<StatelessService> statelessServiceRef;
+
+    /**
+     * Injected reference to the ConversationalService
+     */
+    @Reference(name = "conversationalService")
+    protected ServiceReference<ConversationalService> conversationalServiceRef;
+    
+    /**
+     * Tests Serializing a Stateless ServiceReference
+     * 
+     * @throws Exception Test failed
+     */
+    public void testSerializeStatelessServiceReference() throws Exception {
+        Assert.assertNotNull(statelessServiceRef);
+
+        StatelessService service = statelessServiceRef.getService();
+        service.getCurrentTime();
+        
+        // Serialize the ServiceReference
+        byte[] serializedSR = ServiceReferenceUtils.serialize(statelessServiceRef);
+        Assert.assertNotNull(serializedSR);
+
+        // Deserialize the ServiceReference
+        ServiceReference<?> deserializedSR = ServiceReferenceUtils.deserializeServiceReference(serializedSR);
+        Assert.assertNotNull(deserializedSR);
+        ServiceReference<StatelessService> regotServiceRef = (ServiceReference<StatelessService>) deserializedSR;
+        Assert.assertNotNull(regotServiceRef);
+
+        // Use the ServiceReference to access the Service.
+        StatelessService regotService = regotServiceRef.getService();
+        Assert.assertNotNull(regotService);
+    }
+
+    /**
+     * Tests Serializing a Conversational ServiceReference
+     * 
+     * @throws Exception Test failed
+     */
+    public void testSerializeConversationalServiceReference() throws Exception {
+        Assert.assertNotNull(conversationalServiceRef);
+
+        ConversationalService service = conversationalServiceRef.getService();
+        Object origConvID = service.getConversationID();
+        Assert.assertNotNull(origConvID);
+
+        // Serialize the ServiceReference
+        byte[] serializedSR = ServiceReferenceUtils.serialize(conversationalServiceRef);
+        Assert.assertNotNull(serializedSR);
+
+        // Deserialize the ServiceReference
+        ServiceReference<?> deserializedSR = ServiceReferenceUtils.deserializeServiceReference(serializedSR);
+        Assert.assertNotNull(deserializedSR);
+        ServiceReference<ConversationalService> regotServiceRef = (ServiceReference<ConversationalService>) deserializedSR;
+        Assert.assertNotNull(regotServiceRef);
+
+        // Use the ServiceReference to access the Service.
+        ConversationalService regotService = regotServiceRef.getService();
+        Assert.assertNotNull(regotService);
+        Object regotConvID = regotService.getConversationID();
+        Assert.assertNotNull(regotConvID);
+
+        // Make sure we have the same Conversation ID
+        Assert.assertEquals(origConvID, regotConvID);
+    }
+
+    /**
+     * Simple callback method
+     * 
+     * @param msg The call back message
+     */
+    public void callback(String msg) {
+        System.out.println("Stateless Callback with message " + msg);
+    }
+    
+    /**
+     * Tests Serializing a Callback to a Stateless Service as managed
+     * SCA code
+     * 
+     * @throws Exception Test failed
+     */
+    public void testSerializeCallbackToStatelessServiceInsideSCA() throws Exception {
+        Assert.assertNotNull(statelessServiceRef);
+
+        StatelessService service = statelessServiceRef.getService();
+        String msg = "A message for the callback " + System.currentTimeMillis();
+        service.triggerCallback(msg);
+    }
+}

Added: incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/StatelessService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/StatelessService.java?rev=646273&view=auto
==============================================================================
--- incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/StatelessService.java (added)
+++ incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/StatelessService.java Wed Apr  9 04:23:20 2008
@@ -0,0 +1,46 @@
+/*
+ * 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.servicereference;
+
+import org.osoa.sca.annotations.Callback;
+
+
+/**
+ * A very simple Stateless Service
+ *
+ * @version $Date$ $Revision$
+ */
+@Callback(StatelessServiceCallback.class)
+public interface StatelessService {
+
+    /**
+     * Gets the current time
+     * 
+     * @return The current time
+     */
+    String getCurrentTime();
+
+    /**
+     * Method that triggers the callback
+     * 
+     * @param msg A message to pass with the callback
+     * @throws Exception Test failed
+     */
+    void triggerCallback(String msg) throws Exception;
+}

Added: incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/StatelessServiceCallback.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/StatelessServiceCallback.java?rev=646273&view=auto
==============================================================================
--- incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/StatelessServiceCallback.java (added)
+++ incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/StatelessServiceCallback.java Wed Apr  9 04:23:20 2008
@@ -0,0 +1,34 @@
+/*
+ * 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.servicereference;
+
+/**
+ * This is the callback for the StatelessService
+ *
+ * @version $Date$ $Revision$
+ */
+public interface StatelessServiceCallback {
+
+    /**
+     * Simple callback method
+     * 
+     * @param msg The message for the call back
+     */
+    void callback(String msg);
+}

Added: incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/StatelessServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/StatelessServiceImpl.java?rev=646273&view=auto
==============================================================================
--- incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/StatelessServiceImpl.java (added)
+++ incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/StatelessServiceImpl.java Wed Apr  9 04:23:20 2008
@@ -0,0 +1,82 @@
+/*
+ * 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.servicereference;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.apache.tuscany.sca.itest.servicereference.utils.ServiceReferenceUtils;
+import org.junit.Assert;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * Simple Stateless Service implementation
+ * 
+ * @version $Date$ $Revision$
+ */
+@Service(StatelessService.class)
+public class StatelessServiceImpl implements StatelessService {
+
+    /**
+     * Injected reference to the call back
+     */
+    @Callback
+    protected CallableReference<StatelessServiceCallback> theCallbackRef;
+
+    /**
+     * Constructor
+     */
+    public StatelessServiceImpl() {
+    }
+
+    /**
+     * Gets the current time
+     * 
+     * @return The current time
+     */
+    public String getCurrentTime() {
+        SimpleDateFormat sdf = new SimpleDateFormat();
+        return sdf.format(new Date());
+    }
+
+    /**
+     * Method that triggers the callback
+     * 
+     * @param msg A message to pass with the callback
+     * @throws Exception Test failed
+     */
+    public void triggerCallback(String msg) throws Exception {
+        Assert.assertNotNull(theCallbackRef);
+
+        // Serialize the CallableReference
+        byte[] serializedCR = ServiceReferenceUtils.serialize(theCallbackRef);
+        Assert.assertNotNull(serializedCR);
+
+        // Deserlaize the CallableReference
+        CallableReference<?> cr = ServiceReferenceUtils.deserializeCallableReference(serializedCR);
+        Assert.assertNotNull(cr);
+        CallableReference<StatelessServiceCallback> regotCallbackRef 
+            = (CallableReference<StatelessServiceCallback>) cr;
+
+        // Use the deseralized CallbackReference
+        regotCallbackRef.getService().callback(msg);
+    }
+}

Added: incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/utils/ServiceReferenceUtils.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/utils/ServiceReferenceUtils.java?rev=646273&view=auto
==============================================================================
--- incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/utils/ServiceReferenceUtils.java (added)
+++ incubator/tuscany/java/sca/itest/serialization/src/main/java/org/apache/tuscany/sca/itest/servicereference/utils/ServiceReferenceUtils.java Wed Apr  9 04:23:20 2008
@@ -0,0 +1,127 @@
+/*
+ * 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.servicereference.utils;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ServiceReference;
+
+/**
+ * Utility methods that are used by the ServiceReference Serialization tests
+ * 
+ * @version $Date $Revision$
+ */
+public final class ServiceReferenceUtils {
+
+    /**
+     * Constructor
+     */
+    private ServiceReferenceUtils() {
+    }
+
+    /**
+     * Serializes the specified Object to a byte[]
+     * 
+     * @param obj The Object to Serialize
+     * @return The Serialized Object as a byte[]
+     * @throws IOException Failed to Serialize the Object
+     */
+    public static byte[] serialize(Object obj) throws IOException {
+        ByteArrayOutputStream bos = null;
+        try {
+            ObjectOutputStream oos = null;
+            bos = new ByteArrayOutputStream();
+            try {
+                oos = new ObjectOutputStream(bos);
+                oos.writeObject(obj);
+                oos.flush();
+            } finally {
+                if (oos != null) {
+                    oos.close();
+                }
+            }
+        } finally {
+            if (bos != null) {
+                bos.close();
+            }
+        }
+
+        return bos.toByteArray();
+    }
+
+    /**
+     * Deserializes the specified byte[] into a ServiceReference
+     * 
+     * @param serializedSR The Serialized ServiceReference to deserialize
+     * @return The deserialized ServiceReference
+     * @throws IOException Failed to deserialize the ServiceReference
+     * @throws ClassNotFoundException Failed to deserialize the ServiceReference
+     */
+    public static ServiceReference<?> deserializeServiceReference(byte[] serializedSR)
+            throws IOException, ClassNotFoundException {
+        return (ServiceReference<?>) deserialize(serializedSR);
+    }
+
+    /**
+     * Deserializes the specified byte[] into a CallableReference
+     * 
+     * @param callableRef The Serialized CallableReference to deserialize
+     * @return The deserialized ServiceReference
+     * @throws IOException Failed to deserialize the CallableReference
+     * @throws ClassNotFoundException Failed to deserialize the CallableReference
+     */
+    public static CallableReference<?> deserializeCallableReference(byte[] callableRef)
+            throws IOException, ClassNotFoundException {
+        return (CallableReference<?>) deserialize(callableRef);
+    }
+
+    /**
+     * Deserializes the specified byte[] into an Object
+     * 
+     * @param serializedObj The Serialized Object to deserialize
+     * @return The deserialized Object
+     * @throws IOException Failed to deserialize the Object
+     * @throws ClassNotFoundException Failed to deserialize the Object
+     */
+    public static Object deserialize(byte[] serializedSR) throws IOException, ClassNotFoundException {
+        ByteArrayInputStream bis = null;
+        try {
+            ObjectInputStream ois = null;
+            bis = new ByteArrayInputStream(serializedSR);
+            try {
+                ois = new ObjectInputStream(bis);
+                Object obj = ois.readObject();
+                return obj;
+            } finally {
+                if (ois != null) {
+                    ois.close();
+                }
+            }
+        } finally {
+            if (bis != null) {
+                bis.close();
+            }
+        }
+    }
+}

Added: incubator/tuscany/java/sca/itest/serialization/src/main/resources/ServiceReferenceSerializationTest.composite
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/serialization/src/main/resources/ServiceReferenceSerializationTest.composite?rev=646273&view=auto
==============================================================================
--- incubator/tuscany/java/sca/itest/serialization/src/main/resources/ServiceReferenceSerializationTest.composite (added)
+++ incubator/tuscany/java/sca/itest/serialization/src/main/resources/ServiceReferenceSerializationTest.composite Wed Apr  9 04:23:20 2008
@@ -0,0 +1,47 @@
+<?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://www.osoa.org/xmlns/sca/1.0" xmlns:foo="http://foo" targetNamespace="http://foo"
+    name="ServiceReferenceSerializationTest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+    <service name="StatelessService" promote="StatelessComponent">
+        <interface.java interface="org.apache.tuscany.sca.itest.servicereference.StatelessService" />
+    </service>
+
+    <service name="ConversationalService" promote="ConversationalComponent">
+        <interface.java interface="org.apache.tuscany.sca.itest.servicereference.ConversationalService" />
+    </service>
+
+    <service name="SCAManagedClient" promote="SCAManagedClientComponent">
+        <interface.java interface="org.apache.tuscany.sca.itest.servicereference.SCAManagedClient" />
+    </service>
+
+    <component name="StatelessComponent">
+        <implementation.java class="org.apache.tuscany.sca.itest.servicereference.StatelessServiceImpl" />
+    </component>
+
+    <component name="ConversationalComponent">
+        <implementation.java class="org.apache.tuscany.sca.itest.servicereference.ConversationalServiceImpl" />
+    </component>
+
+    <component name="SCAManagedClientComponent">
+        <implementation.java class="org.apache.tuscany.sca.itest.servicereference.SCAManagedClientImpl" />
+        <reference name="statelessService" target="StatelessComponent"/>
+        <reference name="conversationalService" target="ConversationalComponent"/>
+    </component>
+</composite>

Added: incubator/tuscany/java/sca/itest/serialization/src/test/java/org/apache/tuscany/sca/itest/servicereference/SerializeServiceReferenceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/serialization/src/test/java/org/apache/tuscany/sca/itest/servicereference/SerializeServiceReferenceTestCase.java?rev=646273&view=auto
==============================================================================
--- incubator/tuscany/java/sca/itest/serialization/src/test/java/org/apache/tuscany/sca/itest/servicereference/SerializeServiceReferenceTestCase.java (added)
+++ incubator/tuscany/java/sca/itest/serialization/src/test/java/org/apache/tuscany/sca/itest/servicereference/SerializeServiceReferenceTestCase.java Wed Apr  9 04:23:20 2008
@@ -0,0 +1,106 @@
+/*
+ * 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.servicereference;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * A test case that will attempt to Serialize and Deserialize Service References
+ * 
+ * @version $Date$ $Revision$
+ */
+public class SerializeServiceReferenceTestCase {
+    /**
+     * Reference to the SCA Domain
+     */
+    private static SCADomain domain;
+
+    /**
+     * Initialise the SCA Domain
+     * 
+     * @throws Exception Failed to initialise the SCA Domain
+     */
+    @BeforeClass
+    public static void init() throws Exception {
+        domain = SCADomain.newInstance("ServiceReferenceSerializationTest.composite");
+        Assert.assertNotNull(domain);
+    }
+
+    /**
+     * Shutdown the SCA Domain
+     * 
+     * @throws Exception Failed to shutdown the SCA Domain
+     */
+    @AfterClass
+    public static void destroy() throws Exception {
+        if (domain != null) {
+            domain.close();
+        }
+    }
+
+    /**
+     * Tests Serializing a Stateless ServiceReference as managed
+     * SCA code
+     * 
+     * @throws Exception Test failed
+     */
+    @Test
+    public void testSerializeStatelessServiceReferenceInsideSCA() throws Exception {
+        SCAManagedClient client = domain.getService(
+                SCAManagedClient.class, "SCAManagedClientComponent");
+
+        client.testSerializeStatelessServiceReference();
+    }
+
+    /**
+     * Tests Serializing a Conversational ServiceReference as managed
+     * SCA code
+     * 
+     * @throws Exception Test failed
+     */
+    @Test
+    public void testSerializeConversationalServiceReferenceInsideSCA() throws Exception {
+        SCAManagedClient client = domain.getService(
+                SCAManagedClient.class, "SCAManagedClientComponent");
+
+        client.testSerializeConversationalServiceReference();
+    }
+
+    /**
+     * Tests Serializing a Callback to a Stateless Service as managed
+     * SCA code
+     * 
+     * @throws Exception Test failed
+     */
+    // TODO: TUSCANY-2213 - This test fails so disabled for now
+    @Ignore
+    @Test
+    public void testSerializeCallbackToStatelessServiceInsideSCA() throws Exception {
+        SCAManagedClient client = domain.getService(
+                SCAManagedClient.class, "SCAManagedClientComponent");
+
+        client.testSerializeCallbackToStatelessServiceInsideSCA();
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org