KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > dependency > unit > DependencyUnitTestCase


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.dependency.unit;
23
24 import org.jboss.ejb3.test.dependency.NoDependencies;
25 import org.jboss.ejb3.test.dependency.Stateless;
26 import org.jboss.ejb3.test.dependency.HasMBeanDependency;
27 import org.jboss.ejb3.test.dependency.HasXmlMBeanDependency;
28 import org.jboss.ejb3.test.dependency.Stateless2;
29 import org.jboss.test.JBossTestCase;
30 import junit.framework.Test;
31
32 /**
33  * Sample client for the jboss container.
34  *
35  * @author <a HREF="mailto:bill@burkecentral.com">Bill Burke</a>
36  * @version $Id: DependencyUnitTestCase.java 58110 2006-11-04 08:34:21Z scott.stark@jboss.org $
37  */

38
39 public class DependencyUnitTestCase
40         extends JBossTestCase
41 {
42    org.jboss.logging.Logger log = getLog();
43
44    static boolean deployed = false;
45    static int test = 0;
46
47    public DependencyUnitTestCase(String JavaDoc name)
48    {
49
50       super(name);
51
52    }
53
54    public void testNonDependencies() throws Exception JavaDoc
55    {
56       NoDependencies nada = (NoDependencies) getInitialContext().lookup("dependency-test/NoDependenciesBean/remote");
57       nada.noop();
58    }
59
60    public void testDatasourceDependencies() throws Exception JavaDoc
61    {
62       Stateless test = null;
63       test = (Stateless) getInitialContext().lookup("dependency-test/StatelessBean/remote");
64       test.createCustomer();
65    }
66
67    public void testPUDependencies() throws Exception JavaDoc
68    {
69       try
70       {
71          super.deploy("ejbdepends.jar");
72       }
73       catch (Exception JavaDoc e)
74       {
75          // ignored
76
}
77       try
78       {
79          Stateless2 test = null;
80          boolean exceptionThrown = false;
81          try
82          {
83             test = (Stateless2) getInitialContext().lookup("Stateless2Bean/remote");
84             test.createCustomer();
85          }
86          catch (Exception JavaDoc ex)
87          {
88             exceptionThrown = true;
89          }
90          assertTrue(exceptionThrown);
91
92          super.deploy("yetanother.sar");
93          try
94          {
95             test = (Stateless2) getInitialContext().lookup("Stateless2Bean/remote");
96             test.createCustomer();
97          }
98          finally
99          {
100             super.undeploy("yetanother.sar");
101          }
102       }
103       finally
104       {
105          super.undeploy("ejbdepends.jar");
106       }
107
108    }
109
110    public void testDepends() throws Exception JavaDoc
111    {
112       boolean exceptionThrown = false;
113       try
114       {
115          HasMBeanDependency dependency = (HasMBeanDependency) getInitialContext().lookup("dependency-test/HasMBeanDependencyBean/remote");
116       }
117       catch (Exception JavaDoc e)
118       {
119          exceptionThrown = true;
120       }
121       assertTrue(exceptionThrown);
122       exceptionThrown = false;
123       try
124       {
125          HasXmlMBeanDependency dependency = (HasXmlMBeanDependency) getInitialContext().lookup("dependency-test/HasXmlMBeanDependencyBean/remote");
126       }
127       catch (Exception JavaDoc e)
128       {
129          exceptionThrown = true;
130       }
131       assertTrue(exceptionThrown);
132       exceptionThrown = false;
133       super.deploy("dependedon.sar");
134       try
135       {
136          try
137          {
138             HasMBeanDependency dependency = (HasMBeanDependency) getInitialContext().lookup("dependency-test/HasMBeanDependencyBean/remote");
139          }
140          catch (Exception JavaDoc e)
141          {
142             exceptionThrown = true;
143          }
144          assertTrue(exceptionThrown);
145
146          // should pass now
147
HasXmlMBeanDependency dependency = (HasXmlMBeanDependency) getInitialContext().lookup("dependency-test/HasXmlMBeanDependencyBean/remote");
148          dependency.noop();
149
150          super.deploy("anotherdependedon.sar");
151          try
152          {
153             HasMBeanDependency dependency2 = (HasMBeanDependency) getInitialContext().lookup("dependency-test/HasMBeanDependencyBean/remote");
154             dependency2.testNotNull();
155          }
156          finally
157          {
158             super.undeploy("anotherdependedon.sar");
159          }
160       }
161       finally
162       {
163          super.undeploy("dependedon.sar");
164       }
165    }
166
167    public static Test suite() throws Exception JavaDoc
168    {
169       return getDeploySetup(DependencyUnitTestCase.class, "dependency-test.ear");
170    }
171
172 }
173
Popular Tags