1   package org.seasar.remoting.rmi.adaptor;
2   
3   import junit.framework.Test;
4   import junit.framework.TestSuite;
5   
6   import org.seasar.extension.unit.S2TestCase;
7   import org.seasar.framework.beans.MethodNotFoundRuntimeException;
8   import org.seasar.framework.container.TooManyRegistrationRuntimeException;
9   
10  /***
11   * @author murata
12   */
13  public class RMIAdaptorImplTest extends S2TestCase {
14      private static String PATH = "test.dicon";
15  
16      //変数の自動セット
17      private RMIAdaptorImpl adaptor;
18  
19      public void testInvoke() throws Exception {
20          assertEquals("Hello!", adaptor.invoke("hello", "say", null));
21      }
22  
23      public void testInvoke1() throws Exception {
24          try {
25              adaptor.invoke("hello1", "say", null);
26              fail();
27          } catch (Exception e) {
28              assertEquals(
29                      org.seasar.framework.container.ComponentNotFoundRuntimeException.class,
30                      e.getCause().getClass());
31          }
32      }
33  
34      public void testInvoke2() throws Exception {
35          try {
36              adaptor.invoke("hello2", "say", null);
37              fail();
38          } catch (Exception e) {
39              assertEquals(TooManyRegistrationRuntimeException.class, e
40                      .getCause().getClass());
41          }
42      }
43  
44      public void testInvoke3() throws Exception {
45          try {
46              adaptor.invoke("hello", "hello", null);
47              fail();
48          } catch (Exception e) {
49              assertEquals(MethodNotFoundRuntimeException.class, e.getCause()
50                      .getClass());
51          }
52      }
53  
54      public void testInvoke4() throws Exception {
55          try {
56              String[] args = { "hello" };
57              adaptor.invoke("hello", "say", args);
58              fail();
59          } catch (Exception e) {
60              assertEquals(MethodNotFoundRuntimeException.class, e.getCause()
61                      .getClass());
62          }
63      }
64  
65      public void testInvoke5() throws Exception {
66          adaptor.setInvoker(null);
67          try {
68              adaptor.invoke("hello", "say", null);
69              fail();
70          } catch (Exception e) {
71              assertEquals(NullPointerException.class, e.getCause().getClass());
72          }
73      }
74  
75      protected void setUp() throws Exception {
76          //S2Containerに対するinclude()メソッド
77          include(PATH);
78      }
79  
80      protected void tearDown() throws Exception {
81      }
82  
83      public RMIAdaptorImplTest(String arg0) {
84          super(arg0);
85      }
86  
87      public static Test suite() {
88          return new TestSuite(RMIAdaptorImplTest.class);
89      }
90  
91      public static void main(String[] args) {
92          junit.textui.TestRunner.run(suite());
93      }
94  
95      interface Hello {
96          public String say();
97      }
98  }