2 * Copyright 2008 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 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.SystemAssemblyException;
23 import org.wamblee.test.AssertionUtils;
25 import java.util.List;
34 public class ConstructorConfigurationTest extends AdapterTestCase {
38 public void testGreedyUnique() {
39 ConstructorConfiguration config = new ConstructorConfiguration(X1.class)
41 ProvidedInterface provided = new DefaultProvidedInterface("arg",
43 List<RequiredInterface> required = config.getRequiredInterfaces();
45 assertEquals(1, required.size());
46 assertFalse(required.get(0).isOptional());
48 required.get(0).setProvider(provided);
50 scope.publishInterface(provided, "hello");
53 AssertionUtils.assertEquals(new String[] { "x1(hello)" },
54 AdapterTestCase.EVENT_TRACKER.getEvents(Thread.currentThread())
61 public void testGreedyNonUnique() {
63 ConstructorConfiguration config = new ConstructorConfiguration(X2.class)
65 } catch (SystemAssemblyException e) {
66 // e.printStackTrace();
76 public void testSpecificConstructor() {
77 ConstructorConfiguration config = new ConstructorConfiguration(X2.class)
78 .select(String.class);
79 ProvidedInterface provided = new DefaultProvidedInterface("arg",
81 List<RequiredInterface> required = config.getRequiredInterfaces();
83 assertEquals(1, required.size());
84 required.get(0).setProvider(provided);
86 scope.publishInterface(provided, "hello");
89 AssertionUtils.assertEquals(new String[] { "x2(hello)" },
90 AdapterTestCase.EVENT_TRACKER.getEvents(Thread.currentThread())
97 public void testSetValue() {
98 ConstructorConfiguration config = new ConstructorConfiguration(X1.class)
100 config.getParameters().setValue(0, "bla");
102 config.create(scope);
104 AssertionUtils.assertEquals(new String[] { "x1(bla)" },
105 AdapterTestCase.EVENT_TRACKER.getEvents(Thread.currentThread())
112 public void testOptionalValueProvided() {
113 ConstructorConfiguration config = new ConstructorConfiguration(X1.class)
115 config.getParameters().setOptional(0);
117 ProvidedInterface provided = new DefaultProvidedInterface("arg",
119 List<RequiredInterface> required = config.getRequiredInterfaces();
121 assertEquals(1, required.size());
122 required.get(0).setProvider(provided);
124 scope.publishInterface(provided, "hello");
125 config.create(scope);
127 AssertionUtils.assertEquals(new String[] { "x1(hello)" },
128 AdapterTestCase.EVENT_TRACKER.getEvents(Thread.currentThread())
135 public void testOptionalValueMissing() {
136 ConstructorConfiguration config = new ConstructorConfiguration(X1.class)
138 config.getParameters().setOptional(0);
139 assertTrue(config.getRequiredInterfaces().get(0).isOptional());
141 config.create(scope);
143 AssertionUtils.assertEquals(new String[] { "x1(null)" },
144 AdapterTestCase.EVENT_TRACKER.getEvents(Thread.currentThread())
151 public void testIgnoredNonPublic() {
152 ConstructorConfiguration config = new ConstructorConfiguration(X3.class)
154 List<RequiredInterface> required = config.getRequiredInterfaces();
155 assertEquals(0, config.getParameters().getTypes().length);
161 public void testNonPublicConstructor() {
162 ConstructorConfiguration config = new ConstructorConfiguration(X3.class).setNonPublic(true)
164 ProvidedInterface provided = new DefaultProvidedInterface("arg",
166 List<RequiredInterface> required = config.getRequiredInterfaces();
168 assertEquals(1, required.size());
169 assertFalse(required.get(0).isOptional());
171 required.get(0).setProvider(provided);
173 scope.publishInterface(provided, "hello");
174 config.create(scope);
176 AssertionUtils.assertEquals(new String[] { "x3(hello)" },
177 AdapterTestCase.EVENT_TRACKER.getEvents(Thread.currentThread())