2 * Copyright 2005-2010 the original author or authors.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.wamblee.system.adapters;
18 import java.util.Collections;
19 import java.util.List;
21 import org.wamblee.system.core.DefaultProvidedInterface;
22 import org.wamblee.system.core.ProvidedInterface;
23 import org.wamblee.system.core.RequiredInterface;
24 import org.wamblee.system.core.RequiredInterfaceComparator;
25 import org.wamblee.system.core.Scope;
26 import org.wamblee.test.AssertionUtils;
33 public class ClassConfigurationTest extends AdapterTestCase {
34 public void testConstructorConfig() {
35 ClassConfiguration classConfig = new ClassConfiguration(X1.class);
37 ProvidedInterface provided = new DefaultProvidedInterface("arg",
39 List<RequiredInterface> required = classConfig.getRequiredInterfaces();
41 assertEquals(1, required.size());
42 assertFalse(required.get(0).isOptional());
44 required.get(0).setProvider(provided);
46 getScope().publishInterface(provided, "hello");
47 classConfig.create(getScope());
49 AssertionUtils.assertEquals(new String[] { "x1(hello)" },
50 AdapterTestCase.getEventTracker().getEvents(Thread.currentThread())
54 public void testConstructorConfigWithSetters() {
55 ClassConfiguration classConfig = new ClassConfiguration(X7.class);
57 classConfig.getConstructorConfig().select(Boolean.class);
58 classConfig.getObjectConfig().getSetterConfig().initAllSetters()
59 .values("setPort").setValue(0, 10);
61 ProvidedInterface providedBoolean = new DefaultProvidedInterface(
62 "boolean", Boolean.class);
63 ProvidedInterface providedHost = new DefaultProvidedInterface("host",
65 List<RequiredInterface> required = classConfig.getRequiredInterfaces();
67 Collections.sort(required, new RequiredInterfaceComparator());
68 assertEquals(2, required.size());
69 assertEquals("arg0", required.get(0).getName());
71 required.get(0).setProvider(providedBoolean);
72 required.get(1).setProvider(providedHost);
74 Scope scope = getScope();
75 scope.publishInterface(providedBoolean, true);
76 scope.publishInterface(providedHost, "host.name.org");
78 Object obj = classConfig.create(scope);
79 assertTrue(obj instanceof X7);
82 assertNotNull(x7.getBoolean());
83 assertTrue(x7.getBoolean());
84 assertNull(x7.getHost());
85 assertNull(x7.getPort());
87 classConfig.inject(scope, obj);
89 assertEquals("host.name.org", x7.getHost());
90 assertEquals(10, x7.getPort().intValue());