You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by kw...@apache.org on 2008/05/01 16:11:47 UTC

svn commit: r652528 - in /incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src: main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/ main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/ main/resourc...

Author: kwilliams
Date: Thu May  1 07:11:47 2008
New Revision: 652528

URL: http://svn.apache.org/viewvc?rev=652528&view=rev
Log:
New conversation lifetime tests. TUSCANY-2247

Added:
    incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AServiceCallback.java   (with props)
    incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/CService.java   (with props)
    incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/DService.java   (with props)
    incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/CServiceImpl.java   (with props)
    incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/DServiceImpl.java   (with props)
Modified:
    incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AService.java
    incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/BService.java
    incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/AServiceImpl.java
    incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/BServiceImpl.java
    incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/resources/lifetime.composite
    incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/test/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/LifetimeTestCase.java

Modified: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AService.java?rev=652528&r1=652527&r2=652528&view=diff
==============================================================================
--- incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AService.java (original)
+++ incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AService.java Thu May  1 07:11:47 2008
@@ -18,11 +18,38 @@
  */
 package org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime;
 
+import org.osoa.sca.annotations.Remotable;
+
 /**
  * Simple Remotable Service
  */
+@Remotable
 public interface AService {
 
-    public void setBStateThenGetCState();
+    public void testConversationStarted();
+
+    public void testConversationStarted2();
+
+    public void testConversationContinue();
+
+    public void testConversationContinue2();
+
+    public void testConversationContinue3();
+
+    public void testConversationEnd();
+
+    public void testConversationEnd2();
+
+    public void testConversationEnd3();
+
+    public void testConversationEnd4();
+
+    public void testConversationEnd5();
+
+    public void testConversationEnd6();
+
+    public void testConversationEnd7();
+
+    public void testConversationEnd8();
     
 }

Added: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AServiceCallback.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AServiceCallback.java?rev=652528&view=auto
==============================================================================
--- incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AServiceCallback.java (added)
+++ incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AServiceCallback.java Thu May  1 07:11:47 2008
@@ -0,0 +1,35 @@
+/*
+ * 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.vtest.javaapi.conversation.lifetime;
+
+import org.osoa.sca.annotations.Conversational;
+import org.osoa.sca.annotations.EndsConversation;
+import org.osoa.sca.annotations.Remotable;
+
+/**
+ * Simple Remotable Service
+ */
+@Remotable
+@Conversational
+public interface AServiceCallback {
+
+    @EndsConversation
+    public void endConversation();
+    
+}

Propchange: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AServiceCallback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AServiceCallback.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/BService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/BService.java?rev=652528&r1=652527&r2=652528&view=diff
==============================================================================
--- incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/BService.java (original)
+++ incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/BService.java Thu May  1 07:11:47 2008
@@ -18,7 +18,9 @@
  */
 package org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime;
 
+import org.osoa.sca.annotations.Callback;
 import org.osoa.sca.annotations.Conversational;
+import org.osoa.sca.annotations.EndsConversation;
 import org.osoa.sca.annotations.Remotable;
 
 /**
@@ -26,9 +28,18 @@
  */
 @Remotable
 @Conversational
+@Callback(AServiceCallback.class)
 public interface BService {
 
     public void setState(String someState);
+    
     public String getState();
+    
+    @EndsConversation
+    public void endConversation();
+    
+    public void endConversationViaCallback();
+
+    public void throwNonBusinessException();
 
 }

Added: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/CService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/CService.java?rev=652528&view=auto
==============================================================================
--- incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/CService.java (added)
+++ incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/CService.java Thu May  1 07:11:47 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.vtest.javaapi.conversation.lifetime;
+
+import org.osoa.sca.annotations.Conversational;
+import org.osoa.sca.annotations.Remotable;
+
+/**
+ * Simple Local Service
+ */
+@Remotable
+@Conversational
+public interface CService {
+
+    public void setState(String someState);
+    public String getState();
+
+}

