KickJava   Java API By Example, From Geeks To Geeks.

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


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.net.URL JavaDoc;
26 import java.util.ArrayList JavaDoc;
27
28 import org.jboss.deployers.plugins.structure.AbstractDeploymentContext;
29 import org.jboss.deployers.spi.deployment.MainDeployer;
30 import org.jboss.deployers.spi.structure.DeploymentContext;
31 import org.jboss.profileservice.spi.Profile;
32 import org.jboss.profileservice.spi.ProfileKey;
33 import org.jboss.profileservice.spi.ProfileService;
34 import org.jboss.system.server.profileservice.ProfileServiceBootstrap;
35 import org.jboss.test.BaseTestCase;
36 import org.jboss.virtual.VFS;
37 import org.jboss.virtual.VirtualFile;
38 import org.jboss.Main;
39
40 /**
41  * Test of the jboss main loading a configuration via the ProfileService.
42  *
43  * @author Scott.Stark@jboss.org
44  * @version $Revision$
45  */

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

55    /**
56     * Test creation of a default profile
57     * @throws Exception
58     */

59    public void testCreateDefaultProfile() throws Throwable JavaDoc
60    {
61       // Set the jboss.server.home.url property to the system/src/resources dir
62
URL JavaDoc bootstrapDir = super.getResource("/bootstrap");
63       log.info("bootstrapDir: "+bootstrapDir);
64       URL JavaDoc resourcesDir = new URL JavaDoc(bootstrapDir, "..");
65       log.info("resourcesDir: "+resourcesDir);
66       System.setProperty("jboss.server.home.url", resourcesDir.toString());
67
68       //
69
ProfileServiceBootstrap psb = new ProfileServiceBootstrap();
70       psb.setDeployerBeansPrefix("bootstrap/default/");
71       psb.bootstrap();
72       ProfileService ps = psb.getProfileService();
73       ProfileKey defaultKey = new ProfileKey("default");
74       Profile profile = ps.getProfile(defaultKey);
75       DeploymentContext testBeans = profile.getDeployment("test-beans.xml");
76       if( testBeans == null )
77       {
78          if( profile == null )
79             profile = ps.newProfile(defaultKey);
80          MainDeployer deployer = psb.getMainDeployer();
81          VFS vfs = VFS.getVFS(resourcesDir);
82          VirtualFile file = vfs.findChildFromRoot("deploy/beans/test-beans.xml");
83          testBeans = new AbstractDeploymentContext(file);
84          deployer.addDeploymentContext(testBeans);
85          profile.addDeployment(testBeans);
86       }
87       // Validate the deployment
88
testBeans = profile.getDeployment("test-beans.xml");
89       assertNotNull(testBeans);
90       // TODO String type = testBeans.getType();
91
// assertEquals("Deployment type is beans", "beans", type);
92
}
93
94    /**
95     * Test the startup of the org.jboss.Main entry point using the "default"
96     * profile.
97     * @throws Exception
98     */

99    public void testDefaultStartup() throws Exception JavaDoc
100    {
101       // Set the jboss.server.home.url property to the system/src/resources dir
102
URL JavaDoc bootstrapDir = super.getResource("/bootstrap");
103       log.info("bootstrapDir: "+bootstrapDir);
104       URL JavaDoc resourcesDir = new URL JavaDoc(bootstrapDir, "..");
105       log.info("resourcesDir: "+resourcesDir);
106       System.setProperty("jboss.server.home.url", resourcesDir.toString());
107       // Set the jbosstest.support.dir to output/tests-support
108
File JavaDoc supportDir = new File JavaDoc("output/tests-support");
109       System.setProperty("jbosstest.support.dir", supportDir.toString());
110       // Correct the location of the deployer-beans.xml location
111
System.setProperty("jboss.server.deployerBeansPrefix", "bootstrap/default/");
112
113       ArrayList JavaDoc<String JavaDoc> args = new ArrayList JavaDoc<String JavaDoc>();
114       String JavaDoc[] tmp = {};
115       Main main = new Main();
116       main.boot(args.toArray(tmp));
117    }
118
119 }
120
Popular Tags