KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > standalone > unit > XmlDeployerTestCase


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.ejb3.test.standalone.unit;
23
24 import java.util.Hashtable JavaDoc;
25 import javax.ejb.NoSuchEJBException JavaDoc;
26 import javax.naming.InitialContext JavaDoc;
27 import javax.naming.NamingException JavaDoc;
28 import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap;
29 import org.jboss.ejb3.test.standalone.CalculatorRemote;
30 import org.jboss.ejb3.test.standalone.Customer;
31 import org.jboss.ejb3.test.standalone.CustomerDAO;
32 import org.jboss.ejb3.test.standalone.ShoppingCart;
33 import junit.framework.TestCase;
34
35 /**
36  * POJO Environment tests
37  *
38  * @author <a HREF="bill@jboss.org">Bill Burke</a>
39  * @version $Revision: 57789 $
40  */

41 public class XmlDeployerTestCase extends TestCase
42 {
43    private static boolean booted = false;
44
45    public XmlDeployerTestCase(String JavaDoc name)
46    {
47       super(name);
48    }
49
50    protected void setUp() throws Exception JavaDoc
51    {
52       // set bad properties to make sure that we're injecting InitialContext correct
53
// System.setProperty("java.naming.factory.initial", "ERROR");
54
// System.setProperty("java.naming.factory.url.pkgs", "ERROR");
55

56       super.setUp();
57       long start = System.currentTimeMillis();
58       try
59       {
60          if (!booted)
61          {
62             booted = true;
63             EJB3StandaloneBootstrap.boot("");
64          }
65       }
66       catch (Exception JavaDoc e)
67       {
68          throw e;
69       }
70       catch (Throwable JavaDoc t)
71       {
72          throw new RuntimeException JavaDoc(t);
73       }
74    }
75
76    @Override JavaDoc
77    protected void tearDown() throws Exception JavaDoc
78    {
79       super.tearDown();
80       EJB3StandaloneBootstrap.shutdown();
81    }
82
83    protected InitialContext JavaDoc getInitialContext() throws Exception JavaDoc
84    {
85       return new InitialContext JavaDoc(getInitialContextProperties());
86    }
87
88    protected Hashtable JavaDoc getInitialContextProperties()
89    {
90       return EJB3StandaloneBootstrap.getInitialContextProperties();
91    }
92
93
94    public void testXmlDeployer() throws Throwable JavaDoc
95    {
96       InitialContext JavaDoc ctx = getInitialContext();
97       EJB3StandaloneBootstrap.deployXmlResource("deployer.xml");
98
99       executeEJBs(ctx);
100
101       EJB3StandaloneBootstrap.getKernel().getController().uninstall("EJBDeployment");
102    }
103
104    public void testCleanup() throws Throwable JavaDoc
105    {
106       boolean exceptionThrown = false;
107       try
108       {
109          executeEJBs(getInitialContext());
110       }
111       catch (Exception JavaDoc e)
112       {
113          exceptionThrown = true;
114       }
115       assertTrue(exceptionThrown);
116
117    }
118
119    private void executeEJBs(InitialContext JavaDoc ctx)
120            throws NamingException JavaDoc
121    {
122       CustomerDAO local = (CustomerDAO)ctx.lookup("CustomerDAOBean/local");
123       long id = local.createCustomer();
124       Customer cust = local.findCustomer(id);
125       assertEquals("Bill", cust.getName());
126
127       ShoppingCart cart = (ShoppingCart)ctx.lookup("ShoppingCartBean/local");
128       cart.getCart().add("beer");
129       cart.getCart().add("wine");
130       assertEquals(2, cart.getCart().size());
131
132       cart.checkout();
133
134       boolean exceptionThrown = false;
135       try
136       {
137          cart.getCart();
138       }
139       catch (NoSuchEJBException JavaDoc e)
140       {
141          exceptionThrown = true;
142       }
143
144       assertTrue(exceptionThrown);
145
146       CalculatorRemote calc = (CalculatorRemote)ctx.lookup("CalculatorBean/remote");
147       assertEquals(2, calc.add(1, 1));
148    }
149
150    protected void configureLoggingAfterBootstrap()
151    {
152       //enableTrace("org.jboss.tm");
153
}
154 }
Popular Tags