2fd48f6e4c08de37cb13d62aab3ddcb632db3f6c
[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 public class AbstractComponentTest extends TestCase {
21
22         public void testNotAllInterfacesStarted() {
23                 try {
24                         Component<?> component = new AbstractComponent<Object>("xx",
25                                         new ProvidedInterface[] { new DefaultProvidedInterface(
26                                                         "xxx", String.class) }, new RequiredInterface[0]) {
27                                 @Override
28                                 protected Object doStart(Scope aScope) {
29                                         // Empty, not starting service.
30                                         return null; 
31                                 }
32
33                                 @Override
34                                 protected void doStop(Object aRuntime) {
35                                         // Empty.
36                                 }
37                         };
38                         component.start(new DefaultScope(component.getProvidedInterfaces()));
39                 } catch (SystemAssemblyException e) {
40                         //e.printStackTrace();
41                         return;
42                 }
43                 fail();
44         }
45         
46         public void testUnexpectedServicesStarted() { 
47             try {
48             Component<?> component = new AbstractComponent<Object>("xx",
49                     new ProvidedInterface[0], new RequiredInterface[0]) {
50                 @Override
51                 protected Object doStart(Scope aScope) {
52                     addInterface(new DefaultProvidedInterface("x", Integer.class), 100, aScope);
53                     return null; 
54                 }
55
56                 @Override
57                 protected void doStop(Object aRuntime) {
58                     // Empty.
59                 }
60             };
61             component.start(new DefaultScope(component.getProvidedInterfaces()));
62         } catch (SystemAssemblyException e) {
63             //e.printStackTrace();
64             return;
65         }
66         fail();
67         }
68 }