1   /*
2    * Created on Jan 22, 2004
3    *
4    */
5   package org.neo.swarm.interceptor.appContext;
6   
7   import java.lang.reflect.Method;
8   
9   import junit.framework.TestCase;
10  
11  import org.neo.swarm.ApplicationContext;
12  import org.neo.swarm.core.aop.silc.comp.Invocation;
13  import org.neo.swarm.interceptor.appContext.GetMethodInterceptor;
14  
15  import com.mockobjects.dynamic.C;
16  import com.mockobjects.dynamic.Mock;
17  
18  /***
19   * This filters remote calls from AC->get(blah) => AC->getInterceptor(blah); 
20   *  @author navery
21   */
22  public class GetMethodInterceptorTest extends TestCase {
23  	
24  //	public void testThatGetConvertsToGetInterceptor() throws Exception, Throwable {
25  //		
26  //		Mock invocation = new Mock(Invocation.class);
27  //		Method method = ApplicationContext.class.getMethod("retrieveComponent", new Class[] { Perspective.class, Object.class });
28  //		invocation.expectAndReturn("getArgs", C.NO_ARGS, new Object[] { "dummy"} );		
29  //		invocation.expect("setArgs", C.ANY_ARGS);		
30  //		invocation.expect("setMethod", method);
31  //		invocation.expectAndReturn("getMethod", method);		
32  //		invocation.expect("invokeNext");
33  //		GetMethodConvertor acGC = new GetMethodConvertor();
34  //		acGC.getInterceptor().invoke((Invocation) invocation.proxy());
35  //		invocation.verify();
36  //	}
37  
38  	public void testConversionOfRetrieveComponent() throws Throwable {
39  		Method method = ApplicationContext.class.getMethod("retrieveComponent", new Class[] { Object.class });
40  		
41  		Mock invocation = new Mock(Invocation.class);
42  		
43  		invocation.expectAndReturn("getMethod", method);
44  		invocation.expectAndReturn("getArguments", new Object[] { "objectKey"});
45  		
46  		invocation.expectAndReturn("getArguments", new Object[] { "objectKey"});
47  		invocation.expect("setMethod", C.ANY_ARGS);
48  		invocation.expect("setArguments", C.ANY_ARGS);
49  		invocation.expect("proceed", C.ANY_ARGS);
50  		
51  		GetMethodInterceptor getInterceptor = new GetMethodInterceptor();
52  		getInterceptor.invoke((Invocation) invocation.proxy());
53  		
54  		invocation.verify();
55  	}
56  	
57  	public void testConversionOfRetrieveComponentsOfType() throws Throwable {
58  		Method method = ApplicationContext.class.getMethod("retrieveComponentsOfType", new Class[] { Class.class });
59  		
60  		Mock invocation = new Mock(Invocation.class);
61  		
62  		invocation.expectAndReturn("getMethod", method);
63  		invocation.expectAndReturn("getArguments", new Object[] { "objectKey"});
64  		invocation.expectAndReturn("getArguments", new Object[] { "objectKey"});
65  		invocation.expect("setMethod", C.ANY_ARGS);
66  		invocation.expect("setArguments", C.ANY_ARGS);
67  		invocation.expect("proceed", C.ANY_ARGS);
68  		
69  		GetMethodInterceptor getInterceptor = new GetMethodInterceptor();
70  		getInterceptor.invoke((Invocation) invocation.proxy());
71  		
72  		invocation.verify();
73  	}
74  }