Removed DOCUMENT ME comments that were generated and applied source code
[utils] / system / general / src / test / java / org / wamblee / system / container / ContainerTest.java
1 /*
2  * Copyright 2007 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.container;
17
18 import junit.framework.TestCase;
19
20 import org.wamblee.general.Pair;
21
22 import org.wamblee.system.core.Component;
23 import org.wamblee.system.core.DefaultProvidedInterface;
24 import org.wamblee.system.core.DefaultRequiredInterface;
25 import org.wamblee.system.core.DefaultScope;
26 import org.wamblee.system.core.Environment;
27 import org.wamblee.system.core.ProvidedInterface;
28 import org.wamblee.system.core.RequiredInterface;
29 import org.wamblee.system.core.Scope;
30 import org.wamblee.system.core.StringComponent;
31 import org.wamblee.system.core.SystemAssemblyException;
32
33 import org.wamblee.test.AssertionUtils;
34 import org.wamblee.test.EventTracker;
35
36 import java.io.Serializable;
37
38 import java.util.ArrayList;
39 import java.util.List;
40
41 /**
42  * 
43  * @author $author$
44  * @version $Revision$
45  */
46 public class ContainerTest extends TestCase {
47     private EventTracker<String> tracker;
48
49     @Override
50     protected void setUp() throws Exception {
51         super.setUp();
52         tracker = new EventTracker<String>();
53     }
54
55     private List<Pair<ProvidedInterface, Component>> createProvidedInput(
56         ProvidedInterface[] aProvided, Component aProvider) {
57         List<Pair<ProvidedInterface, Component>> result = new ArrayList<Pair<ProvidedInterface, Component>>();
58
59         for (ProvidedInterface provided : aProvided) {
60             result.add(new Pair<ProvidedInterface, Component>(provided,
61                 aProvider));
62         }
63
64         return result;
65     }
66
67     public void testEnvironmentApplication() {
68         Environment environment = new Environment(tracker);
69         Application application = new Application(tracker);
70         Container container = new Container("root", new Component[] {
71             environment, application }, new ProvidedInterface[0],
72             new RequiredInterface[0]);
73         Scope scope = container.start();
74         assertTrue(container.isSealed());
75         AssertionUtils.assertEquals(new String[] { "start.environment",
76             "start.application" }, tracker.getEvents(Thread.currentThread())
77             .toArray(new String[0]));
78         assertEquals(0, scope.getProvidedInterfaces().size());
79
80         assertEquals(environment.getString(), application.getString());
81         assertEquals(environment.getInteger(), application.getInteger());
82     }
83
84     public void testEnvironmentApplicationSimpleConstructor() {
85         Environment environment = new Environment(tracker);
86         Application application = new Application(tracker);
87         Container container = new Container("root").addComponent(environment)
88             .addComponent(application);
89
90         Scope scope = container.start();
91         AssertionUtils.assertEquals(new String[] { "start.environment",
92             "start.application" }, tracker.getEvents(Thread.currentThread())
93             .toArray(new String[0]));
94         assertEquals(0, scope.getProvidedInterfaces().size());
95
96         assertEquals(environment.getString(), application.getString());
97         assertEquals(environment.getInteger(), application.getInteger());
98     }
99
100     public void testApplicationEnvironment() {
101         try {
102             Component<?> environment = new Environment();
103             Component<?> application = new Application();
104             Container container = new Container("root", new Component[] {
105                 application, environment }, new ProvidedInterface[0],
106                 new RequiredInterface[0]);
107             container.start();
108         } catch (SystemAssemblyException e) {
109             // e.printStackTrace();
110             return;
111         }
112
113         fail();
114     }
115
116     public void testComposite() {
117         Component<?> environment = new Environment(tracker);
118         Component<?> application = new Application(tracker);
119         assertEquals(0, tracker.getEventCount());
120
121         Container system = new Container("all", new Component[] { environment,
122             application }, new ProvidedInterface[0], new RequiredInterface[0]);
123         Scope runtime = system.start();
124         List<RequiredInterface> required = system.getRequiredInterfaces();
125         assertEquals(0, required.size());
126
127         List<ProvidedInterface> provided = system.getProvidedInterfaces();
128         assertEquals(0, provided.size());
129
130         AssertionUtils.assertEquals(new String[] { "start.environment",
131             "start.application" }, tracker.getEvents(Thread.currentThread())
132             .toArray(new String[0]));
133         tracker.clear();
134
135         system.stop(runtime);
136         AssertionUtils.assertEquals(new String[] { "stop.application",
137             "stop.environment" }, tracker.getEvents(Thread.currentThread())
138             .toArray(new String[0]));
139     }
140
141     public void testCompositeWithWrongProvidedInfo() {
142         try {
143             Component<?> environment = new Environment();
144             Component<?> application = new Application();
145             Container system = new Container("all", new Component[] {
146                 environment, application },
147                 new ProvidedInterface[] { new DefaultProvidedInterface("float",
148                     Float.class) }, new DefaultRequiredInterface[0]);
149             system.validate();
150         } catch (SystemAssemblyException e) {
151             return;
152         }
153
154         fail();
155     }
156
157     public void testCompositeRequiredInterfaceNotProvided() {
158         try {
159             Component<?> environment = new Environment();
160             Component<?> application = new Application();
161             Container system = new Container("all", new Component[] {
162                 environment, application }, new ProvidedInterface[0],
163                 new RequiredInterface[] { new DefaultRequiredInterface(
164                     "string", String.class) });
165             system.start();
166         } catch (SystemAssemblyException e) {
167             return;
168         }
169
170         fail();
171     }
172
173     public void testCompositeWithSuperfluousRequiredInfo() {
174         Component<?> environment = new Environment();
175         Component<?> application = new Application();
176         Container system = new Container("all", new Component[] { environment,
177             application }, new ProvidedInterface[0],
178             new RequiredInterface[] { new DefaultRequiredInterface("float",
179                 Float.class) });
180         system.getRequiredInterfaces().get(0).setProvider(
181             new DefaultProvidedInterface("hallo", Float.class));
182         system.start();
183
184         List<RequiredInterface> required = system.getRequiredInterfaces();
185         assertEquals(1, required.size());
186
187         List<ProvidedInterface> provided = system.getProvidedInterfaces();
188         assertEquals(0, provided.size());
189     }
190
191     public void testCompositeWithExternalDependencesNotProvided() {
192         try {
193             Component<?> application = new Application();
194
195             Container system = new Container("all",
196                 new Component[] { application }, new ProvidedInterface[0],
197                 application.getRequiredInterfaces().toArray(
198                     new RequiredInterface[0]));
199             system.start();
200         } catch (SystemAssemblyException e) {
201             return;
202         }
203
204         fail();
205     }
206
207     public void testDuplicateComponent() {
208         try {
209             Component<?> comp1 = new Application();
210             Component<?> comp2 = new Application();
211             Container system = new Container("top");
212             system.addComponent(comp1).addComponent(comp2);
213         } catch (SystemAssemblyException e) {
214             return;
215         }
216
217         fail();
218     }
219
220     public void testInconsistentHierarchy() {
221         try {
222             Component<?> comp = new Application();
223             Container system = new Container("top").addComponent(comp);
224             Container system2 = new Container("top2").addComponent(comp);
225         } catch (SystemAssemblyException e) {
226             return;
227         }
228
229         fail();
230     }
231
232     public void testCompositeWithExternalDependencesProvided() {
233         Component<?> environment = new Environment();
234         Component<?> application = new Application();
235         Container system = new Container("all",
236             new Component[] { application }, new ProvidedInterface[0],
237             application.getRequiredInterfaces().toArray(
238                 new RequiredInterface[0]));
239         environment.start(new DefaultScope(new ProvidedInterface[0]));
240         system.getRequiredInterfaces().get(0).setProvider(
241             environment.getProvidedInterfaces().get(0));
242         system.getRequiredInterfaces().get(1).setProvider(
243             environment.getProvidedInterfaces().get(1));
244
245         system.start();
246
247         List<RequiredInterface> required = system.getRequiredInterfaces();
248         assertEquals(2, required.size());
249
250         List<ProvidedInterface> provided = system.getProvidedInterfaces();
251         assertEquals(0, provided.size());
252     }
253
254     public void testAmbiguousInterfaces() {
255         try {
256             Component<?> environment1 = new Environment();
257             Component<?> environment2 = new Environment();
258             Component<?> application = new Application();
259             Container container = new Container("root", new Component[] {
260                 environment1, environment2, application },
261                 new ProvidedInterface[0], new RequiredInterface[0]);
262             container.start();
263         } catch (SystemAssemblyException e) {
264             return;
265         }
266
267         fail();
268     }
269
270     public void testIncompleteRequirements() {
271         try {
272             Component<?> application = new Application();
273             Container system = new Container("all",
274                 new Component[] { application }, new ProvidedInterface[0],
275                 new RequiredInterface[0]);
276             system.start();
277         } catch (SystemAssemblyException e) {
278             return;
279         }
280
281         fail();
282     }
283
284     public void testEnvironmentApplicationRollbackOnException()
285         throws Exception {
286         Environment environment = new Environment(tracker);
287         Application application = new Application() {
288             @Override
289             public Object doStart(Scope aScope) {
290                 throw new RuntimeException();
291             }
292         };
293
294         try {
295             Container container = new Container("root", new Component[] {
296                 environment, application }, new ProvidedInterface[0],
297                 new RequiredInterface[0]);
298
299             container.start();
300         } catch (RuntimeException e) {
301             AssertionUtils.assertEquals(new String[] { "start.environment",
302                 "stop.environment" }, tracker.getEvents(Thread.currentThread())
303                 .toArray(new String[0]));
304
305             return;
306         }
307
308         fail();
309     }
310
311     public void testEnvironmentApplicationRollbackOnExceptionWithExceptionOnStop()
312         throws Exception {
313         Environment environment = new Environment(tracker);
314
315         // Application 1 will throw an exception while stopping.
316         Application application1 = new Application("app1") {
317             @Override
318             public void doStop(Object aRuntime) {
319                 throw new RuntimeException();
320             }
321         };
322
323         // application 2 will throw an exception while starting
324         Application application2 = new Application("app2") {
325             public Object doStart(Scope aScope) {
326                 throw new RuntimeException();
327             }
328         };
329
330         try {
331             Container container = new Container("root", new Component[] {
332                 environment, application1, application2 },
333                 new ProvidedInterface[0], new RequiredInterface[0]);
334
335             container.start();
336         } catch (RuntimeException e) {
337             AssertionUtils.assertEquals(new String[] { "start.environment",
338                 "stop.environment" }, tracker.getEvents(Thread.currentThread())
339                 .toArray(new String[0]));
340
341             return;
342         }
343
344         fail();
345     }
346
347     public void testOptionalRequiredInterfaceProvidedOptionalInternal() {
348         Application application = new Application(true);
349         Container container = new Container("top",
350             new Component[] { application }, new ProvidedInterface[0],
351             Application.required(true));
352         Environment env = new Environment();
353         container.getRequiredInterfaces().get(0).setProvider(
354             env.getProvidedInterfaces().get(0));
355         container.getRequiredInterfaces().get(1).setProvider(
356             env.getProvidedInterfaces().get(1));
357
358         Scope external = new DefaultScope(env.getProvidedInterfaces());
359         env.start(external);
360
361         container.start(external);
362         assertSame(env.getProvidedInterfaces().get(0), container
363             .getRequiredInterfaces().get(0).getProvider());
364         assertSame(env.getProvidedInterfaces().get(1), container
365             .getRequiredInterfaces().get(1).getProvider());
366         assertSame(env.getProvidedInterfaces().get(0), application
367             .getRequiredInterfaces().get(0).getProvider());
368         assertSame(env.getProvidedInterfaces().get(1), application
369             .getRequiredInterfaces().get(1).getProvider());
370     }
371
372     public void testOptionalRequiredInterfaceNotProvidedOptionalInternal() {
373         Application application = new Application(true);
374         Container container = new Container("top",
375             new Component[] { application }, new ProvidedInterface[0],
376             Application.required(true));
377         Environment env = new Environment();
378         container.getRequiredInterfaces().get(0).setProvider(
379             env.getProvidedInterfaces().get(0));
380
381         Scope external = new DefaultScope(new ProvidedInterface[0]);
382         external.publishInterface(env.getProvidedInterfaces().get(0), env
383             .getString());
384         container.start(external);
385         assertSame(env.getProvidedInterfaces().get(0), container
386             .getRequiredInterfaces().get(0).getProvider());
387         assertNull(container.getRequiredInterfaces().get(1).getProvider());
388         assertSame(env.getProvidedInterfaces().get(0), application
389             .getRequiredInterfaces().get(0).getProvider());
390         assertNull(application.getRequiredInterfaces().get(1).getProvider());
391     }
392
393     public void testOptionalRequiredInterfaceProvidedMandatoryInternal() {
394         Application application = new Application();
395         Container container = new Container("top",
396             new Component[] { application }, new ProvidedInterface[0],
397             Application.required(true));
398         Environment env = new Environment();
399         container.getRequiredInterfaces().get(0).setProvider(
400             env.getProvidedInterfaces().get(0));
401         container.getRequiredInterfaces().get(1).setProvider(
402             env.getProvidedInterfaces().get(1));
403
404         try {
405             container.start();
406         } catch (SystemAssemblyException e) {
407             return;
408         }
409
410         fail();
411     }
412
413     public void testSealed() {
414         final Container container = new Container("xx");
415         assertFalse(container.isSealed());
416         container.start();
417         assertTrue(container.isSealed());
418
419         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
420             @Override
421             public void run() throws Exception {
422                 container.addComponent(new Application());
423             }
424         }, SystemAssemblyException.class);
425
426         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
427             @Override
428             public void run() throws Exception {
429                 container.connectRequiredProvided("x", "y", "a", "b");
430             }
431         }, SystemAssemblyException.class);
432         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
433             @Override
434             public void run() throws Exception {
435                 container.connectExternalRequired("x", "y", "a");
436             }
437         }, SystemAssemblyException.class);
438         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
439             @Override
440             public void run() throws Exception {
441                 container.connectExternalProvided("x", "y", "z");
442             }
443         }, SystemAssemblyException.class);
444         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
445             @Override
446             public void run() throws Exception {
447                 container.addProvidedInterface(new DefaultProvidedInterface(
448                     "xx", String.class));
449             }
450         }, SystemAssemblyException.class);
451
452         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
453             @Override
454             public void run() throws Exception {
455                 container.addRequiredInterface(new DefaultRequiredInterface(
456                     "xx", String.class));
457             }
458         }, SystemAssemblyException.class);
459     }
460
461     public void testRestriction() {
462         Environment env1 = new Environment("env1");
463         Environment env2 = new Environment("env2");
464         Application app = new Application("app");
465         Container container = new Container("top").addComponent(env1)
466             .addComponent(env2).addComponent(app);
467         container.connectRequiredProvided("app", null, "env1", null);
468         container.start();
469         assertEquals(env1.getString(), app.getString());
470         assertEquals(env1.getInteger(), app.getInteger());
471         assertFalse(env2.getString().equals(app.getString()));
472         assertFalse(env2.getInteger().equals(app.getInteger()));
473     }
474
475     public void testRestrictionWithFromAndToInterfaceName() {
476         Environment env1 = new Environment("env1");
477         Environment env2 = new Environment("env2");
478         Application app = new Application("app");
479         Container container = new Container("top").addComponent(env1)
480             .addComponent(env2).addComponent(app);
481         container.connectRequiredProvided("app", app.getRequiredInterfaces()
482             .get(0).getName(), "env1", env1.getProvidedInterfaces().get(0)
483             .getName());
484         container.connectRequiredProvided("app", app.getRequiredInterfaces()
485             .get(1).getName(), "env2", env2.getProvidedInterfaces().get(1)
486             .getName());
487         container.start();
488         assertEquals(env1.getString(), app.getString());
489         assertEquals(env2.getInteger(), app.getInteger());
490         assertFalse(env2.getString().equals(app.getString()));
491         assertFalse(env1.getInteger().equals(app.getInteger()));
492     }
493
494     public void testRestrictionWrongComponentNames() {
495         Environment env1 = new Environment("env1");
496         Environment env2 = new Environment("env2");
497         Application app = new Application("app");
498         final Container container = new Container("top").addComponent(env1)
499             .addComponent(env2).addComponent(app);
500         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
501             @Override
502             public void run() throws Exception {
503                 container.connectRequiredProvided("app2", null, "env1", null);
504             }
505         }, SystemAssemblyException.class);
506         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
507             @Override
508             public void run() throws Exception {
509                 container.connectRequiredProvided("app", null, "env3", null);
510             }
511         }, SystemAssemblyException.class);
512     }
513
514     public void testRestrictionWrongInterfaceNames() {
515         final Environment env1 = new Environment("env1");
516         Environment env2 = new Environment("env2");
517         final Application app = new Application("app");
518         final Container container = new Container("top").addComponent(env1)
519             .addComponent(env2).addComponent(app);
520         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
521             @Override
522             public void run() throws Exception {
523                 container.connectRequiredProvided("app", app
524                     .getRequiredInterfaces().get(0).getName() +
525                     "xxx", "env1", null);
526             }
527         }, SystemAssemblyException.class);
528         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
529             @Override
530             public void run() throws Exception {
531                 container.connectRequiredProvided("app", null, "env1", env1
532                     .getProvidedInterfaces().get(0).getName() +
533                     "yyy");
534             }
535         }, SystemAssemblyException.class);
536     }
537
538     public void testProvidedInDifferentScopes() {
539         // Scoping problem occurred. Externally and internally provided
540         // components clashed
541         // because unique id generation in the scope was wrong.
542         StringComponent str = new StringComponent("string");
543         Application app = new Application("app");
544         Container container = new Container("top").addComponent(str)
545             .addComponent(app);
546         container.addRequiredInterface(new DefaultRequiredInterface("integer",
547             Integer.class));
548
549         ProvidedInterface provided = new DefaultProvidedInterface("hallo",
550             Integer.class);
551         container.getRequiredInterfaces().get(0).setProvider(provided);
552
553         Scope external = new DefaultScope(new ProvidedInterface[0]);
554         external.publishInterface(provided, 100);
555
556         Scope scope = container.start(external);
557     }
558
559     public void testProvidedInterfaces() {
560         Environment env = new Environment(tracker);
561         Container envcontainer = new Container("0").addComponent(env)
562             .addProvidedInterface(
563                 new DefaultProvidedInterface("string", String.class))
564             .addProvidedInterface(
565                 new DefaultProvidedInterface("integer", Integer.class));
566         Scope scope = envcontainer.start();
567
568         AssertionUtils.assertEquals(new String[] { "start.environment" },
569             tracker.getEvents(Thread.currentThread()).toArray(new String[0]));
570
571         envcontainer.stop(scope);
572     }
573
574     public void testCoupleTwoContainers() {
575         Environment env = new Environment(tracker);
576         Container envcontainer = new Container("0").addComponent(env)
577             .addProvidedInterface(
578                 new DefaultProvidedInterface("string", String.class))
579             .addProvidedInterface(
580                 new DefaultProvidedInterface("integer", Integer.class));
581
582         Application app = new Application(tracker);
583         Container appcontainer = new Container("1").addComponent(app)
584             .addRequiredInterface(
585                 new DefaultRequiredInterface("string", String.class))
586             .addRequiredInterface(
587                 new DefaultRequiredInterface("integer", Integer.class));
588
589         Container top = new Container("top");
590         top.addComponent(envcontainer).addComponent(appcontainer);
591
592         top.start();
593         AssertionUtils.assertEquals(new String[] { "start.environment",
594             "start.application" }, tracker.getEvents(Thread.currentThread())
595             .toArray(new String[0]));
596     }
597
598     public void testNonUniqueRequiredInterface() {
599         final Container container = new Container("top");
600         container.addRequiredInterface(new DefaultRequiredInterface("i",
601             Integer.class));
602         container.addRequiredInterface(new DefaultRequiredInterface("x",
603             String.class));
604         container.addRequiredInterface(new DefaultRequiredInterface("y",
605             String.class));
606
607         Application app = new Application("1");
608         container.addComponent(app);
609
610         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
611             @Override
612             public void run() throws Exception {
613                 container.start();
614             }
615         }, SystemAssemblyException.class);
616
617         container.connectExternalRequired("1", app.getRequiredInterfaces().get(
618             0).getName(), "y");
619
620         ProvidedInterface i = new DefaultProvidedInterface("i", Integer.class);
621         ProvidedInterface x = new DefaultProvidedInterface("x", String.class);
622         ProvidedInterface y = new DefaultProvidedInterface("y", String.class);
623
624         Scope externalScope = new DefaultScope(new ProvidedInterface[0]);
625
626         externalScope.publishInterface(i, 100);
627         externalScope.publishInterface(x, "x-value");
628         externalScope.publishInterface(y, "y-value");
629
630         container.getRequiredInterfaces().get(0).setProvider(i);
631         container.getRequiredInterfaces().get(1).setProvider(x);
632         container.getRequiredInterfaces().get(2).setProvider(y);
633
634         Scope runtime = container.start(externalScope);
635
636         assertEquals("y-value", app.getString());
637     }
638
639     public void testNonUniqueRequiredInterfaceWrongNames() {
640         final Container container = new Container("top");
641         container.addRequiredInterface(new DefaultRequiredInterface("i",
642             Integer.class));
643         container.addRequiredInterface(new DefaultRequiredInterface("x",
644             String.class));
645         container.addRequiredInterface(new DefaultRequiredInterface("y",
646             String.class));
647
648         final Application app = new Application("1");
649         container.addComponent(app);
650
651         // wrong component name.
652         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
653             @Override
654             public void run() throws Exception {
655                 container.connectExternalRequired("2", "x", "y");
656             }
657         }, SystemAssemblyException.class);
658
659         // Wrong interface name of component.
660         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
661             @Override
662             public void run() throws Exception {
663                 container.connectExternalRequired("1", app
664                     .getRequiredInterfaces().get(0).getName() +
665                     "xxx", "y");
666             }
667         }, SystemAssemblyException.class);
668
669         // Wrong external interface name of container
670         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
671             @Override
672             public void run() throws Exception {
673                 container.connectExternalRequired("1", app
674                     .getRequiredInterfaces().get(0).getName(), "z");
675             }
676         }, SystemAssemblyException.class);
677     }
678
679     public void testNonUniqueProvidedInterface() {
680         final Container container = new Container("top")
681             .addProvidedInterface(new DefaultProvidedInterface("external",
682                 String.class));
683         Environment env1 = new Environment("env1");
684         Environment env2 = new Environment("env2");
685
686         container.addComponent(env1);
687         container.addComponent(env2);
688
689         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
690             @Override
691             public void run() throws Exception {
692                 container.start();
693             }
694         }, SystemAssemblyException.class);
695
696         // now choose env2
697         container.connectExternalProvided(container.getProvidedInterfaces()
698             .get(0).getName(), env2.getName(), env2.getProvidedInterfaces()
699             .get(0).getName());
700
701         Scope scope = container.start();
702
703         // check the value of the provided interface of the container
704         String value = scope.getInterfaceImplementation(container
705             .getProvidedInterfaces().get(0), String.class);
706         assertNotNull(value);
707         assertEquals(value, env2.getString());
708         assertFalse(value.equals(env1.getString()));
709     }
710
711     public void testNonUniqueProvidedInterfaceWrongNames() {
712         final Container container = new Container("top")
713             .addProvidedInterface(new DefaultProvidedInterface("external",
714                 String.class));
715         final Environment env1 = new Environment("env1");
716         final Environment env2 = new Environment("env2");
717
718         container.addComponent(env1);
719         container.addComponent(env2);
720
721         // Wrong external provided interface name
722         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
723             @Override
724             public void run() throws Exception {
725                 container
726                     .connectExternalProvided(container.getProvidedInterfaces()
727                         .get(0).getName() +
728                         "xx", "env1", env1.getProvidedInterfaces().get(0)
729                         .getName());
730             }
731         }, SystemAssemblyException.class);
732
733         // Wrong provided interface name.
734         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
735             @Override
736             public void run() throws Exception {
737                 container.connectExternalProvided(container
738                     .getProvidedInterfaces().get(0).getName(), "env1", env1
739                     .getProvidedInterfaces().get(0).getName() +
740                     "xx");
741             }
742         }, SystemAssemblyException.class);
743
744         // Wrong provided component
745         AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
746             @Override
747             public void run() throws Exception {
748                 container.connectExternalProvided(container
749                     .getProvidedInterfaces().get(0).getName(), "env3", env1
750                     .getProvidedInterfaces().get(0).getName());
751             }
752         }, SystemAssemblyException.class);
753     }
754
755     private static class MyMultiple implements Serializable, Runnable {
756         @Override
757         public void run() {
758             // Empty
759         }
760     }
761 }