KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > beans > factory > xml > LookupMethodWrappedByCglibProxyTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.beans.factory.xml;
18
19 import org.springframework.aop.interceptor.DebugInterceptor;
20 import org.springframework.beans.ITestBean;
21 import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
22
23 /**
24  * Tests lookup methods wrapped by a CGLIB proxy (see SPR-391).
25  *
26  * @author Rod Johnson
27  */

28 public class LookupMethodWrappedByCglibProxyTests extends AbstractDependencyInjectionSpringContextTests {
29
30     protected String JavaDoc[] getConfigLocations() {
31         return new String JavaDoc[] {"/org/springframework/beans/factory/xml/overloadOverrides.xml"};
32     }
33
34     protected void onSetUp() {
35         resetInterceptor();
36     }
37
38     public void testAutoProxiedLookup() {
39         OverloadLookup olup = (OverloadLookup) applicationContext.getBean("autoProxiedOverload");
40         ITestBean jenny = olup.newTestBean();
41         assertEquals("Jenny", jenny.getName());
42         assertEquals("foo", olup.testMethod());
43         assertInterceptorCount(2);
44     }
45
46     public void testRegularlyProxiedLookup() {
47         OverloadLookup olup = (OverloadLookup) applicationContext.getBean("regularlyProxiedOverload");
48         ITestBean jenny = olup.newTestBean();
49         assertEquals("Jenny", jenny.getName());
50         assertEquals("foo", olup.testMethod());
51         assertInterceptorCount(2);
52     }
53
54     private void assertInterceptorCount(int count) {
55         DebugInterceptor interceptor = getInterceptor();
56         assertEquals("Interceptor count is incorrect", count, interceptor.getCount());
57     }
58
59     private void resetInterceptor() {
60         DebugInterceptor interceptor = getInterceptor();
61         interceptor.resetCount();
62     }
63
64     private DebugInterceptor getInterceptor() {
65         return (DebugInterceptor) applicationContext.getBean("interceptor");
66     }
67
68
69     public static abstract class OverloadLookup {
70
71         public abstract ITestBean newTestBean();
72
73         public String JavaDoc testMethod() {
74             return "foo";
75         }
76     }
77
78 }
79
Popular Tags