001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ejb3.test.standalone.unit;
023:
024: import junit.extensions.TestSetup;
025: import junit.framework.Test;
026: import junit.framework.TestCase;
027: import junit.framework.TestSuite;
028: import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap;
029: import org.jboss.ejb3.test.standalone.CalculatorBean;
030: import org.jboss.ejb3.test.standalone.CalculatorRemote;
031: import org.jboss.ejb3.test.standalone.Customer;
032: import org.jboss.ejb3.test.standalone.CustomerDAO;
033: import org.jboss.ejb3.test.standalone.ShoppingCart;
034: import org.jboss.ejb3.test.standalone.StupidInterceptor;
035:
036: import javax.ejb.NoSuchEJBException;
037: import javax.naming.InitialContext;
038: import javax.naming.NamingException;
039: import java.util.Hashtable;
040:
041: /**
042: * POJO Environment tests
043: *
044: * @author <a href="bill@jboss.org">Bill Burke</a>
045: * @version $Revision: 60233 $
046: */
047: public class JavaClassPathTestCase extends TestCase {
048: public JavaClassPathTestCase(String name) {
049: super (name);
050: }
051:
052: public static Test suite() throws Exception {
053: TestSuite suite = new TestSuite();
054: suite.addTestSuite(JavaClassPathTestCase.class);
055:
056: // setup test so that embedded JBoss is started/stopped once for all tests here.
057: TestSetup wrapper = new TestSetup(suite) {
058: protected void setUp() {
059: startupEmbeddedJboss();
060: }
061:
062: protected void tearDown() {
063: shutdownEmbeddedJboss();
064: }
065: };
066:
067: return wrapper;
068: }
069:
070: public static void startupEmbeddedJboss() {
071: EJB3StandaloneBootstrap.boot(null);
072: EJB3StandaloneBootstrap.scanClasspath("standalone.jar");
073: }
074:
075: public static void shutdownEmbeddedJboss() {
076: EJB3StandaloneBootstrap.shutdown();
077: }
078:
079: protected InitialContext getInitialContext() throws Exception {
080: return new InitialContext(getInitialContextProperties());
081: }
082:
083: protected Hashtable getInitialContextProperties() {
084: return EJB3StandaloneBootstrap.getInitialContextProperties();
085: }
086:
087: public void testJavaClassPath() throws Throwable {
088: InitialContext ctx = getInitialContext();
089:
090: executeEJBs(ctx);
091: }
092:
093: private void executeEJBs(InitialContext ctx) throws NamingException {
094: CustomerDAO local = (CustomerDAO) ctx
095: .lookup("CustomerDAOBean/local");
096: long id = local.createCustomer();
097: Customer cust = local.findCustomer(id);
098: assertEquals("Bill", cust.getName());
099:
100: ShoppingCart cart = (ShoppingCart) ctx
101: .lookup("ShoppingCartBean/local");
102: cart.getCart().add("beer");
103: cart.getCart().add("wine");
104: assertEquals(2, cart.getCart().size());
105:
106: cart.checkout();
107:
108: boolean exceptionThrown = false;
109: try {
110: cart.getCart();
111: } catch (NoSuchEJBException e) {
112: exceptionThrown = true;
113: }
114:
115: assertTrue(exceptionThrown);
116:
117: CalculatorRemote calc = (CalculatorRemote) ctx
118: .lookup("CalculatorBean/remote");
119: StupidInterceptor.count = 0;
120: CalculatorBean.test = true;
121: try {
122: assertEquals(2, calc.add(1, 1));
123: assertEquals(1, StupidInterceptor.count);
124: StupidInterceptor.count = 0;
125: CalculatorBean.test = true;
126: assertEquals(0, calc.sub(1, 1));
127: assertEquals(1, StupidInterceptor.count);
128: } finally {
129: CalculatorBean.test = false;
130: }
131: }
132:
133: protected void configureLoggingAfterBootstrap() {
134: //enableTrace("org.jboss.tm");
135: }
136: }
|