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;
018:
019: import junit.framework.Test;
020: import junit.framework.TestSuite;
021: import org.apache.openejb.core.ServerFederation;
022: import org.apache.openejb.server.ServiceDaemon;
023: import org.apache.openejb.server.ServiceException;
024: import org.apache.openejb.server.ejbd.EjbServer;
025: import org.apache.openejb.test.TestManager;
026: import org.apache.openejb.test.entity.bmp.BmpTestSuite;
027: import org.apache.openejb.test.entity.cmp.CmpTestSuite;
028: import org.apache.openejb.test.stateful.StatefulTestSuite;
029: import org.apache.openejb.test.stateless.StatelessTestSuite;
030:
031: import java.util.Properties;
032:
033: import javax.naming.Context;
034:
035: /**
036: * To run from intellij or another IDE add
037: * <p/>
038: * -Dopenejb.home=/Users/dblevins/work/openejb3/server/openejb-ejbd/target/test-classes
039: *
040: * @version $Revision: 638272 $ $Date: 2008-03-18 01:59:59 -0700 $
041: */
042: public class RemoteiTest extends org.apache.openejb.test.TestSuite {
043:
044: protected void setUp() throws Exception {
045: System.setProperty("openejb.test.server", EjbTestServer.class
046: .getName());
047: // System.setProperty("openejb.test.database", org.apache.openejb.test.DerbyTestDatabase.class.getName());
048: System.setProperty("openejb.test.database",
049: org.apache.openejb.test.HsqldbTestDatabase.class
050: .getName());
051: TestManager.init(null);
052: TestManager.start();
053: }
054:
055: protected void tearDown() throws Exception {
056: TestManager.stop();
057: OpenEJB.destroy();
058: }
059:
060: public static Test suite() {
061: TestSuite suite = new RemoteiTest();
062: suite.addTest(StatelessTestSuite.suite());
063: suite.addTest(StatefulTestSuite.suite());
064: suite.addTest(BmpTestSuite.suite());
065: suite.addTest(CmpTestSuite.suite());
066: // suite.addTest(Cmp2TestSuite.suite());
067: return suite;
068: }
069:
070: public static class EjbTestServer implements
071: org.apache.openejb.test.TestServer {
072: private ServiceDaemon serviceDaemon;
073: private int port;
074:
075: public void init(Properties props) {
076: try {
077: EjbServer ejbServer = new EjbServer();
078: props.put("openejb.deployments.classpath", "true");
079: OpenEJB.init(props, new ServerFederation());
080: ejbServer.init(props);
081:
082: serviceDaemon = new ServiceDaemon(ejbServer, 0,
083: "localhost");
084:
085: } catch (Exception e) {
086: throw new RuntimeException(
087: "Unable to initialize Test Server.", e);
088: }
089: }
090:
091: public void start() {
092: try {
093: serviceDaemon.start();
094: port = serviceDaemon.getPort();
095: } catch (ServiceException e) {
096: throw new RuntimeException(
097: "Unable to start Test Server.", e);
098: }
099: }
100:
101: public void stop() {
102: try {
103: serviceDaemon.stop();
104: } catch (ServiceException e) {
105: throw new RuntimeException(
106: "Unable to stop Test Server.", e);
107: }
108: }
109:
110: public Properties getContextEnvironment() {
111: Properties props = new Properties();
112: props
113: .put(Context.INITIAL_CONTEXT_FACTORY,
114: "org.apache.openejb.client.RemoteInitialContextFactory");
115: props.put(Context.PROVIDER_URL, "ejbd://localhost:" + port);
116: return props;
117: }
118: }
119: }
|