KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > consumer > unit > ConsumerUnitTestCase


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.consumer.unit;
23
24 import org.jboss.ejb3.mdb.ProducerManager;
25 import org.jboss.ejb3.mdb.ProducerObject;
26 import org.jboss.ejb3.test.consumer.QueueTestRemote;
27 import org.jboss.ejb3.test.consumer.DeploymentDescriptorQueueTestRemote;
28 import org.jboss.ejb3.test.consumer.TestStatus;
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: ConsumerUnitTestCase.java 58110 2006-11-04 08:34:21Z scott.stark@jboss.org $
37  */

38
39 public class ConsumerUnitTestCase
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 ConsumerUnitTestCase(String JavaDoc name)
48    {
49
50       super(name);
51
52    }
53
54    public void testQueue() throws Exception JavaDoc
55    {
56       TestStatus status = (TestStatus) getInitialContext().lookup("TestStatusBean/remote");
57       status.clear();
58       QueueTestRemote tester = (QueueTestRemote) getInitialContext().lookup("org.jboss.ejb3.test.consumer.QueueTestRemote");
59       ProducerManager manager = (ProducerManager) ((ProducerObject) tester).getProducerManager();
60       manager.connect();
61       try
62       {
63          tester.method1("testQueue", 5);
64          Thread.sleep(1000);
65          assertEquals(status.queueFired(), "method1");
66          assertEquals(status.interceptedQueue(), "method1");
67          assertTrue(status.postConstruct());
68          assertTrue(status.fieldMessage());
69          assertTrue(status.setterMessage());
70
71          status.clear();
72          tester.method2("testQueue", 5.5F);
73          Thread.sleep(1000);
74          assertEquals(status.queueFired(), "method2");
75          assertEquals(status.interceptedQueue(), "method2");
76          assertTrue(status.fieldMessage());
77          assertTrue(status.setterMessage());
78       }
79       finally
80       {
81          manager.close();
82       }
83
84       //TODO: Figure out how to test preDestroy gets invoked
85
//assertTrue(status.preDestroy());
86
}
87
88    public void testQueueXA() throws Exception JavaDoc
89    {
90       TestStatus status = (TestStatus) getInitialContext().lookup("TestStatusBean/remote");
91       status.clear();
92       status.testXA();
93
94       Thread.sleep(1000);
95       assertEquals(status.queueFired(), "method2");
96       assertEquals(status.interceptedQueue(), "method2");
97    }
98
99    public void testQueueLocal() throws Exception JavaDoc
100    {
101       TestStatus status = (TestStatus) getInitialContext().lookup("TestStatusBean/remote");
102       status.clear();
103       status.testLocal();
104
105       Thread.sleep(1000);
106       assertEquals(status.queueFired(), "method2");
107       assertEquals(status.interceptedQueue(), "method2");
108    }
109    
110    public void testDeploymentDescriptorQueue() throws Exception JavaDoc
111    {
112       TestStatus status = (TestStatus) getInitialContext().lookup("TestStatusBean/remote");
113       status.clear();
114       DeploymentDescriptorQueueTestRemote tester = (DeploymentDescriptorQueueTestRemote) getInitialContext().lookup("org.jboss.ejb3.test.consumer.DeploymentDescriptorQueueTestRemote");
115       ProducerManager manager = (ProducerManager) ((ProducerObject) tester).getProducerManager();
116       manager.connect();
117       try
118       {
119          tester.method1("testQueue", 5);
120          Thread.sleep(1000);
121          assertEquals(status.queueFired(), "method1");
122          assertEquals(status.interceptedQueue(), "method1");
123          assertTrue(status.postConstruct());
124          assertTrue(status.fieldMessage());
125          assertTrue(status.setterMessage());
126
127          status.clear();
128          tester.method2("testQueue", 5.5F);
129          Thread.sleep(1000);
130          assertEquals(status.queueFired(), "method2");
131          assertEquals(status.interceptedQueue(), "method2");
132          assertTrue(status.fieldMessage());
133          assertTrue(status.setterMessage());
134       }
135       finally
136       {
137          manager.close();
138       }
139
140       //TODO: Figure out how to test preDestroy gets invoked
141
//assertTrue(status.preDestroy());
142
}
143    
144    public void testDeploymentDescriptorQueueXA() throws Exception JavaDoc
145    {
146       TestStatus status = (TestStatus) getInitialContext().lookup("TestStatusBean/remote");
147       status.clear();
148       status.testDeploymentDescriptorXA();
149
150       Thread.sleep(1000);
151       assertEquals(status.queueFired(), "method2");
152       assertEquals(status.interceptedQueue(), "method2");
153    }
154
155    public void testDeploymentDescriptorQueueLocal() throws Exception JavaDoc
156    {
157       TestStatus status = (TestStatus) getInitialContext().lookup("TestStatusBean/remote");
158       status.clear();
159       status.testDeploymentDescriptorLocal();
160
161       Thread.sleep(1000);
162       assertEquals(status.queueFired(), "method2");
163       assertEquals(status.interceptedQueue(), "method2");
164    }
165
166    public static Test suite() throws Exception JavaDoc
167    {
168       return getDeploySetup(ConsumerUnitTestCase.class, "consumertest-service.xml, consumer-test.jar");
169    }
170
171 }
172
Popular Tags