1   /*** 
2    * 
3    * Copyright 2005 LogicBlaze, Inc.
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * You may obtain a copy of the License at 
8    * 
9    * http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License. 
16   * 
17   **/
18  package org.logicblaze.lingo.example;
19  
20  import org.logicblaze.lingo.SpringTestSupport;
21  
22  /***
23   * A simple test case which tests the use of Lingo from Spring using the Spring XML deployment descriptor
24   *
25   * @version $Revision: 1.7 $
26   */
27  public class ExampleTest extends SpringTestSupport {
28  
29      public void TODO_testAsyncRequestResponse() throws Exception {
30          // START SNIPPET: async
31  
32          // lets lookup the client in Spring
33          // (we could be using DI here instead)
34          ExampleService service = (ExampleService) getBean("client");
35  
36          // async request-response
37          TestResultListener listener = new TestResultListener();
38          service.asyncRequestResponse("IBM", listener);
39  
40          // the server side will now invoke the listener
41          // objects's methods asynchronously
42          // END SNIPPET: async
43  
44          listener.waitForAsyncResponses(2);
45  
46          System.out.println("Found results: " + listener.getResults());
47      }
48  
49      public void testSyncRequestResponse() throws Exception {
50          // START SNIPPET: simple
51  
52          // lets lookup the client in Spring
53          // (we could be using DI here instead)
54          ExampleService service = (ExampleService) getBean("client");
55  
56          // regular synchronous request-response
57          int i = service.regularRPC("Foo");
58          System.out.println("Found result: " + i);
59      }
60  
61      public void testOneWayMethodCall() throws Exception {
62          ExampleServiceImpl serverImpl = (ExampleServiceImpl) getBean("serverImpl");
63  
64          callOneWayMethod();
65  
66          serverImpl.assertOneWayCalled();
67      }
68  
69      protected void callOneWayMethod() {
70          ExampleService service = (ExampleService) getBean("client");
71  
72          long start = System.currentTimeMillis();
73          service.someOneWayMethod("James", 35);
74          logTime("Method invocation took", System.currentTimeMillis() - start);
75          System.out.println("### client side method invoked");
76      }
77  
78      protected void logTime(String text, long millis) {
79          System.out.println(text + " took: " + (millis) + " milli(s) to complete");
80      }
81  
82      protected void setUp() throws Exception {
83          super.setUp();
84  
85          // lets force the creation of the server side
86          getBean("server");
87      }
88  
89      protected String getApplicationContextXml() {
90          return "org/logicblaze/lingo/example/spring.xml";
91      }
92  }