KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > server > profileservice > MainWithSimpleHotDeployTestCase


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.test.server.profileservice;
23
24 import java.io.File JavaDoc;
25 import java.security.CodeSource JavaDoc;
26
27 import org.jboss.Main;
28 import org.jboss.dependency.spi.ControllerState;
29 import org.jboss.kernel.Kernel;
30 import org.jboss.kernel.spi.registry.KernelRegistry;
31 import org.jboss.kernel.spi.registry.KernelRegistryEntry;
32 import org.jboss.system.server.Server;
33 import org.jboss.system.server.profileservice.ServerImpl;
34 import org.jboss.test.BaseTestCase;
35
36 /**
37  * Test of the jboss main loading a bootstrap configuration via the ProfileService
38  * and additional service via a simple hot deployment service.
39  *
40  * @see
41  *
42  * @author Scott.Stark@jboss.org
43  * @version $Revision: 56797 $
44  */

45 public class MainWithSimpleHotDeployTestCase extends BaseTestCase
46 {
47    public MainWithSimpleHotDeployTestCase(String JavaDoc name)
48    {
49       super(name);
50    }
51
52    // Public --------------------------------------------------------
53

54    /* (non-Javadoc)
55     * @see org.jboss.test.AbstractTestCase#configureLogging()
56     */

57    @Override JavaDoc
58    protected void configureLogging()
59    {
60       //enableTrace("org.jboss.kernel");
61
}
62
63    /**
64     * Test the startup of the org.jboss.Main entry point using the "default"
65     * profile and bootstrap deployer-beans.xml search logic.
66     * @throws Exception
67     */

68    public void testDefaultStartup() throws Exception JavaDoc
69    {
70       String JavaDoc deployPrefix = "";
71       // If jbosstest.deploy.dir is not defined fail
72
String JavaDoc deployDirEnv = System.getenv("jbosstest.deploy.dir");
73       String JavaDoc deployDirProp = System.getProperty("jbosstest.deploy.dir");
74       if( deployDirProp == null && deployDirEnv != null )
75       {
76          System.setProperty("jbosstest.deploy.dir", deployDirEnv);
77          deployDirProp = deployDirEnv;
78       }
79       String JavaDoc supportDirEnv = System.getenv("jbosstest.support.dir");
80       String JavaDoc supportDirProp = System.getProperty("jbosstest.support.dir");
81       if( supportDirProp == null && supportDirEnv != null )
82       {
83          System.setProperty("jbosstest.support.dir", supportDirEnv);
84          supportDirProp = supportDirEnv;
85       }
86
87       if( supportDirProp == null )
88       {
89          // If these have not been set, assume running inside eclipse from the system folder
90
File JavaDoc resourcesDir = new File JavaDoc("output/eclipse-resources");
91          File JavaDoc classesDir = new File JavaDoc("output/eclipse-test-classes");
92          deployDirProp = resourcesDir.toURL().toExternalForm();
93          supportDirProp = classesDir.toURL().toExternalForm();
94          System.setProperty("jbosstest.deploy.dir", deployDirProp);
95          System.setProperty("jbosstest.support.dir", supportDirProp);
96          deployPrefix = "tests/bootstrap/defaulthotdeploy/";
97       }
98       assertNotNull("jbosstest.support.dir != null", supportDirProp);
99       assertNotNull("jbosstest.deploy.dir != null", deployDirProp);
100       // Set the deploy prefix
101

102
103       String JavaDoc[] args = {"-c", "defaulthotdeploy", "-Djboss.server.deployerBeansPrefix="+deployPrefix};
104       Main main = new Main();
105       main.boot(args);
106       Server server = main.getServer();
107       assertTrue("Server", server instanceof ServerImpl);
108       ServerImpl serverImpl = (ServerImpl) server;
109
110       // Validate that the expected deployment beans exist
111
Kernel kernel = serverImpl.getKernel();
112       assertInstalled(kernel, "ProfileService");
113       assertInstalled(kernel, "MainDeployer");
114       assertInstalled(kernel, "BeanDeployer");
115       assertInstalled(kernel, "VFSDeploymentScanner");
116       KernelRegistry registry = kernel.getRegistry();
117       KernelRegistryEntry entry = registry.getEntry("VFSDeploymentScanner");
118       /** TODO DeploymentScanner scanner = (DeploymentScanner) entry.getTarget();
119       synchronized( scanner )
120       {
121          while( scanner.getScanCount() <= 0 )
122             scanner.wait(10000);
123       }
124       log.info("Notified of scan: "+scanner.getScanCount());
125       */

126
127       // Expected hot deployments
128
assertInstalled(kernel, "VFSClassLoader");
129       assertInstalled(kernel, "TestBean");
130       assertInstalled(kernel, "VFSClassLoader-unpacked");
131       assertInstalled(kernel, "TestBean-unpacked");
132       entry = registry.getEntry("TestBean");
133       Object JavaDoc testBean = entry.getTarget();
134       CodeSource JavaDoc testBeanCS = testBean.getClass().getProtectionDomain().getCodeSource();
135       log.info("TestBean.CS: "+testBeanCS);
136       log.info("TestBean.ClassLoader: "+testBean.getClass().getClassLoader());
137       
138
139       // Shutdown
140
main.shutdown();
141    }
142
143    private void assertInstalled(Kernel kernel, String JavaDoc name)
144    {
145       KernelRegistry registry = kernel.getRegistry();
146       KernelRegistryEntry entry = registry.getEntry(name);
147       assertEquals(name+" Installed", ControllerState.INSTALLED, entry.getState());
148    }
149 }
150
Popular Tags