KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > gbean > runtime > GBeanDependencyTest


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.gbean.runtime;
18
19 import junit.framework.TestCase;
20 import org.apache.geronimo.gbean.AbstractName;
21 import org.apache.geronimo.gbean.GBeanData;
22 import org.apache.geronimo.gbean.ReferencePatterns;
23 import org.apache.geronimo.kernel.Kernel;
24 import org.apache.geronimo.kernel.KernelFactory;
25 import org.apache.geronimo.kernel.MockGBean;
26 import org.apache.geronimo.kernel.management.State;
27 import org.apache.geronimo.kernel.repository.Artifact;
28
29 /**
30  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
31  */

32 public class GBeanDependencyTest extends TestCase {
33     private Kernel kernel;
34
35     public void testGBeanDependency() throws Exception JavaDoc {
36         AbstractName parentName = kernel.getNaming().createRootName(new Artifact("test", "foo", "1", "car"), "parent", "parent");
37         GBeanData gbeanDataParent = new GBeanData(parentName, MockGBean.getGBeanInfo());
38         GBeanData gbeanDataChild = new GBeanData(kernel.getNaming().createChildName(parentName, "child", "child"), MockGBean.getGBeanInfo());
39         gbeanDataChild.addDependency(new ReferencePatterns(parentName));
40         kernel.loadGBean(gbeanDataChild, MockGBean.class.getClassLoader());
41         kernel.startGBean(gbeanDataChild.getAbstractName());
42         assertEquals(State.STARTING_INDEX, kernel.getGBeanState(gbeanDataChild.getAbstractName()));
43         kernel.loadGBean(gbeanDataParent, MockGBean.class.getClassLoader());
44         assertEquals(State.STARTING_INDEX, kernel.getGBeanState(gbeanDataChild.getAbstractName()));
45         kernel.startGBean(parentName);
46         assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(gbeanDataChild.getAbstractName()));
47     }
48
49     protected void setUp() throws Exception JavaDoc {
50         super.setUp();
51         kernel = KernelFactory.newInstance().createKernel("test");
52         kernel.boot();
53     }
54
55     protected void tearDown() throws Exception JavaDoc {
56         kernel.shutdown();
57         super.tearDown();
58     }
59 }
60
Popular Tags