From 75813a5fd9489c1715e7544d4e1416b7a16e81eb Mon Sep 17 00:00:00 2001 From: antelder Date: Tue, 17 Mar 2009 16:20:41 +0000 Subject: [maven-release-plugin] copy for tag 2.0-M2 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@755301 13f79535-47bb-0310-9956-ffa450edef68 --- .../vtest/java-api/conversation/lifetime/pom.xml | 46 +++++ .../javaapi/conversation/lifetime/AService.java | 56 ++++++ .../conversation/lifetime/AServiceCallback.java | 35 ++++ .../javaapi/conversation/lifetime/BService.java | 47 +++++ .../lifetime/BServiceBusinessException.java | 53 +++++ .../javaapi/conversation/lifetime/CService.java | 34 ++++ .../javaapi/conversation/lifetime/DService.java | 38 ++++ .../conversation/lifetime/impl/AServiceImpl.java | 197 +++++++++++++++++++ .../conversation/lifetime/impl/BServiceImpl.java | 64 ++++++ .../conversation/lifetime/impl/CServiceImpl.java | 40 ++++ .../conversation/lifetime/impl/DServiceImpl.java | 78 ++++++++ .../lifetime/src/main/resources/lifetime.composite | 45 +++++ .../conversation/lifetime/LifetimeTestCase.java | 216 +++++++++++++++++++++ 13 files changed, 949 insertions(+) create mode 100644 sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/pom.xml create mode 100644 sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AService.java create mode 100644 sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AServiceCallback.java create mode 100644 sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/BService.java create mode 100644 sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/BServiceBusinessException.java create mode 100644 sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/CService.java create mode 100644 sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/DService.java create mode 100644 sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/AServiceImpl.java create mode 100644 sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/BServiceImpl.java create mode 100644 sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/CServiceImpl.java create mode 100644 sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/DServiceImpl.java create mode 100644 sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/resources/lifetime.composite create mode 100644 sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/test/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/LifetimeTestCase.java (limited to 'sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime') diff --git a/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/pom.xml b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/pom.xml new file mode 100644 index 0000000000..ed3c07ae7c --- /dev/null +++ b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/pom.xml @@ -0,0 +1,46 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + java-api-annotations + 2.0-M2-SNAPSHOT + ../pom.xml + + vtest-java-api-conversation-lifetime + Apache Tuscany SCA Java APIs and Annotations Verification Tests - Conversation - Lifetime + + + + org.apache.tuscany.sca + tuscany-host-embedded + 2.0-M2-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 2.0-M2-SNAPSHOT + runtime + + + + diff --git a/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AService.java b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AService.java new file mode 100644 index 0000000000..f5249b3a5b --- /dev/null +++ b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AService.java @@ -0,0 +1,56 @@ +/* + * 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.oasisopen.sca.annotation.Remotable; + +/** + * Simple Remotable Service + */ +@Remotable +public interface AService { + + 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(); + + public void testConversationEnd9(); +} diff --git a/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AServiceCallback.java b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AServiceCallback.java new file mode 100644 index 0000000000..635e6e74d4 --- /dev/null +++ b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/AServiceCallback.java @@ -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.oasisopen.sca.annotation.Conversational; +import org.oasisopen.sca.annotation.EndsConversation; +import org.oasisopen.sca.annotation.Remotable; + +/** + * Simple Remotable Service + */ +@Remotable +@Conversational +public interface AServiceCallback { + + @EndsConversation + public void endConversation(); + +} diff --git a/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/BService.java b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/BService.java new file mode 100644 index 0000000000..b28a31da38 --- /dev/null +++ b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/BService.java @@ -0,0 +1,47 @@ +/* + * 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.oasisopen.sca.annotation.Callback; +import org.oasisopen.sca.annotation.Conversational; +import org.oasisopen.sca.annotation.EndsConversation; +import org.oasisopen.sca.annotation.Remotable; + +/** + * Simple Local Service + */ +@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(); + + public void throwBusinessException() throws BServiceBusinessException; + +} diff --git a/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/BServiceBusinessException.java b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/BServiceBusinessException.java new file mode 100644 index 0000000000..ab186ee7eb --- /dev/null +++ b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/BServiceBusinessException.java @@ -0,0 +1,53 @@ +/* + * 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; + + +/** + * Denotes an error starting the runtime + * + * @version $Rev$ $Date$ + */ +public class BServiceBusinessException extends Exception { + + static final long serialVersionUID = 2096658015909178325L; + + private String message; + + public BServiceBusinessException() { + } + + public BServiceBusinessException(String message) { + super(message); + setMessage(message); + } + + public BServiceBusinessException(Throwable cause) { + super(cause); + setMessage(cause.getMessage()); + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/CService.java b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/CService.java new file mode 100644 index 0000000000..020d18b862 --- /dev/null +++ b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/CService.java @@ -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.oasisopen.sca.annotation.Conversational; +import org.oasisopen.sca.annotation.Remotable; + +/** + * Simple Local Service + */ +@Remotable +@Conversational +public interface CService { + + public void setState(String someState); + public String getState(); + +} diff --git a/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/DService.java b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/DService.java new file mode 100644 index 0000000000..c339ebd6ea --- /dev/null +++ b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/DService.java @@ -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.oasisopen.sca.ServiceReference; +import org.oasisopen.sca.annotation.Conversational; +import org.oasisopen.sca.annotation.Remotable; + +/** + * Simple Local Service + */ +@Remotable +@Conversational +public interface DService { + + public void setState(String someState); + public String getState(); + + public void continueConversation(ServiceReference b, Object convId); + public void continueConversation2(String filename, Object id, String serializedState); + +} diff --git a/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/AServiceImpl.java b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/AServiceImpl.java new file mode 100644 index 0000000000..18d592f9d0 --- /dev/null +++ b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/AServiceImpl.java @@ -0,0 +1,197 @@ +/* + * 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.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.BServiceBusinessException; +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.oasisopen.sca.ComponentContext; +import org.oasisopen.sca.ConversationEndedException; +import org.oasisopen.sca.ServiceReference; +import org.oasisopen.sca.annotation.Context; +import org.oasisopen.sca.annotation.Reference; +import org.oasisopen.sca.annotation.Scope; +import org.oasisopen.sca.annotation.Service; + +@Service(AService.class) +@Scope("CONVERSATION") +public class AServiceImpl implements AService, AServiceCallback { + + @Context + public ComponentContext context; + + @Reference + protected ServiceReference b; + + @Reference + protected DService d; + + public void testConversationStarted() { + b.getService().setState("Some state"); + Assert.assertNotNull(b.getConversation().getConversationID()); + } + + public void testConversationStarted2() { + ServiceReference ref = context.getServiceReference(BService.class, "b"); + 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 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(); + } + + public void testConversationEnd9() { + String someState = "Some state"; + b.getService().setState(someState); + try { + b.getService().throwBusinessException(); + } catch (BServiceBusinessException e) { + // Expected + } + Assert.assertSame(someState, b.getService().getState()); + } + +} diff --git a/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/BServiceImpl.java b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/BServiceImpl.java new file mode 100644 index 0000000000..71e09c38b3 --- /dev/null +++ b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/BServiceImpl.java @@ -0,0 +1,64 @@ +/* + * 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.AServiceCallback; +import org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime.BService; +import org.apache.tuscany.sca.vtest.javaapi.conversation.lifetime.BServiceBusinessException; +import org.oasisopen.sca.annotation.Callback; +import org.oasisopen.sca.annotation.ConversationAttributes; +import org.oasisopen.sca.annotation.Scope; +import org.oasisopen.sca.annotation.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; + } + + public String getState() { + return someState; + } + + public void endConversation() { + System.out.println("Someone called Bservice.endsConversation()"); + } + + public void endConversationViaCallback() { + callback.endConversation(); + } + + public void throwNonBusinessException() { + throw new Error(); + } + + public void throwBusinessException() throws BServiceBusinessException { + throw new BServiceBusinessException("Business Exception"); + } + +} diff --git a/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/CServiceImpl.java b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/CServiceImpl.java new file mode 100644 index 0000000000..e182613932 --- /dev/null +++ b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/CServiceImpl.java @@ -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.oasisopen.sca.annotation.Scope; +import org.oasisopen.sca.annotation.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; + } + +} diff --git a/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/DServiceImpl.java b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/DServiceImpl.java new file mode 100644 index 0000000000..15a4ab3b76 --- /dev/null +++ b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/impl/DServiceImpl.java @@ -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.oasisopen.sca.ServiceReference; +import org.oasisopen.sca.annotation.Scope; +import org.oasisopen.sca.annotation.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 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 b = readReference(filename); + Assert.assertEquals(serializedState, b.getService().getState()); + Assert.assertEquals(convId, b.getConversation().getConversationID()); + } + + // Utilities + @SuppressWarnings("unchecked") + private ServiceReference readReference(String filename) { + ServiceReference b = null; + FileInputStream fis = null; + ObjectInputStream in = null; + try { + fis = new FileInputStream(filename); + in = new ObjectInputStream(fis); + ServiceReference readObject = (ServiceReference)in.readObject(); + b = readObject; + in.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } catch (ClassNotFoundException ex) { + ex.printStackTrace(); + } + return b; + } +} diff --git a/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/resources/lifetime.composite b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/resources/lifetime.composite new file mode 100644 index 0000000000..21ee8acac1 --- /dev/null +++ b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/main/resources/lifetime.composite @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/test/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/LifetimeTestCase.java b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/test/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/LifetimeTestCase.java new file mode 100644 index 0000000000..52c11b881c --- /dev/null +++ b/sandbox/ant/sca/tags/2.0-M2/vtest/java-api/conversation/lifetime/src/test/java/org/apache/tuscany/sca/vtest/javaapi/conversation/lifetime/LifetimeTestCase.java @@ -0,0 +1,216 @@ +/* + * 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.apache.tuscany.sca.vtest.utilities.ServiceFinder; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.oasisopen.sca.ConversationEndedException; + +/** + * + */ +public class LifetimeTestCase { + + protected static String compositeName = "lifetime.composite"; + protected static AService aService = null; + + @BeforeClass + public static void init() throws Exception { + try { + System.out.println("Setting up"); + ServiceFinder.init(compositeName); + aService = ServiceFinder.getService(AService.class, "AComponent"); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + @AfterClass + public static void destroy() throws Exception { + + System.out.println("Cleaning up"); + ServiceFinder.cleanup(); + + } + + /** + * Lines 475, 476 + *

+ * 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 lifetime1() throws Exception { + aService.testConversationStarted(); + } + + /** + * Lines 477, 478, 479 + *

+ * 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 + *

+ * 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 + *

+ * 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 + *

+ * The client can continue an existing conversation, by:
• 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 + *

+ * A conversation ends, and any state associated with the conversation is + * freed up, when:
+ * ...A server operation that has been annotated "@EndConveration" has been + * called + */ + @Test + public void lifetime7() throws Exception { + aService.testConversationEnd(); + } + + /** + * Line 487, 489 + *

+ * A conversation ends, and any state associated with the conversation is + * freed up, when:
+ * ...The server calls an "@EndsConversation" method on the "@Callback" + * reference
+ */ + @Test + public void lifetime8() throws Exception { + aService.testConversationEnd2(); + } + + /** + * Line 487, 490 + *

+ * 487 A conversation ends, and any state associated with the conversation + * is freed up, when:
+ * ... The server's conversation lifetime timeout occurs + */ + @Test + public void lifetime9() throws Exception { + aService.testConversationEnd3(); + } + + /** + * Line 487, 491 + *

+ * A conversation ends, and any state associated with the conversation is + * freed up, when:
+ * ...The client calls Conversation.end() + */ + @Test + public void lifetime10() throws Exception { + aService.testConversationEnd4(); + } + + /** + * Line 487, 492 + *

+ * A conversation ends, and any state associated with the conversation is + * freed up, when:
+ * ...Any non-business exception is thrown by a conversational operation + */ + @Test + //@Ignore("TUSCANY-2283") + public void lifetime11() throws Exception { + aService.testConversationEnd5(); + aService.testConversationEnd9(); + } + + /** + * Line 494, 495 + *

+ * 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 + *

+ * 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 + *

+ * 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(); + } + +} -- cgit v1.2.3