Propchange: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/CService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/CService.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/DService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/DService.java?rev=652528&view=auto
==============================================================================
--- incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/DService.java (added)
+++ incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/DService.java Thu May  1 07:11:47 2008
@@ -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.vtest.javaapi.conversation.lifetime;
+
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.annotations.Conversational;
+import org.osoa.sca.annotations.Remotable;
+
+/**
+ * Simple Local Service
+ */
+@Remotable
+@Conversational
+public interface DService {
+
+    public void setState(String someState);
+    public String getState();
+    
+    public void continueConversation(ServiceReference<BService> b, Object convId);
+    public void continueConversation2(String filename, Object id, String serializedState);
+
+}

Propchange: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/DService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/DService.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/AServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/AServiceImpl.java?rev=652528&r1=652527&r2=652528&view=diff
==============================================================================
--- incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/AServiceImpl.java (original)
+++ incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/AServiceImpl.java Thu May  1 07:11:47 2008
@@ -19,22 +19,167 @@
 
 package org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime.impl;
 
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+
 import org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime.AService;
+import org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime.AServiceCallback;
 import org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime.BService;
+import org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime.CService;
+import org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime.DService;
+import org.junit.Assert;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.ConversationEndedException;
 import org.osoa.sca.ServiceReference;
+import org.osoa.sca.annotations.Context;
 import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
 import org.osoa.sca.annotations.Service;
 
 @Service(AService.class)
