001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.server.httpd;
018:
019: import java.util.Properties;
020:
021: import junit.framework.Test;
022: import junit.framework.TestSuite;
023:
024: import org.apache.openejb.OpenEJB;
025: import org.apache.openejb.core.ServerFederation;
026: import org.apache.openejb.server.ServiceException;
027: import org.apache.openejb.server.ServiceDaemon;
028: import org.apache.openejb.server.ejbd.EjbServer;
029: import org.apache.openejb.test.TestManager;
030: import org.apache.openejb.test.entity.bmp.BmpTestSuite;
031: import org.apache.openejb.test.entity.cmp.CmpTestSuite;
032: import org.apache.openejb.test.stateful.StatefulTestSuite;
033: import org.apache.openejb.test.stateless.StatelessTestSuite;
034:
035: /**
036: * To run from intellij or another IDE add
037: *
038: * -Dopenejb.home=/Users/dblevins/work/openejb3/server/openejb-httpd/target/test-classes
039: *
040: * @version $Revision: 629307 $ $Date: 2008-02-19 17:36:18 -0800 $
041: */
042: public class HttpEjbServerTest extends
043: org.apache.openejb.test.TestSuite {
044:
045: protected void setUp() throws Exception {
046: System.setProperty("openejb.test.server",
047: HttpEjbTestServer.class.getName());
048: // System.setProperty("openejb.test.database", org.apache.openejb.test.DerbyTestDatabase.class.getName());
049: System.setProperty("openejb.test.database",
050: org.apache.openejb.test.HsqldbTestDatabase.class
051: .getName());
052:
053: // Copied from org.apache.openejb.server.httpd.SomeoneBrokeSurefireAndThisIsADirtyHackForItTest which is now gone
054: System.setProperty("openejb.assembler",
055: org.apache.openejb.assembler.classic.Assembler.class
056: .getName());
057: System.setProperty("openejb.deployments.classpath.include",
058: ".*openejb-itests-beans.*");
059: System.setProperty(
060: "openejb.deployments.classpath.filter.systemapps",
061: "false");
062:
063: TestManager.init(null);
064: TestManager.start();
065: }
066:
067: protected void tearDown() throws Exception {
068: TestManager.stop();
069: OpenEJB.destroy();
070: }
071:
072: public static Test suite() {
073: TestSuite suite = new HttpEjbServerTest();
074: suite.addTest(StatelessTestSuite.suite());
075: suite.addTest(StatefulTestSuite.suite());
076: suite.addTest(BmpTestSuite.suite());
077: suite.addTest(CmpTestSuite.suite());
078: return suite;
079: }
080:
081: public static class HttpEjbTestServer implements
082: org.apache.openejb.test.TestServer {
083: private ServiceDaemon serviceDaemon;
084: HttpServer httpServer;
085: private int port;
086:
087: public void init(Properties props) {
088: try {
089: EjbServer ejbServer = new EjbServer();
090: ServerServiceAdapter adapter = new ServerServiceAdapter(
091: ejbServer);
092: httpServer = new OpenEJBHttpServer(adapter);
093:
094: props.put("openejb.deployments.classpath", "true");
095: OpenEJB.init(props, new ServerFederation());
096: ejbServer.init(props);
097:
098: httpServer.init(props);
099:
100: // Binding to port 0 means that the OS will
101: // randomly pick an *available* port and bind to it
102: serviceDaemon = new ServiceDaemon(httpServer, 0,
103: "localhost");
104:
105: } catch (Exception e) {
106: throw new RuntimeException(
107: "Unable to initialize Test Server.", e);
108: }
109: }
110:
111: public void start() {
112: try {
113: serviceDaemon.start();
114: httpServer.start();
115:
116: // Here we figure out which port the OS picked for us
117: // so we can use it in the getContextEnvironment method
118: port = serviceDaemon.getPort();
119: } catch (ServiceException e) {
120: throw new RuntimeException(
121: "Unable to start Test Server.", e);
122: }
123: }
124:
125: public void stop() {
126: try {
127: serviceDaemon.stop();
128: httpServer.stop();
129: } catch (ServiceException e) {
130: throw new RuntimeException(
131: "Unable to stop Test Server.", e);
132: }
133: }
134:
135: public Properties getContextEnvironment() {
136: Properties props = new Properties();
137: props
138: .put("java.naming.factory.initial",
139: "org.apache.openejb.client.RemoteInitialContextFactory");
140: props.put("java.naming.provider.url", "http://127.0.0.1:"
141: + port + "/rjp");
142: return props;
143: }
144: }
145: }
|