fe73dd9938ddf16800dc15fc092a2f1aa1f12407
[utils] / system / general / src / test / java / org / wamblee / system / core / AbstractComponentTest.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.core;
17
18 import junit.framework.TestCase;
19
20
21 /**
22  * DOCUMENT ME!
23  *
24  * @author $author$
25  * @version $Revision$
26   */
27 public class AbstractComponentTest extends TestCase {
28     /**
29      * DOCUMENT ME!
30      */
31     public void testNotAllInterfacesStarted() {
32         try {
33             Component<?> component = new AbstractComponent<Object>("xx",
34                     new ProvidedInterface[] {
35                         new DefaultProvidedInterface("xxx", String.class)
36                     }, new RequiredInterface[0]) {
37                     @Override
38                     protected Object doStart(Scope aScope) {
39                         // Empty, not starting service.
40                         return null;
41                     }
42
43                     @Override
44                     protected void doStop(Object aRuntime) {
45                         // Empty.
46                     }
47                 };
48
49             component.start(new DefaultScope(component.getProvidedInterfaces()));
50         } catch (SystemAssemblyException e) {
51             //e.printStackTrace();
52             return;
53         }
54
55         fail();
56     }
57
58     /**
59      * DOCUMENT ME!
60      */
61     public void testUnexpectedServicesStarted() {
62         try {
63             Component<?> component = new AbstractComponent<Object>("xx",
64                     new ProvidedInterface[0], new RequiredInterface[0]) {
65                     @Override
66                     protected Object doStart(Scope aScope) {
67                         addInterface(new DefaultProvidedInterface("x",
68                                 Integer.class), 100, aScope);
69
70                         return null;
71                     }
72
73                     @Override
74                     protected void doStop(Object aRuntime) {
75                         // Empty.
76                     }
77                 };
78
79             component.start(new DefaultScope(component.getProvidedInterfaces()));
80         } catch (SystemAssemblyException e) {
81             //e.printStackTrace();
82             return;
83         }
84
85         fail();
86     }
87 }