001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.tests.embedded;
034:
035: import com.flexive.core.security.UserTicketImpl;
036: import com.flexive.shared.EJBLookup;
037: import com.flexive.shared.FxContext;
038: import com.flexive.shared.configuration.DivisionData;
039: import com.flexive.shared.exceptions.FxApplicationException;
040: import com.flexive.shared.interfaces.AccountEngine;
041: import com.flexive.shared.security.UserTicket;
042: import org.apache.commons.logging.Log;
043: import org.apache.commons.logging.LogFactory;
044: import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap;
045: import org.jboss.ejb3.embedded.EJB3StandaloneDeployer;
046: import org.testng.annotations.AfterSuite;
047: import org.testng.annotations.BeforeSuite;
048: import org.testng.annotations.Test;
049:
050: import java.net.MalformedURLException;
051: import java.net.URL;
052: import java.util.ArrayList;
053: import java.util.Collections;
054: import java.util.List;
055:
056: /**
057: * JBoss EJB3 embedded container bootstrap
058: *
059: * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
060: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
061: */
062: @Test(groups={"bootstrap","ejb","configuration","content","structure","jsf","security","workflow","streaming","scripting","valuetest","cache","image","tree","relation","search","tutorial","benchmark","environment","mandator"})
063: public class ContainerBootstrap {
064: private static final transient Log LOG = LogFactory
065: .getLog(ContainerBootstrap.class);
066:
067: private EJB3StandaloneDeployer deployer;
068: private List<Object> deployedBeans = new ArrayList<Object>();
069: protected final List<URL> deployDirectories = new ArrayList<URL>();
070:
071: @BeforeSuite
072: public void startup() throws FxApplicationException {
073: System.out.println("=== starting EJB3 container ===");
074: try {
075: System.setProperty("java.naming.factory.initial",
076: "org.jnp.interfaces.LocalOnlyContextFactory");
077: System.setProperty("java.naming.factory.url.pkgs",
078: "org.jboss.naming:org.jnp.interfaces");
079: EJB3StandaloneBootstrap.boot(null);
080: // enable security manager
081: EJB3StandaloneBootstrap
082: .deployXmlResource("security-beans.xml");
083: deployer = EJB3StandaloneBootstrap.createDeployer();
084: if (LOG.isInfoEnabled()) {
085: LOG.info("Running on: " + System.getProperty("os.name")
086: + " " + System.getProperty("os.version"));
087: }
088:
089: deployDirectories.add(0, new URL(
090: getFileUrl(getFlexiveBaseDir())
091: + getFlexiveDistDir()));
092: for (URL url : deployDirectories) {
093: deployDirectory(url);
094: }
095:
096: deployer
097: .getArchivesByResource()
098: .add(
099: getFlexiveBaseDir()
100: + "/src/META-INF/embeddedJBossCacheConfig.xml");
101:
102: // deployer.setMbeanServer(MBeanServerFactory.createMBeanServer("flexive"));
103:
104: if (LOG.isInfoEnabled()) {
105: LOG.info("Deploying...");
106: }
107: deployer.create();
108: deployer.start();
109:
110: if (LOG.isDebugEnabled()) {
111: LOG.debug("MBeanServer: " + deployer.getMbeanServer());
112: }
113: /*
114: FxCacheMBean cache = new FxCache();
115: cache.create();
116: deployer.getMbeanServer().registerMBean(cache, new ObjectName(CacheAdmin.CACHE_SERVICE_NAME));
117: deployedBeans.add(cache);
118:
119: StructureMBean structure = new Structure();
120: structure.create();
121: deployer.getMbeanServer().registerMBean(structure, new ObjectName(StructureAdmin.STRUCTURE_SERVICE_NAME));
122: deployedBeans.add(structure);
123: */
124: FxContext.get().setDivisionId(DivisionData.DIVISION_TEST);
125: FxContext.get().setContextPath("flexiveTests");
126: FxContext.get().setTicket(UserTicketImpl.getGuestTicket());
127: TestUsers.initializeUsers();
128: } catch (Exception ex) {
129: throw new RuntimeException(ex);
130: }
131: }
132:
133: protected String getFlexiveDistDir() {
134: return "/build/framework/jar";
135: }
136:
137: protected void deployDirectory(URL deployDir)
138: throws MalformedURLException {
139: deployer.getDeployDirs().add(deployDir);
140: }
141:
142: protected String getFileUrl(String fileName) {
143: return "file:"
144: + (System.getProperty("os.name").toLowerCase().indexOf(
145: "windows") >= 0 ? "/" : "") + fileName;
146: }
147:
148: protected String getFlexiveBaseDir() {
149: return getBuildDir();
150: }
151:
152: protected String getBuildDir() {
153: return System.getProperty("user.dir");
154: }
155:
156: @AfterSuite
157: public void shutdown() throws FxApplicationException {
158: try {
159: ScriptingTest.allowTearDown = true;
160: ScriptingTest.suiteShutDown();
161: TestUsers.deleteUsers();
162: System.out.println("=== shutting down EJB3 container ===");
163: AccountEngine accountEngine = EJBLookup.getAccountEngine();
164: for (UserTicket ticket : accountEngine
165: .getActiveUserTickets())
166: System.out.println("Still logged in: " + ticket);
167:
168: // destroy MBeans (in reverse order)
169: Collections.reverse(deployedBeans);
170: for (Object bean : deployedBeans) {
171: try {
172: bean.getClass().getMethod("destroy", new Class[0])
173: .invoke(bean, new Object[0]);
174: } catch (Exception e) {
175: System.out.println("Failed to destroy MBean: "
176: + e.getMessage());
177: e.printStackTrace();
178: }
179: }
180:
181: deployer.stop();
182: // deployer.destroy();
183: // EJB3StandaloneBootstrap.shutdown();
184: } catch (Exception ex) {
185: ex.printStackTrace();
186: throw new RuntimeException(ex);
187: }
188: }
189:
190: }
|