-public class AServiceImpl implements AService {
+@Scope("CONVERSATION")
+public class AServiceImpl implements AService, AServiceCallback {
+
+    @Context
+    public ComponentContext context;
 
     @Reference
     protected ServiceReference<BService> b;
 
-    public void setBStateThenGetCState() {
-        String someState = "set by A";
+    @Reference
+    protected DService d;
+
+    public void testConversationStarted() {
+        b.getService().setState("Some state");
+        Assert.assertNotNull(b.getConversation().getConversationID());
+    }
+
+    public void testConversationStarted2() {
+        ServiceReference<CService> ref = context.getServiceReference(CService.class, "c");
+        ref.getService().setState("Some state");
+        Assert.assertNotNull(ref.getConversation().getConversationID());
+    }
+
+    public void testConversationContinue() {
+
+        b.getService().setState("Some state");
+        Object id = b.getConversation().getConversationID();
+        b.getService().setState("Some more state");
+        Assert.assertEquals(id, b.getConversation().getConversationID());
+    }
+
+    public void testConversationContinue2() {
+
+        b.getService().setState("Some state");
+        d.continueConversation(b, b.getConversation().getConversationID());
+
+    }
+
+    public void testConversationContinue3() {
+
+        String serializedState = "Serialized State";
+
+        String filename = "target/Serialized-Reference.txt";
+        b.getService().setState(serializedState);
+        Object id = b.getConversation().getConversationID();
+        writeReference(b, filename);
+        d.continueConversation2(filename, id, serializedState);
+
+    }
+
+    // Utilities
+
+    private void delayForSeconds(int numSeconds) {
+        try {
+            Thread.sleep(numSeconds * 1000);// millisecs
+        } catch (InterruptedException ex) {
+            throw new Error(ex);
+        }
+    }
+
+    private void writeReference(ServiceReference<BService> ref, String filename) {
+
+        FileOutputStream fos = null;
+        ObjectOutputStream out = null;
+        try {
+            fos = new FileOutputStream(filename);
+            out = new ObjectOutputStream(fos);
+            out.writeObject(ref);
+            out.close();
+        } catch (IOException ex) {
+            ex.printStackTrace();
+        }
+    }
+
+    public void testConversationEnd() {
+        String someState = "Some state";
+        b.getService().setState(someState);
+        b.getService().endConversation();
+        Assert.assertNotSame(someState, b.getService().getState());
+    }
+
+    public void testConversationEnd2() {
+        String someState = "Some state";
+        b.getService().setState(someState);
+        b.getService().endConversationViaCallback();
+        Assert.assertNotSame(someState, b.getService().getState());
+    }
+
+    public void endConversation() {
+        System.out.println("A-callback to end conversation");
+    }
+
+    public void testConversationEnd3() {
+        String someState = "Some state";
         b.getService().setState(someState);
+        delayForSeconds(2);
+        try {
+            b.getService().getState();
+        } catch (ConversationEndedException e) {
+            b.getConversation().end();// need to clean up to avoid exception
+        }
+        Assert.assertNotSame(someState, b.getService().getState());
     }
 
+    public void testConversationEnd4() {
+        String someState = "Some state";
+        b.getService().setState(someState);
+        b.getConversation().end();
+        Assert.assertNotSame(someState, b.getService().getState());
+    }
+
+    public void testConversationEnd5() {
+        String someState = "Some state";
+        b.getService().setState(someState);
+        try {
+            b.getService().throwNonBusinessException();
+        } catch (Error e) {
+            // Expected
+        }
+        Assert.assertNotSame(someState, b.getService().getState());
+    }
+
+    public void testConversationEnd6() {
+        String someState = "Some state";
+        b.getService().setState(someState);
+        Object id = b.getConversation().getConversationID();
+        b.getService().endConversation();
+        Assert.assertNotSame(someState, b.getService().getState());
+        Assert.assertNotSame(id, b.getConversation().getConversationID());
+    }
+
+    public void testConversationEnd7() {
+        b.getService().setState("Some state");
+        b.getService().endConversation();
+        Assert.assertNull(b.getConversationID());
+    }
+
+    public void testConversationEnd8() {
+        String someState = "Some state";
+        b.getService().setState(someState);
+        delayForSeconds(2);
+        b.getService().getState();
+    }
 
 }

Modified: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/BServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/BServiceImpl.java?rev=652528&r1=652527&r2=652528&view=diff
==============================================================================
--- incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/BServiceImpl.java (original)
+++ incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/BServiceImpl.java Thu May  1 07:11:47 2008
@@ -19,16 +19,23 @@
 
 package org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime.impl;
 
+import org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime.AServiceCallback;
 import org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime.BService;
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.ConversationAttributes;
 import org.osoa.sca.annotations.Scope;
 import org.osoa.sca.annotations.Service;
 
 @Service(BService.class)
 @Scope("CONVERSATION")
+@ConversationAttributes(maxAge="1 seconds")
 public class BServiceImpl implements BService {
 
     String someState;
 
+    @Callback
+    protected AServiceCallback callback;
+
     public void setState(String someState) {
         this.someState = someState;
     }
@@ -37,4 +44,18 @@
         return someState;
     }
 
+    public void endConversation() {
+        System.out.println("Someone called Bservice.endsConversation()");
+    }
+
+    public void endConversationViaCallback() {
+        callback.endConversation();
+    }
+
+    public void throwNonBusinessException() {
+       
+        throw new Error();
+        
+    }
+
 }

Added: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/CServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/CServiceImpl.java?rev=652528&view=auto
==============================================================================
--- incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/CServiceImpl.java (added)
+++ incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/CServiceImpl.java Thu May  1 07:11:47 2008
@@ -0,0 +1,40 @@
+/*
+ * 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.vtest.javaapi.conversation.lifetime.impl;
+
+import org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime.CService;
+import org.osoa.sca.annotations.Scope;
+import org.osoa.sca.annotations.Service;
+
+@Service(CService.class)
+@Scope("CONVERSATION")
+public class CServiceImpl implements CService {
+
+    String someState;
+
+    public void setState(String someState) {
+        this.someState = someState;
+    }
+
+    public String getState() {
+        return someState;
+    }
+
+}

Propchange: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/CServiceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/CServiceImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/DServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/DServiceImpl.java?rev=652528&view=auto
==============================================================================
--- incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/DServiceImpl.java (added)
+++ incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/DServiceImpl.java Thu May  1 07:11:47 2008
@@ -0,0 +1,78 @@
+/*
+ * 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.vtest.javaapi.conversation.lifetime.impl;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+
+import org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime.BService;
+import org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime.DService;
+import org.junit.Assert;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.annotations.Scope;
+import org.osoa.sca.annotations.Service;
+
+@Service(DService.class)
+@Scope("CONVERSATION")
+public class DServiceImpl implements DService {
+
+    String someState;
+
+    public void setState(String someState) {
+        this.someState = someState;
+    }
+
+    public String getState() {
+        return someState;
+    }
+
+    public void continueConversation(ServiceReference<BService> b, Object convId) {
+
+        b.getService().setState("Some more state");
+        Assert.assertEquals(convId, b.getConversation().getConversationID());
+    }
+
+    public void continueConversation2(String filename, Object convId, String serializedState) {
+        ServiceReference<BService> b = readReference(filename);
+        Assert.assertEquals(serializedState, b.getService().getState());
+        Assert.assertEquals(convId, b.getConversation().getConversationID());
+    }
+
+    // Utilities
+    @SuppressWarnings("unchecked")
+    private ServiceReference<BService> readReference(String filename) {
+        ServiceReference<BService> b = null;
+        FileInputStream fis = null;
+        ObjectInputStream in = null;
+        try {
+            fis = new FileInputStream(filename);
+            in = new ObjectInputStream(fis);
+            ServiceReference<BService> readObject = (ServiceReference<BService>)in.readObject();
+            b = readObject;
+            in.close();
+        } catch (IOException ex) {
+            ex.printStackTrace();
+        } catch (ClassNotFoundException ex) {
+            ex.printStackTrace();
+        }
+        return b;
+    }
+}

Propchange: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/DServiceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/DServiceImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/resources/lifetime.composite
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/resources/lifetime.composite?rev=652528&r1=652527&r2=652528&view=diff
==============================================================================
--- incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/resources/lifetime.composite (original)
+++ incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/main/resources/lifetime.composite Thu May  1 07:11:47 2008
@@ -18,12 +18,14 @@
 	* under the License.
 -->
 <composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
-	targetNamespace="http://java-api-tests" name="Converstion-Composite">
+	targetNamespace="http://java-api-tests" name="Converstion-Lifetime">
 
 	<component name="AComponent">
 		<implementation.java
 			class="org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime.impl.AServiceImpl" />
 		<reference name="b" target="BComponent" />
+		<reference name="c" target="CComponent" />
+		<reference name="d" target="DComponent" />
 	</component>
 
 	<component name="BComponent">
@@ -31,4 +33,14 @@
 			class="org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime.impl.BServiceImpl" />
 	</component>
 
+	<component name="CComponent">
+		<implementation.java
+			class="org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime.impl.CServiceImpl" />
+	</component>
+
+	<component name="DComponent">
+		<implementation.java
+			class="org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime.impl.DServiceImpl" />
+	</component>
+	
 </composite>

Modified: incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/test/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/LifetimeTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/test/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/LifetimeTestCase.java?rev=652528&r1=652527&r2=652528&view=diff
==============================================================================
--- incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/test/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/LifetimeTestCase.java (original)
+++ incubator/tuscany/java/sca/vtest/java-api/conversation/lifetime/src/test/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/LifetimeTestCase.java Thu May  1 07:11:47 2008
@@ -22,11 +22,12 @@
 import org.apache.tuscany.sca.host.embedded.SCADomain;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
+import org.osoa.sca.ConversationEndedException;
 
 /**
- * This test class tests the Service annotation described in section 1.2.1 and
- * 1.8.17
+ * 
  */
 public class LifetimeTestCase {
 
@@ -55,17 +56,162 @@
     }
 
     /**
-     * Line 423, 424, 425:<br>
+     * Lines 475, 476
      * <p>
-     * The service reference which represents a single conversation can be
-     * passed as a parameter to another service, even if that other service is
-     * remote. This may be used in order to allow one component to continue a
-     * conversation that had been started by another.
+     * Conversations start on the client side when one of the following occur: A
+     * "@Reference" to a conversational service is injected, ... and then a
+     * method of the service is called
      */
     @Test
-    public void passParameter1() throws Exception {
-        System.out.println("No tests yet");
+    public void lifetime1() throws Exception {
+        aService.testConversationStarted();
     }
 
+    /**
+     * Lines 477, 478, 479
+     * <p>
+     * Conversations start on the client side when one of the following occur
+     * ... A call is made to CompositeContext.getServiceReference and then a
+     * method of the service is called.
+     */
+    @Test
+    @Ignore("TUSCANY-2243")
+    public void lifetime2() throws Exception {
+        aService.testConversationStarted2();
+    }
+
+    /**
+     * Line 481, 482
+     * <p>
+     * The client can continue an existing conversation, by: Holding the service
+     * reference that was created when the conversation started
+     */
+    @Test
+    public void lifetime3() throws Exception {
+        aService.testConversationContinue();
+    }
+
+    /**
+     * Line 481, 483
+     * <p>
+     * The client can continue an existing conversation, by: ... • Getting the
+     * service reference object passed as a parameter from another service, even
+     * remotely
+     */
+    @Test
+    public void lifetime4() throws Exception {
+        // aService.testConversationContinue2();
+    }
+
+    /**
+     * Line 481, 484
+     * <p>
+     * The client can continue an existing conversation, by:<br> • Loading a
+     * service reference that had been written to some form of persistent
+     * storage
+     */
+    @Test
+    public void lifetime6() throws Exception {
+        aService.testConversationContinue3();
+    }
+
+    /**
+     * Line 487, 488
+     * <p>
+     * A conversation ends, and any state associated with the conversation is
+     * freed up, when: <br>
+     * ...A server operation that has been annotated "@EndConveration" has been
+     * called
+     */
+    @Test
+    public void lifetime7() throws Exception {
+        aService.testConversationEnd();
+    }
+
+    /**
+     * Line 487, 489
+     * <p>
+     * A conversation ends, and any state associated with the conversation is
+     * freed up, when: <br>
+     * ...The server calls an "@EndsConversation" method on the "@Callback"
+     * reference <br>
+     */
+    @Test
+    public void lifetime8() throws Exception {
+        aService.testConversationEnd2();
+    }
+
+    /**
+     * Line 487, 490
+     * <p>
+     * 487 A conversation ends, and any state associated with the conversation
+     * is freed up, when: <br>
+     * ... The server's conversation lifetime timeout occurs
+     */
+    @Test
+    public void lifetime9() throws Exception {
+        aService.testConversationEnd3();
+    }
+
+    /**
+     * Line 487, 491
+     * <p>
+     * A conversation ends, and any state associated with the conversation
+     * is freed up, when: <br>
+     * ...The client calls Conversation.end()
+     */
+    @Test
+    public void lifetime10() throws Exception {
+        aService.testConversationEnd4();
+    }
+
+    /**
+     * Line 487, 492
+     * <p>
+     * A conversation ends, and any state associated with the conversation
+     * is freed up, when: <br>
+     * ...Any non-business exception is thrown by a conversational operation
+     */
+    @Test
+    @Ignore("TUSCANY-2283")
+    public void lifetime11() throws Exception {
+        aService.testConversationEnd5();
+    }
+
+    /**
+     * Line 494, 495
+     * <p>
+     * If a method is invoked on a service reference after an
+     * "@EndsConversation" method has been called then a new conversation will
+     * automatically be started.
+     */
+    @Test
+    public void lifetime12() throws Exception {
+        aService.testConversationEnd6();
+    }
+
+    /**
+     * Line 495, 496, 497
+     * <p>
+     * If ServiceReference.getConversationID() is called after the
+     * "@EndsConversation" method: is called, but before the next conversation has
+     * been started, it will return null.
+     */
+    @Test
+    public void lifetime13() throws Exception {
+        aService.testConversationEnd7();
+    }
+
+    /**
+     * Line 498, 499
+     * <p>
+     * If a service reference is used after the service provider's
+     * conversation timeout has caused the conversation to be ended, then
+     * ConversationEndedException will be thrown.
+     */
+    @Test(expected=ConversationEndedException.class)
+    public void lifetime14() throws Exception {
+        aService.testConversationEnd8();
+    }
 
 }