1 17 18 package org.apache.geronimo.kernel; 19 20 import junit.framework.TestCase; 21 import org.apache.geronimo.gbean.AbstractName; 22 import org.apache.geronimo.gbean.AbstractNameQuery; 23 import org.apache.geronimo.gbean.GBeanData; 24 import org.apache.geronimo.kernel.config.Configuration; 25 import org.apache.geronimo.kernel.config.ConfigurationData; 26 import org.apache.geronimo.kernel.config.ConfigurationUtil; 27 import org.apache.geronimo.kernel.config.EditableConfigurationManager; 28 import org.apache.geronimo.kernel.config.EditableKernelConfigurationManager; 29 import org.apache.geronimo.kernel.management.State; 30 import org.apache.geronimo.kernel.repository.Artifact; 31 import org.apache.geronimo.kernel.repository.DefaultArtifactManager; 32 import org.apache.geronimo.kernel.repository.DefaultArtifactResolver; 33 34 37 public class ConfigTest extends TestCase { 38 private Kernel kernel; 39 private AbstractName gbeanName1; 40 private AbstractName gbeanName2; 41 private ConfigurationData configurationData; 42 private EditableConfigurationManager configurationManager; 43 45 public void testConfigLifecycle() throws Exception { 46 Artifact configurationId = configurationData.getId(); 47 48 configurationManager.loadConfiguration(configurationData); 50 Configuration configuration = configurationManager.getConfiguration(configurationId); 51 AbstractName configurationName = Configuration.getConfigurationAbstractName(configurationId); 52 53 assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(configurationName)); 54 assertNotNull(configuration.getConfigurationClassLoader()); 55 56 assertFalse(kernel.isLoaded(gbeanName1)); 57 assertFalse(kernel.isLoaded(gbeanName2)); 58 59 configurationManager.startConfiguration(configurationId); 61 62 assertTrue(kernel.isLoaded(gbeanName1)); 63 assertTrue(kernel.isLoaded(gbeanName2)); 64 65 assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(gbeanName1)); 66 assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(gbeanName2)); 67 68 assertEquals(new Integer (1), kernel.getAttribute(gbeanName1, "finalInt")); 69 assertEquals("1234", kernel.getAttribute(gbeanName1, "value")); 70 assertEquals(new Integer (3), kernel.getAttribute(gbeanName2, "finalInt")); 71 72 kernel.setAttribute(gbeanName2, "mutableInt", new Integer (44)); 73 assertEquals(new Integer (44), kernel.getAttribute(gbeanName2, "mutableInt")); 74 75 kernel.invoke(gbeanName2, "doSetMutableInt", new Object []{new Integer (55)}, new String []{"int"}); 76 assertEquals(new Integer (55), kernel.getAttribute(gbeanName2, "mutableInt")); 77 78 assertEquals("no endpoint", kernel.invoke(gbeanName1, "checkEndpoint", null, null)); 79 assertEquals("endpointCheck", kernel.invoke(gbeanName2, "checkEndpoint", null, null)); 80 81 assertEquals(new Integer (0), kernel.invoke(gbeanName1, "checkEndpointCollection", null, null)); 82 assertEquals(new Integer (1), kernel.invoke(gbeanName2, "checkEndpointCollection", null, null)); 83 84 kernel.setAttribute(gbeanName2, "endpointMutableInt", new Integer (99)); 85 assertEquals(new Integer (99), kernel.getAttribute(gbeanName2, "endpointMutableInt")); 86 assertEquals(new Integer (99), kernel.getAttribute(gbeanName1, "mutableInt")); 87 88 89 configurationManager.stopConfiguration(configurationId); 91 92 assertFalse(kernel.isLoaded(gbeanName1)); 93 assertFalse(kernel.isLoaded(gbeanName2)); 94 95 96 configurationManager.unloadConfiguration(configurationId); 98 99 assertFalse(kernel.isLoaded(configurationName)); 100 assertFalse(kernel.isLoaded(gbeanName1)); 101 assertFalse(kernel.isLoaded(gbeanName2)); 102 103 } 104 105 public void testConfigStartStopRestart() throws Exception { 106 Artifact configurationId = configurationData.getId(); 107 108 configurationManager.loadConfiguration(configurationData); 110 Configuration configuration = configurationManager.getConfiguration(configurationId); 111 AbstractName configurationName = Configuration.getConfigurationAbstractName(configurationId); 112 113 assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(configurationName)); 114 assertNotNull(configuration.getConfigurationClassLoader()); 115 116 assertFalse(kernel.isLoaded(gbeanName1)); 117 assertFalse(kernel.isLoaded(gbeanName2)); 118 119 120 configurationManager.startConfiguration(configurationId); 122 123 assertTrue(kernel.isLoaded(gbeanName1)); 124 assertTrue(kernel.isLoaded(gbeanName2)); 125 assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(gbeanName1)); 126 assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(gbeanName2)); 127 128 129 configurationManager.stopConfiguration(configurationId); 131 132 assertFalse(kernel.isLoaded(gbeanName1)); 133 assertFalse(kernel.isLoaded(gbeanName2)); 134 135 136 configurationManager.startConfiguration(configurationId); 138 139 assertTrue(kernel.isLoaded(gbeanName1)); 140 assertTrue(kernel.isLoaded(gbeanName2)); 141 assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(gbeanName1)); 142 assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(gbeanName2)); 143 144 configurationManager.stopConfiguration(configurationId); 146 configurationManager.unloadConfiguration(configurationId); 147 148 assertFalse(kernel.isLoaded(configurationName)); 149 assertFalse(kernel.isLoaded(gbeanName1)); 150 assertFalse(kernel.isLoaded(gbeanName2)); 151 152 } 153 154 public void testAddToConfig() throws Exception { 155 Artifact configurationId = configurationData.getId(); 156 157 configurationManager.loadConfiguration(configurationData); 159 Configuration configuration = configurationManager.getConfiguration(configurationId); 160 assertNotNull(configuration.getConfigurationClassLoader()); 161 162 GBeanData mockBean3 = new GBeanData(MockGBean.getGBeanInfo()); 163 try { 164 kernel.getGBeanState(mockBean3.getAbstractName()); 165 fail("Gbean should not be found yet"); 166 } catch (GBeanNotFoundException e) { 167 } 168 mockBean3.setAttribute("value", "1234"); 169 mockBean3.setAttribute("name", "child"); 170 mockBean3.setAttribute("finalInt", new Integer (1)); 171 configurationManager.addGBeanToConfiguration(configurationId, "MyMockGMBean3", mockBean3, true); 172 173 assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(mockBean3.getAbstractName())); 174 assertEquals(new Integer (1), kernel.getAttribute(mockBean3.getAbstractName(), "finalInt")); 175 assertEquals("1234", kernel.getAttribute(mockBean3.getAbstractName(), "value")); 176 assertEquals("child", kernel.getAttribute(mockBean3.getAbstractName(), "name")); 177 } 178 179 protected void setUp() throws Exception { 180 super.setUp(); 181 kernel = KernelFactory.newInstance().createKernel("test"); 182 kernel.boot(); 183 184 ConfigurationData bootstrap = new ConfigurationData(new Artifact("bootstrap", "bootstrap", "", "car"), kernel.getNaming()); 185 186 GBeanData artifactManagerData = bootstrap.addGBean("ArtifactManager", DefaultArtifactManager.GBEAN_INFO); 187 188 GBeanData artifactResolverData = bootstrap.addGBean("ArtifactResolver", DefaultArtifactResolver.GBEAN_INFO); 189 artifactResolverData.setReferencePattern("ArtifactManager", artifactManagerData.getAbstractName()); 190 191 GBeanData configurationManagerData = bootstrap.addGBean("ConfigurationManager", EditableKernelConfigurationManager.GBEAN_INFO); 192 configurationManagerData.setReferencePattern("ArtifactManager", artifactManagerData.getAbstractName()); 193 configurationManagerData.setReferencePattern("ArtifactResolver", artifactResolverData.getAbstractName()); 194 195 ConfigurationUtil.loadBootstrapConfiguration(kernel, bootstrap, getClass().getClassLoader()); 196 197 configurationManager = ConfigurationUtil.getEditableConfigurationManager(kernel); 198 199 200 configurationData = new ConfigurationData(new Artifact("test", "test", "", "car"), kernel.getNaming()); 201 202 GBeanData mockBean1 = configurationData.addGBean("MyMockGMBean1", MockGBean.getGBeanInfo()); 203 gbeanName1 = mockBean1.getAbstractName(); 204 mockBean1.setAttribute("value", "1234"); 205 mockBean1.setAttribute("name", "child"); 206 mockBean1.setAttribute("finalInt", new Integer (1)); 207 208 GBeanData mockBean2 = configurationData.addGBean("MyMockGMBean2", MockGBean.getGBeanInfo()); 209 gbeanName2 = mockBean2.getAbstractName(); 210 mockBean2.setAttribute("value", "5678"); 211 mockBean2.setAttribute("name", "Parent"); 212 mockBean2.setAttribute("finalInt", new Integer (3)); 213 mockBean2.setReferencePattern("MockEndpoint", gbeanName1); 214 mockBean2.setReferencePattern("EndpointCollection", new AbstractNameQuery(gbeanName1, MockGBean.getGBeanInfo().getInterfaces())); 215 } 216 217 protected void tearDown() throws Exception { 218 kernel.shutdown(); 219 super.tearDown(); 220 } 221 } 222 | Popular Tags |