Removed DOCUMENT ME comments that were generated and applied source code
[utils] / system / general / src / test / java / org / wamblee / system / adapters / ClassConfigurationTest.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.DefaultProvidedInterface;
19 import org.wamblee.system.core.ProvidedInterface;
20 import org.wamblee.system.core.RequiredInterface;
21 import org.wamblee.system.core.RequiredInterfaceComparator;
22
23 import org.wamblee.test.AssertionUtils;
24
25 import java.util.Collections;
26 import java.util.List;
27
28 /**
29  * 
30  * @author $author$
31  * @version $Revision$
32  */
33 public class ClassConfigurationTest extends AdapterTestCase {
34     public void testConstructorConfig() {
35         ClassConfiguration classConfig = new ClassConfiguration(X1.class);
36
37         ConstructorConfiguration config = classConfig.getConstructorConfig()
38             .greedy();
39
40         ProvidedInterface provided = new DefaultProvidedInterface("arg",
41             String.class);
42         List<RequiredInterface> required = classConfig.getRequiredInterfaces();
43
44         assertEquals(1, required.size());
45         assertFalse(required.get(0).isOptional());
46
47         required.get(0).setProvider(provided);
48
49         scope.publishInterface(provided, "hello");
50         classConfig.create(scope);
51
52         AssertionUtils.assertEquals(new String[] { "x1(hello)" },
53             AdapterTestCase.EVENT_TRACKER.getEvents(Thread.currentThread())
54                 .toArray());
55     }
56
57     public void testConstructorConfigWithSetters() {
58         ClassConfiguration classConfig = new ClassConfiguration(X7.class);
59
60         classConfig.getConstructorConfig().select(Boolean.class);
61         classConfig.getObjectConfig().getSetterConfig().initAllSetters()
62             .values("setPort").setValue(0, 10);
63
64         ProvidedInterface providedBoolean = new DefaultProvidedInterface(
65             "boolean", Boolean.class);
66         ProvidedInterface providedHost = new DefaultProvidedInterface("host",
67             String.class);
68         List<RequiredInterface> required = classConfig.getRequiredInterfaces();
69
70         Collections.sort(required, new RequiredInterfaceComparator());
71         assertEquals(2, required.size());
72         assertEquals("arg0", required.get(0).getName());
73
74         required.get(0).setProvider(providedBoolean);
75         required.get(1).setProvider(providedHost);
76
77         scope.publishInterface(providedBoolean, true);
78         scope.publishInterface(providedHost, "host.name.org");
79
80         Object obj = classConfig.create(scope);
81         assertTrue(obj instanceof X7);
82
83         X7 x7 = (X7) obj;
84         assertNotNull(x7.getBoolean());
85         assertTrue(x7.getBoolean());
86         assertNull(x7.getHost());
87         assertNull(x7.getPort());
88
89         classConfig.inject(scope, obj);
90
91         assertEquals("host.name.org", x7.getHost());
92         assertEquals(10, x7.getPort().intValue());
93     }
94 }