KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > aop > target > PrototypeTargetSourceTests


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.aop.target;
18
19 import junit.framework.TestCase;
20
21 import org.springframework.aop.interceptor.SideEffectBean;
22 import org.springframework.beans.factory.BeanFactory;
23 import org.springframework.beans.factory.xml.XmlBeanFactory;
24 import org.springframework.core.io.ClassPathResource;
25
26 /**
27  * @author Rod Johnson
28  */

29 public class PrototypeTargetSourceTests extends TestCase {
30     
31     /** Initial count value set in bean factory XML */
32     private static final int INITIAL_COUNT = 10;
33     
34     private BeanFactory beanFactory;
35     
36     protected void setUp() throws Exception JavaDoc {
37         this.beanFactory = new XmlBeanFactory(new ClassPathResource("prototypeTests.xml", getClass()));
38     }
39
40     /**
41      * Test that multiple invocations of the prototype bean will result
42      * in no change to visible state, as a new instance is used.
43      * With the singleton, there will be change.
44      */

45     public void testPrototypeAndSingletonBehaveDifferently() {
46         SideEffectBean singleton = (SideEffectBean) beanFactory.getBean("singleton");
47         assertEquals(INITIAL_COUNT, singleton.getCount() );
48         singleton.doWork();
49         assertEquals(INITIAL_COUNT + 1, singleton.getCount() );
50         
51         SideEffectBean prototype = (SideEffectBean) beanFactory.getBean("prototype");
52         assertEquals(INITIAL_COUNT, prototype.getCount() );
53         prototype.doWork();
54         assertEquals(INITIAL_COUNT, prototype.getCount() );
55     }
56
57
58 }
59
Popular Tags