1 17 package org.apache.geronimo.kernel; 18 19 import junit.framework.TestCase; 20 import org.apache.geronimo.gbean.GBeanData; 21 import org.apache.geronimo.gbean.GBeanInfo; 22 import org.apache.geronimo.gbean.GBeanInfoBuilder; 23 import org.apache.geronimo.kernel.config.ConfigurationData; 24 import org.apache.geronimo.kernel.config.ConfigurationManager; 25 import org.apache.geronimo.kernel.config.ConfigurationUtil; 26 import org.apache.geronimo.kernel.config.KernelConfigurationManager; 27 import org.apache.geronimo.kernel.repository.Artifact; 28 29 32 public class SimpleGBeanTest extends TestCase { 33 public void test() throws Exception { 34 Kernel kernel = KernelFactory.newInstance().createKernel("test"); 36 kernel.boot(); 37 38 ConfigurationData bootstrap = new ConfigurationData(new Artifact("bootstrap", "bootstrap", "", "car"), kernel.getNaming()); 40 bootstrap.addGBean("ConfigurationManager", KernelConfigurationManager.GBEAN_INFO); 41 ConfigurationUtil.loadBootstrapConfiguration(kernel, bootstrap, getClass().getClassLoader()); 42 ConfigurationManager configurationManager = (ConfigurationManager) kernel.getGBean(ConfigurationManager.class); 43 44 Artifact configurationId = new Artifact("test", "test", "", "car"); 46 ConfigurationData configurationData = new ConfigurationData(configurationId, kernel.getNaming()); 47 GBeanData mockBean1 = configurationData.addGBean("MyBean", TestGBean.getGBeanInfo()); 48 mockBean1.setAttribute("value", "1234"); 49 50 configurationManager.loadConfiguration(configurationData); 52 configurationManager.startConfiguration(configurationId); 53 54 TestGBean testGBean = (TestGBean) kernel.getGBean("MyBean"); 56 assertEquals("1234", testGBean.getValue()); 57 assertEquals("1234", testGBean.fetchValue()); 58 59 assertEquals("1234", kernel.getAttribute("MyBean", "value")); 61 assertEquals("1234", kernel.invoke("MyBean", "fetchValue")); 62 63 assertEquals("1234", kernel.getAttribute(TestGBean.class, "value")); 65 assertEquals("1234", kernel.invoke(TestGBean.class, "fetchValue")); 66 67 assertEquals("1234", kernel.getAttribute("MyBean", TestGBean.class, "value")); 69 assertEquals("1234", kernel.invoke("MyBean", TestGBean.class, "fetchValue")); 70 71 configurationManager.stopConfiguration(configurationId); 73 configurationManager.unloadConfiguration(configurationId); 74 75 kernel.shutdown(); 77 } 78 79 public static class TestGBean { 80 private final String value; 81 82 public TestGBean(String value) { 83 this.value = value; 84 } 85 86 public String getValue() { 87 return value; 88 } 89 90 public String fetchValue() { 91 return value; 92 } 93 94 95 private static final GBeanInfo GBEAN_INFO; 96 static { 97 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(TestGBean.class); 98 infoBuilder.setConstructor(new String [] {"value"}); 99 GBEAN_INFO = infoBuilder.getBeanInfo(); 100 } 101 public static GBeanInfo getGBeanInfo() { 102 return GBEAN_INFO; 103 } 104 } 105 } 106 | Popular Tags |