(no commit message)
[utils] / system / general / src / test / java / org / wamblee / system / adapters / ClassAdapterTest.java
1 /*
2  * Copyright 2008 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 package org.wamblee.system.adapters;
17
18 import org.wamblee.system.core.Component;
19 import org.wamblee.system.core.Container;
20 import org.wamblee.system.core.ProvidedInterface;
21 import org.wamblee.system.core.RequiredInterface;
22 import org.wamblee.system.core.Scope;
23 import org.wamblee.test.AssertionUtils;
24
25 public class ClassAdapterTest extends AdapterTestCase {
26
27
28         public void testSimpleConstructorInjection() { 
29                 ClassConfiguration x1Config = new ClassConfiguration(X1.class);
30                 x1Config.getConstructorConfig().getParameters().setValue(0, "hello");
31         ClassConfiguration x4Config = new ClassConfiguration(X4.class); 
32         
33         ClassAdapter x1Adapter = new ClassAdapter("x1", x1Config);
34         ClassAdapter x4Adapter = new ClassAdapter("x4", x4Config);
35         
36         Container container = new Container("top", new Component[] { 
37                         x1Adapter, x4Adapter
38             }, new ProvidedInterface[0], new RequiredInterface[0]);
39         
40         Scope scope = container.start();
41         AssertionUtils.assertEquals(new String[] { "x1(hello)", "x4(x1)" },
42                         EVENT_TRACKER.getEvents(Thread.currentThread()).toArray());
43         
44         Object obj = scope.getRuntime(x1Adapter);
45         assertTrue(obj instanceof X1); 
46         obj = scope.getRuntime(x4Adapter);
47         assertTrue(obj instanceof X4);
48         }
49 }