diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:13:31 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:13:31 +0000 |
commit | 3caf8614f25d6b1962e20331fdf423c863bc02f3 (patch) | |
tree | 069fa30b63dd4804846385d8571928bdaa7b73ad /sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src | |
parent | 6d0e93c68d3aeaeb4bb6d96ac0460eec40ef786e (diff) |
Moving 1.x branches
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835144 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src')
12 files changed, 916 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/AnotherService.java b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/AnotherService.java new file mode 100644 index 0000000000..f8256e6446 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/AnotherService.java @@ -0,0 +1,18 @@ +package org.apache.tuscany.sca.test; + +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.ServiceReference; + +@Remotable + +/** + * + */ +public interface AnotherService { + + public void setService(ServiceReference aServiceReference); + public void add(int anInt); + public int getCount(); + +} diff --git a/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/AnotherServiceImpl.java b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/AnotherServiceImpl.java new file mode 100644 index 0000000000..184ff20727 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/AnotherServiceImpl.java @@ -0,0 +1,59 @@ +package org.apache.tuscany.sca.test; + +import junit.framework.Assert; + +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; +import org.osoa.sca.RequestContext; +import org.osoa.sca.ServiceReference; +import org.osoa.sca.annotations.Callback; +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Service; +import org.osoa.sca.annotations.Context; +import org.osoa.sca.annotations.Scope; +import java.io.File; +import org.apache.tuscany.sca.test.ConversationsClient; + +@Service(AnotherService.class) +@Scope("CONVERSATION") + +public class AnotherServiceImpl implements AnotherService { + + // This is a simple pass-thru service used to test propogation + // of ServiceReference and maintenance of Session state. + + private ServiceReference aServiceReference; + + public void add(int anInt) { + + Assert.assertNotNull("AnotherServiceImpl - add ", aServiceReference); + ((ConversationsService) aServiceReference).add(anInt); + + } + + + public void initializeCount() { + + Assert.assertNotNull("AnotherServiceImpl - initializeCount ", aServiceReference); + ((ConversationsService) aServiceReference).initializeCount(); + + } + + + public void setService(ServiceReference aRef) { + + Assert.assertNotNull("AnotherServiceImpl - setService ", aRef); + aServiceReference = aRef; + + } + + + public int getCount() { + + Assert.assertNotNull("AnotherServiceImpl - getCount ", aServiceReference); + return ((ConversationsService) aServiceReference).getLocalCount(); + } + + +} + diff --git a/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsCallback.java b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsCallback.java new file mode 100644 index 0000000000..1aa4089805 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsCallback.java @@ -0,0 +1,18 @@ +/** + * + */ +package org.apache.tuscany.sca.test; + +import org.osoa.sca.annotations.Remotable; + +/** + * @author lamodeo + * + */ +public interface ConversationsCallback { + + public void callBackMessage(String aString); + public void callBackIncrement(String aString); + public void callBackEndSession(); + +} diff --git a/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsClient.java b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsClient.java new file mode 100644 index 0000000000..1d2ecb4903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsClient.java @@ -0,0 +1,12 @@ +package org.apache.tuscany.sca.test; + +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Scope; + +@Remotable +public interface ConversationsClient { + + public void run(); + public int count(); + +} diff --git a/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsClient2.java b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsClient2.java new file mode 100644 index 0000000000..b464899922 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsClient2.java @@ -0,0 +1,11 @@ +package org.apache.tuscany.sca.test; + +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Scope; + +@Remotable +public interface ConversationsClient2 { + public String getDateTime(); + + +} diff --git a/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsClientImpl.java b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsClientImpl.java new file mode 100644 index 0000000000..5b7165de34 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsClientImpl.java @@ -0,0 +1,466 @@ +package org.apache.tuscany.sca.test; + +import java.io.File; +import java.text.DateFormat; + +import junit.framework.Assert; + +import org.osoa.sca.CompositeContext; +import org.osoa.sca.ConversationEndedException; +import org.osoa.sca.CurrentCompositeContext; +import org.osoa.sca.ServiceReference; +import org.osoa.sca.annotations.Context; +import org.osoa.sca.annotations.ConversationAttributes; +import org.osoa.sca.annotations.ConversationID; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +@Service(interfaces={ConversationsClient.class,ConversationsClient2.class}) + + +@Scope("CONVERSATION") +@ConversationAttributes(maxIdleTime="10 minutes", + singlePrincipal=false) + + +public class ConversationsClientImpl implements ConversationsClient, ConversationsClient2, ConversationsCallback { + + @Reference + protected ConversationsService aService; + @Reference + protected AnotherService anotherService; + @Reference + protected ConversationsLifeCycleService aLifeCycleService; + @Context + protected CompositeContext myContext; // This is broken Tuscany-965 defect has been opened. + @ConversationID + protected String conversationID; + + private Object monitor = new Object(); + private int count=0; + private String message; + private String initialState; + private int initialCount = 56; + private String dateTime; + private final static String markerFileName = "target/testConversations_test3_marker"; + + public void run() { + + // This tests various aspects of session lifecycle and maintenance of session state. + // None of these test are working due to various issues. + + /* test0() + This test verifies annotations and API's for ConversationID. + */ + test0(); // - Tuscany-1001. + + /* test1() + Test stateful callbacks. Verify that the client�s state is maintained throughout the execution of + all callback methods. + */ + test1(); // This test is working for MODULE scope. Cant claim succcess because it needs Conversation scope. + + /* test2() + Test each method of starting a session. Test @Init. + */ + test2(); // Tuscany-965, Tuscany-1001 + + /* test3() + Test each method of ending a session. Test @Destroy. + */ + test3(); // Tuscany-965, Tuscany-1001 + + /* test4() + Pass an existing service reference with an active session to another service. Verify the session is maintained + */ + test4(); // Tuscany-964, Tuscant-1001 + + /* test5() + Call the createServiceReferenceForSession() API to get a service reference for the active session. + Pass the service reference to another service. Verify the session is maintained. + */ + test5(); + + /* test6() + * Allow a session to timeout. + */ + test6(); // Tuscany-965, Tuscany-1001 + + + return; + } + + private void test0() + { + + // Verify that conversationID was injected. + Assert.assertNotNull("test0 - conversationID injected", conversationID); + System.out.println("ConversationID: " + conversationID); + + // + // The client may access the ConversationID by calling getConversationID on a Service Reference. + // This also verifies a session was created during injection of this Service Reference. + // + //FIXME Port to the 1.0 spec API + //Object aServicesSessionID =((ServiceReference)aService).getSessionID(); + //Assert.assertNotNull("test0 - ConversationID from service reference", aServicesSessionID); + + //FIXME Port to the 1.0 spec API + //Object aLifeCycleServicesSessionID =((ServiceReference)aLifeCycleService).getSessionID(); + //Assert.assertNotNull("test0 - ConversationID from LifeCycleService service reference", aLifeCycleServicesSessionID); + + // This will verify the @Init() is working for a session created during injection. See test2(). + aLifeCycleService.knockKnock("Hello"); + + } + + private void test1() + { + + // + // This test verifies that the state of the client is preserved across method calls. Each + // call to the service results in 2 callbacks. One to increment a count and the other to set a string. + // At the end of the test the count should equal 5 and the string should be set. Also the original strings + // values should be preserved. + // + // + initialState = "Initial State"; + + int numCalls = 0; + + for(int i=0; i < 10; i++) + { + aService.knockKnock("Knock Knock " + ++numCalls); + } + + // I want to drive multiple callbacks and then give them time to complete. Don't want to + // force serialization. After 20 seconds check the assertions. + + synchronized(monitor) + { + try + { + monitor.wait(20000L); + } + catch (Exception ex) + {ex.printStackTrace();} + } + + // Here we test for the expected state of several different variables. State needs to be maintained + // across method calls to the service. If the same client instance is used then the state should match + // the following assertions. + + // instance variable count should equal the number of calls to the backend service. count is incremented + // during callback processing. + Assert.assertEquals("Conversations - Test1 count", numCalls, count); + // The returned message should be like the following. + Assert.assertEquals("Conversations - Test1 message", true, message.startsWith("Who's There")); + // any initial state set prior to running the callbacks should be maintained. + Assert.assertEquals("Conversations - Test1 initialState", "Initial State", initialState); + Assert.assertEquals("Conversations - Test1 initialCount", 56, initialCount); + + return; + + } + + private void test2() + { + + // Verify the various methods to create a new Session. + // Sesssions can be started: + // + // 1) When a service reference is injected into a client. This is verified in test0(). + // 2) By the client calling newSession() API with and without a ConversationID. + // + // Verify init() is called prior to any business methods. This is performed in the Service when any + // business methos is called. + + myContext = CurrentCompositeContext.getContext(); + Assert.assertNotNull("current composite context",myContext); + + // This tests creating a conversational session. And that @Init is run prior to business method. + ServiceReference aServRef; + aServRef = myContext.newSession("ConversationsLifeCycleService"); + Assert.assertNotNull("Conversations - Test2 Service Reference 1 not returned", aServRef); + + //FIXME Port to the 1.0 spec API + //Get the session ID. + //Object aConversationID = aServRef.getSessionID(); + ConversationsLifeCycleService aConversationsLifeCycleService = (ConversationsLifeCycleService) aServRef; + aConversationsLifeCycleService.knockKnock("Hello"); + + //Create a new session this time specifying a session ID. Verify the seesion id is what was specified. + aServRef = myContext.newSession("ConversationsLifeCycleService","Test2-12345"); + Assert.assertNotNull("Conversations - Test2 Service Reference 2 not returned", aServRef); + //FIXME Port to the 1.0 spec API + //Get the session ID. + //Object aConversationID2 = aServRef.getSessionID(); + //Assert.assertEquals("Conversations - Test2 Session not created with specified ConversationID", "Test2-12345", aConversationID2); + aConversationsLifeCycleService = (ConversationsLifeCycleService) aServRef; + aConversationsLifeCycleService.knockKnock("Hello"); + + //FIXME Port to the 1.0 spec API + //Assert.assertNotSame("Conversations - Test2 sessions are not different", aConversationID, aConversationID2); + + } + + private void test3() + { + + // Note: The @EndSesion and @EndsConversation anotations are not implemented. + // So #1 an #2 cannot be done. + + // + // Verify the various methods to end a session. + // Sesssions can be ended: + // + // 1) Server operation annotated with @EndsConversation. + // 2) Server operation calls an @EndSession annotated callback method. + // 3) Servers conversation lifetime times out. This is test6() so its not implimented in the test3 method. + // 4) The client calls ServiceReference.endSession(); + // + // Verify @Destroy annotated method get called after completion of the business + // method that called the endSession. + // + + ConversationsLifeCycleService aConversationsLifeCycleService; + Object aConversationID; + myContext = CurrentCompositeContext.getContext(); + Assert.assertNotNull("current composite context",myContext); + ServiceReference aServRef; + this.removeMarkerFile(); + + // + // test3 variation #1 - Cannot be done annotation not implimented yet. 12/15/2006 + // + + aServRef = myContext.newSession("ConversationsLifeCycleService"); + Assert.assertNotNull("Conversations - Test3-1 Service Reference not returned", aServRef); + + aConversationsLifeCycleService = (ConversationsLifeCycleService) aServRef; + aConversationsLifeCycleService.knockKnock("Hello"); + //FIXME Port to the 1.0 spec API + //aConversationID = aServRef.getSessionID(); + //Assert.assertNotNull("Conversations - Test3-1 ConversationID not found", aConversationID); + + //Call the business method annotated with @EndsConversation. + aConversationsLifeCycleService.endThisSession(); // This should also drive @Destroy method. + + // Verify session has ended. The ConversationID should be null; + //FIXME Port to the 1.0 spec API + //aConversationID = aServRef.getSessionID(); + //Assert.assertNull("Conversations - Test3-1 session not null after endSession()", aConversationID); + + // Verify Destroy was run. The baxckend service creates a marker file when @Destroy annotated method is run. + Assert.assertEquals("Conversations - Test3-1 @Destroy method not invoked", true, this.isMarkerFilePresent()); + this.removeMarkerFile(); + + // + // test3 variation #2 - Cannot be done annotation not implimented yet. 12/15/2006 + // + + aServRef = myContext.newSession("ConversationsLifeCycleService"); + Assert.assertNotNull("Conversations - Test3-2 Service Reference not returned", aServRef); + + aConversationsLifeCycleService = (ConversationsLifeCycleService) aServRef; + aConversationsLifeCycleService.knockKnock("Hello"); + //FIXME Port to the 1.0 spec API + //aConversationID = aServRef.getSessionID(); + //Assert.assertNotNull("Conversations - Test3-2 ConversationID not found", aConversationID); + + //Call the business method that will invoke my @EndSession callback method. + aConversationsLifeCycleService.endThisSessionUsingCallback(); // This should also drive @Destroy method. + + // Verify session has ended. The ConversationID should be null; + //FIXME Port to the 1.0 spec API + //aConversationID = aServRef.getSessionID(); + //Assert.assertNull("Conversations - Test3-2 session not null after endSession()", aConversationID); + + // Verify Destroy was run. The baxckend service creates a marker file when @Destroy annotated method is run. + Assert.assertEquals("Conversations - Test3-2 @Destroy method not invoked", true, this.isMarkerFilePresent()); + this.removeMarkerFile(); + + // + // test3 variation #4 - Client calls endSession() + // + + aServRef = myContext.newSession("ConversationsLifeCycleService"); + Assert.assertNotNull("Conversations - Test3-4 Service Reference not returned", aServRef); + + aConversationsLifeCycleService = (ConversationsLifeCycleService) aServRef; + aConversationsLifeCycleService.knockKnock("Hello"); + //FIXME Port to the 1.0 spec API + //aConversationID = aServRef.getSessionID(); + //Assert.assertNotNull("Conversations - Test3-4 ConversationID not found", aConversationID); + + //Call the endSession() API on the Service Reference. + //FIXME Port to the 1.0 spec API + //aServRef.endSession(); // This should also drive @Destroy method. + + // Verify session has ended. The ConversationID should be null; + //FIXME Port to the 1.0 spec API + //aConversationID = aServRef.getSessionID(); + //Assert.assertNull("Conversations - Test3-4 session not null after endSession()", aConversationID); + + // Verify Destroy was run. The baxckend service creates a marker file when @Destroy annotated method is run. + Assert.assertEquals("Conversations - Test3-4 @Destroy method not invoked", true, this.isMarkerFilePresent()); + this.removeMarkerFile(); + } + + public void test4() + { + + // + // This test uses the injected active session for the ConversationsService. It starts a conversation + // in this method building up state with a counter. It then passes this reference to another backend service adding + // additional state. It then returns and adds more state using original service and then performs the Assertions. + // + + aService.initializeCount(); + aService.add(1); + anotherService.setService((ServiceReference)aService); + anotherService.add(1); + anotherService.add(1); + aService.add(1); + aService.add(1); + int count = anotherService.getCount(); + + Assert.assertEquals("test4 - ConversationsClientImpl ", 5, count); + + return; + } + + + public void test5() + { + + // The first test verifies that the createServiceReferenceForSession(this) API is functioning. + // This is done in the backend serviced as it needs a single interface defined. The 2nd test + // uses the variant of this API when > 1 interfaces are implemented. + // + // The 2nd test obtains a service reference for myself and passes that reference to a backend service. + // The backend service then invokes the count() method on my service reference. It then returns + // the count that it retrieved. The test then asserts that the count returned from the backend + // service matches the client services internal state. + // + + myContext = CurrentCompositeContext.getContext(); + Assert.assertNotNull("current composite context",myContext); + + boolean result = aService.createServiceReferenceForSelf(); + System.out.println("Laa: returned from createServiceReferenceForSelf() " + result); + Assert.assertEquals("test5 - createServiceReferenceForSelf",true,result); + + count = 6; + int returnCount = 0; + ServiceReference myServiceReference = myContext.createServiceReferenceForSession(this,"ConversationsClient2"); + Assert.assertNotNull("test5 - createServiceReferenceForSession - myContext.createServiceReferenceForSession(this,ConversationsClient);", myServiceReference); + returnCount = aService.getCount(myServiceReference); + + Assert.assertEquals("test5 - createServiceReferenceForSession(this,ConversationsClient2)",count,returnCount); + String aRemoteDateTime = aService.getDateTime(myServiceReference); + Assert.assertEquals("test5 - createServiceReferenceForSession(this,ConversationsClient2 - dateTime)", dateTime, aRemoteDateTime); + + return; + } + + public void test6() + { + + // + // Create a session and allow it to timeout and verify that it did. + // Invoking a business method on a service that has timed out should result in + // a SessionEndedException. + // + + myContext = CurrentCompositeContext.getContext(); + Assert.assertNotNull("current composite context",myContext); + + // This tests creating a conversational session. This service has a maxAge="5 seconds". + ServiceReference aServRef; + aServRef = myContext.newSession("ConversationsLifeCycleService"); + Assert.assertNotNull("Conversations - Test6 Service Reference not returned", aServRef); + + // Run a business method. + ConversationsLifeCycleService aConversationsLifeCycleService = (ConversationsLifeCycleService) aServRef; + aConversationsLifeCycleService.knockKnock("Hello"); + + // + // wait 10 seconds so session will time out. + // + try { + Thread.sleep(10000L); + } + catch (InterruptedException ex) + { + ex.printStackTrace(); + } + + // Run a busineess method after timeout period has elapsed. + boolean sessionEnded = false; + try + { + aConversationsLifeCycleService.knockKnock("Hello"); + } + catch (ConversationEndedException sex) + { + sessionEnded = true; + } + + Assert.assertEquals("Conversations - Test6 Session did not timeout ", true, sessionEnded); + + return; + } + + + public synchronized void callBackIncrement(String aString) { + + count++; + System.out.println("Laa: callBackIncrement invoked on client. count = " + count); + + } + + public synchronized void callBackMessage(String aString) { + + message = aString; + System.out.println("Laa: callBackIMessage invoked on client. message = " + message); + + } + + // @EndSession - This is for test3() variation #2. + public void callBackEndSession() { + + System.out.println("Laa: callBackEndSession method invoked on client."); + + } + + public int count() + { + return this.count; + } + + public String getDateTime() { + + dateTime = DateFormat.getDateTimeInstance().toString(); + return dateTime; + + } + + private void removeMarkerFile() + { + // Make sure the marker file is not present before starting the test. + File aFile = new File(markerFileName); + if (aFile.exists()) + aFile.delete(); + } + + private boolean isMarkerFilePresent() + { + File aFile = new File(markerFileName); + return aFile.exists(); + } + + + +} diff --git a/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsLifeCycleService.java b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsLifeCycleService.java new file mode 100644 index 0000000000..744737dacd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsLifeCycleService.java @@ -0,0 +1,20 @@ +package org.apache.tuscany.sca.test; + +import org.osoa.sca.annotations.Callback; +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.ServiceReference; + +@Remotable +@Callback(ConversationsCallback.class) + +/** + * + */ +public interface ConversationsLifeCycleService { + + public String knockKnock(String aString); + public void endThisSession(); + public void endThisSessionUsingCallback(); + +} diff --git a/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsLifeCycleServiceImpl.java b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsLifeCycleServiceImpl.java new file mode 100644 index 0000000000..61e349abed --- /dev/null +++ b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsLifeCycleServiceImpl.java @@ -0,0 +1,79 @@ +package org.apache.tuscany.sca.test; + +import java.io.File; + +import junit.framework.Assert; + +import org.osoa.sca.annotations.Callback; +import org.osoa.sca.annotations.ConversationAttributes; +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +@Service(ConversationsLifeCycleService.class) +@Scope("CONVERSATION") +@ConversationAttributes(maxAge="5 seconds") + +// This is a short-lived conversational service. + +public class ConversationsLifeCycleServiceImpl implements ConversationsLifeCycleService { + + @Callback + protected ConversationsCallback callback; + + private String state = "NOT READY"; + private final static String markerFileName = "target/testConversations_test3_marker"; + + + public String knockKnock(String aString) { + + // Prior to any business methods being invoked the state must have been set to READY using the @Init. + System.out.println("ConversationsLifeCycleServiceImpl.knockKnock - State = " + state); + Assert.assertEquals("ConversationsLifeCycleServiceImpl.knockKnock - not in READY state ", "READY", state); + + return "Who's There!"; + } + + @Init + public void init() + { + state = "READY"; + System.out.println("ConversationsLifeCycleServiceImpl.init()"); + } + + + @Destroy + public void destroy() + { + state = "DESTROYED"; + + File aFile = new File(markerFileName); + try + { + aFile.createNewFile(); + } + catch (Exception ex) + { + System.out.println("Error Creating " + markerFileName); + ex.printStackTrace(); + } + System.out.println("ConversationsLifeCycleServiceImpl.destroy()"); + } + +// @EndsConversation + public void endThisSession() { + //This method will end the current session by annotation. + System.out.println("ConversationsLifeCycleServiceImpl.endThisSession()"); + + } + + public void endThisSessionUsingCallback() { + + //This method will end the current session by a callback method annotated with @EndSession. + callback.callBackEndSession(); + System.out.println("ConversationsLifeCycleServiceImpl.endThisSessionUsingCallback()"); + } + +} + diff --git a/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsService.java b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsService.java new file mode 100644 index 0000000000..d631cf91b4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsService.java @@ -0,0 +1,24 @@ +package org.apache.tuscany.sca.test; + +import org.osoa.sca.annotations.Callback; +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.ServiceReference; + +@Remotable +@Callback(ConversationsCallback.class) + +/** + * + */ +public interface ConversationsService { + + public void knockKnock(String aString); + public void add(int anInt); + public void initializeCount(); + public int getCount(ServiceReference aServiceReference); + public int getLocalCount(); + public String getDateTime(ServiceReference aServiceReference); + public boolean createServiceReferenceForSelf(); + +} diff --git a/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsServiceImpl.java b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsServiceImpl.java new file mode 100644 index 0000000000..d764e79330 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsServiceImpl.java @@ -0,0 +1,134 @@ +package org.apache.tuscany.sca.test; + +import junit.framework.Assert; + +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; +import org.osoa.sca.RequestContext; +import org.osoa.sca.ServiceReference; +import org.osoa.sca.annotations.Callback; +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Service; +import org.osoa.sca.annotations.Context; +import org.osoa.sca.annotations.Scope; +import java.io.File; +import org.apache.tuscany.sca.test.ConversationsClient; + +@Service(ConversationsService.class) +@Scope("CONVERSATION") + +public class ConversationsServiceImpl implements ConversationsService { + + @Callback + // Note injection is not working with a private access modifier. + protected ConversationsCallback callback; + private int count=0; + + public void knockKnock(String aString) { + + try + { + count++; + //System.out.println("ConversationsServiceImpl message received: " + aString); + callback.callBackMessage("Who's There " + count); + callback.callBackIncrement("Add one please"); + //System.out.println("ConversationsServiceImpl responses sent"); + return; + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + } + + public int getCount(ServiceReference aServiceReference) + { + + // + // Invoke a method on the service reference and return back the result. + // + + int count=0; + try + { + count = ((ConversationsClient) aServiceReference).count(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + return count; + + } + + public int getLocalCount() + { + + // + // Return my localc instance count. This is used for test4. + // + + return count; + + } + + public String getDateTime(ServiceReference aServiceReference) + { + + // + // Invoke a method on the service reference and return back the result. + // + + String dateTime; + dateTime = ((ConversationsClient2) aServiceReference).getDateTime(); + return dateTime; + + } + + public void add(int anInt) { + + count +=anInt; + + } + + public void initializeCount() { + + count =0; + + } + + public boolean createServiceReferenceForSelf() { + + // This is done here because we need to test getting a ServiceReference + // from a component that implements a single interface. The client in this test + // impliments 2 interfaces to test the variant of this that takes interface name as an argumnet. + + boolean aBoolean = false; + + ServiceReference myServiceReference = null; + CompositeContext ctx = CurrentCompositeContext.getContext(); + + try + { + myServiceReference = ctx.createServiceReferenceForSession(this); + System.out.println("Laa: Created Service Reference for Session:" + myServiceReference); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + + if (myServiceReference != null) + { + aBoolean = true; + System.out.println("Laa: Service Reference is not null"); + } + + return aBoolean; + } + + +} + diff --git a/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/resources/ConversationsTest.composite b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/resources/ConversationsTest.composite new file mode 100644 index 0000000000..266cd8b386 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/main/resources/ConversationsTest.composite @@ -0,0 +1,48 @@ +<?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. +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + name="ConversationsTest"> + + <component name="ConversationsClient"> + <implementation.java class="org.apache.tuscany.sca.test.ConversationsClientImpl"/> + <reference name="aService"> + ConversationsService + </reference> + <reference name="anotherService"> + AnotherService + </reference> + <reference name="aLifeCycleService"> + ConversationLifeCycleService + </reference> + </component> + + <component name="ConversationsService"> + <implementation.java class="org.apache.tuscany.sca.test.ConversationsServiceImpl"/> + </component> + + <component name="AnotherService"> + <implementation.java class="org.apache.tuscany.sca.test.AnotherServiceImpl"/> + </component> + + <component name="ConversationLifeCycleService"> + <implementation.java class="org.apache.tuscany.sca.test.ConversationsLifeCycleServiceImpl"/> + </component> + +</composite> diff --git a/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/test/java/org/apache/tuscany/sca/test/ConversationsTest.java b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/test/java/org/apache/tuscany/sca/test/ConversationsTest.java new file mode 100644 index 0000000000..3fb753cbf7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-integration/testing/sca/itest/conversations/src/test/java/org/apache/tuscany/sca/test/ConversationsTest.java @@ -0,0 +1,27 @@ +package org.apache.tuscany.sca.test; + +import junit.framework.TestCase; + +import org.apache.tuscany.api.SCARuntime; +import org.osoa.sca.CurrentCompositeContext; + +public class ConversationsTest extends TestCase { + + private ConversationsClient aConversationsClient; + + public void testConversations() { + aConversationsClient.run(); + } + + protected void setUp() throws Exception { + SCARuntime.start("ConversationsTest.composite"); + + aConversationsClient = CurrentCompositeContext.getContext().locateService(ConversationsClient.class, "ConversationsClient/org.apache.tuscany.sca.test.ConversationsClient"); + + } + + protected void tearDown() throws Exception { + SCARuntime.stop(); + } + +} |