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