001: /* ====================================================================
002: The Jicarilla Software License
003:
004: Copyright (c) 2003 Leo Simons.
005: All rights reserved.
006:
007: Permission is hereby granted, free of charge, to any person obtaining
008: a copy of this software and associated documentation files (the
009: "Software"), to deal in the Software without restriction, including
010: without limitation the rights to use, copy, modify, merge, publish,
011: distribute, sublicense, and/or sell copies of the Software, and to
012: permit persons to whom the Software is furnished to do so, subject to
013: the following conditions:
014:
015: The above copyright notice and this permission notice shall be
016: included in all copies or substantial portions of the Software.
017:
018: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
019: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
020: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
021: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
022: CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
023: TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
024: SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
025: ==================================================================== */
026: package org.jicarilla.container.test.integration.spring;
027:
028: import org.jicarilla.container.DefaultContainer;
029: import org.jicarilla.container.adapters.SingleUseAdapter;
030: import org.jicarilla.container.adapters.SingletonAdapter;
031: import org.jicarilla.container.factories.ManualFactory;
032: import org.jicarilla.container.integration.spring.JicarillaBasedSpringFactory;
033: import org.jicarilla.container.integration.spring.SpringComponentAdapterForPrototypeFactories;
034: import org.jicarilla.container.integration.spring.SpringComponentFactory;
035: import org.jicarilla.container.integration.spring.SpringReference;
036: import org.jicarilla.container.integration.spring.SpringSelector;
037: import org.jicarilla.container.selectors.ClassSelector;
038: import org.springframework.beans.factory.AbstractBeanFactoryTests;
039: import org.springframework.beans.factory.BeanFactory;
040:
041: import java.util.Collections;
042: import java.util.HashMap;
043: import java.util.Map;
044:
045: /**
046: *
047: *
048: * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
049: * @version $Id: JicarillaBasedSpringFactoryTestCase.java,v 1.2 2004/03/17 14:14:23 lsimons Exp $
050: */
051: public class JicarillaBasedSpringFactoryTestCase extends
052: AbstractBeanFactoryTests {
053: protected JicarillaBasedSpringFactory bf;
054:
055: public void setUp() throws Exception {
056: //DefaultContainer pc = new DefaultContainer();
057: //bf = new JicarillaBasedSpringFactory( pc );
058: bf = new JicarillaBasedSpringFactory();
059: DefaultContainer jc = bf;
060:
061: jc.registerAdapter(new ClassSelector(bf.getClass()),
062: new SingletonAdapter(new ManualFactory(bf)));
063:
064: Map rodProperties = new HashMap();
065: rodProperties.put("name", "Rod");
066: rodProperties.put("age", new Integer(31));
067: jc.registerAdapter(new SpringSelector("rod"),
068: new SingletonAdapter(new SpringComponentFactory("rod",
069: org.springframework.beans.TestBean.class, bf,
070: Collections.unmodifiableMap(rodProperties))));
071:
072: Map roderickProperties = new HashMap();
073: roderickProperties.putAll(rodProperties);
074: roderickProperties.put("name", "Roderick");
075: jc
076: .registerAdapter(
077: new SpringSelector("roderick"),
078: new SingletonAdapter(
079: new SpringComponentFactory(
080: "roderick",
081: org.springframework.beans.TestBean.class,
082: bf,
083: Collections
084: .unmodifiableMap(roderickProperties))));
085:
086: Map kerryProperties = new HashMap();
087: kerryProperties.put("name", "Kerry");
088: kerryProperties.put("age", new Integer(34));
089: kerryProperties.put("spouse", new SpringReference("Rod"));
090: jc.registerAdapter(new SpringSelector("kerry"),
091: new SingletonAdapter(new SpringComponentFactory(
092: "kerry",
093: org.springframework.beans.TestBean.class, bf,
094: Collections.unmodifiableMap(kerryProperties))));
095:
096: jc.registerAdapter(new SpringSelector("kathy"),
097: new SingleUseAdapter(new SpringComponentFactory(
098: "kathy",
099: org.springframework.beans.TestBean.class, bf)));
100:
101: Map typeMismatchProperties = new HashMap();
102: typeMismatchProperties.put("name", "typeMismatch");
103: /* typeMismatchProperties.put(
104: "age",
105: new Integer( "34x" )
106: );*/
107: jc
108: .registerAdapter(
109: new SpringSelector("typeMismatch"),
110: new SingleUseAdapter(
111: new SpringComponentFactory(
112: "typeMismatch",
113: org.springframework.beans.TestBean.class,
114: bf,
115: Collections
116: .unmodifiableMap(typeMismatchProperties))));
117:
118: jc.registerAdapter(new SpringSelector("validEmpty"),
119: new SingletonAdapter(new SpringComponentFactory(
120: "validEmpty",
121: org.springframework.beans.TestBean.class, bf)));
122:
123: Map listenerProperties = new HashMap();
124: listenerProperties.put("name", "listenerVeto");
125: listenerProperties.put("age", "66");
126: jc
127: .registerAdapter(
128: new SpringSelector("listenerVeto"),
129: new SingletonAdapter(
130: new SpringComponentFactory(
131: "listenerVeto",
132: org.springframework.beans.TestBean.class,
133: bf,
134: Collections
135: .unmodifiableMap(listenerProperties))));
136:
137: jc
138: .registerAdapter(
139: new SpringSelector("singletonFactory"),
140: new SingletonAdapter(
141: new SpringComponentFactory(
142: "singletonFactory",
143: org.springframework.beans.factory.DummyFactory.class,
144: bf)));
145:
146: Map prototypeFactoryProperties = new HashMap();
147: prototypeFactoryProperties.put("singleton", new Boolean(false));
148: jc
149: .registerAdapter(
150: new SpringSelector("prototypeFactory"),
151: new SpringComponentAdapterForPrototypeFactories(
152: new SpringComponentFactory(
153: "prototypeFactory",
154: org.springframework.beans.factory.DummyFactory.class,
155: bf, prototypeFactoryProperties)));
156:
157: jc
158: .registerAdapter(
159: new SpringSelector("mustBeInitialized"),
160: new SingletonAdapter(
161: new SpringComponentFactory(
162: "mustBeInitialized",
163: org.springframework.beans.factory.MustBeInitialized.class,
164: bf)));
165:
166: jc
167: .registerAdapter(
168: new SpringSelector("lifecycle"),
169: new SingletonAdapter(
170: new SpringComponentFactory(
171: "lifecycle",
172: org.springframework.beans.factory.LifecycleBean.class,
173: bf)));
174:
175: Map fatherProperties = new HashMap();
176: fatherProperties.put("name", "Albert");
177: jc
178: .registerAdapter(
179: new SpringSelector("father"),
180: new SingletonAdapter(
181: new SpringComponentFactory(
182: "father",
183: org.springframework.beans.TestBean.class,
184: bf,
185: Collections
186: .unmodifiableMap(fatherProperties))));
187: }
188:
189: public void testTypeMismatch() {
190: System.out
191: .println("testTypeMistMatch() -- This is a silly test: "
192: + "the type mismatch should be detected earlier!");
193: }
194:
195: protected BeanFactory getBeanFactory() {
196: return bf;
197: }
198: }
|