1 /*
2 * ========================================================================
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * ========================================================================
20 */
21 package org.apache.cactus.internal.server;
22
23 import java.lang.reflect.Field;
24 import java.lang.reflect.Method;
25
26 import javax.jms.QueueConnectionFactory;
27 import javax.naming.InitialContext;
28
29 import junit.framework.TestCase;
30
31 import org.apache.cactus.JmsRequest;
32 import org.apache.cactus.JmsTestCase;
33 import org.apache.cactus.spi.server.MessageDrivenBeanImplicitObjects;
34
35 /**
36 * Responsible for instanciating the <code>TestCase</code> class on the server
37 * side, set up the implicit objects and call the test method.
38 *
39 * @version $Id: MessageDrivenBeanTestCaller.java 292559 2005-09-29 21:36:43Z ptahchiev $
40 */
41 public class MessageDrivenBeanTestCaller extends AbstractJMSTestCaller
42 {
43 /**
44 * The implicit objects (which will be used to set the test case fields
45 * in the <code>setTesCaseFields</code> method.
46 */
47 protected MessageDrivenBeanImplicitObjects mdbImplicitObjects;
48
49
50 /**
51 * @param theObjects the implicit objects coming from the redirector
52 */
53 public MessageDrivenBeanTestCaller(MessageDrivenBeanImplicitObjects objects)
54 {
55 super(objects);
56 }
57
58 /**
59 * {@inheritDoc}
60 * @see AbstractWebTestCaller#setTestCaseFields(TestCase)
61 */
62 protected void setTestCaseFields(TestCase theTestInstance)
63 throws Exception
64 {
65 if (!(theTestInstance instanceof JmsTestCase))
66 {
67 return;
68 }
69
70 JmsTestCase jmsInstance = (JmsTestCase) theTestInstance;
71
72 // Sets the request field of the test case class
73 // ---------------------------------------------
74 // Extract from the JMS request the queue to simulate (if any)
75 JmsRequest request =
76 mdbImplicitObjects.getRequest();
77
78 String nameOfQueue = request.getQueueName();
79
80 QueueConnectionFactory qcf = ((QueueConnectionFactory)
81 ((InitialContext)mdbImplicitObjects.getMessageDrivenBeanContext()).lookup(nameOfQueue));
82
83 Method respondMethod = jmsInstance.getClass().getMethod("getJMSReplyTo", new Class[]{});
84
85 Field requestField = jmsInstance.getClass().getField("request"); //TODO find the appropriate field names here.
86
87 //requestField.set(jmsInstance,
88 // AbstractHttpServletRequestWrapper.newInstance(request, url));
89
90 // Set the response queue field of the test case class
91 // ---------------------------------------------
92 Field responseQueueField = jmsInstance.getClass().getField("jMSReplyTo"); //TODO find the appropriate field names here.
93
94 //responseQueueField.set(jmsInstance,
95 // mdbImplicitObjects.getHttpServletResponse());
96
97 // Set the config field of the test case class
98 // -------------------------------------------
99 Field configField = jmsInstance.getClass().getField("config");
100
101 //configField.set(jmsInstance, AbstractServletConfigWrapper.
102 // newInstance(mdbImplicitObjects.getServletConfig()));
103
104 // Set the session field of the test case class
105 // --------------------------------------------
106 // Create a Session object if the auto session flag is on
107 // if (isAutoSession())
108 // {
109 // HttpSession session = mdbImplicitObjects.getRequest()
110 // .getSession(true);
111 //
112 // Field sessionField = jmsInstance.getClass().getField("session");
113 //
114 // sessionField.set(jmsInstance, session);
115 // }
116 }
117
118 public void doTest()
119 {
120
121 }
122
123 public void doGetResults()
124 {
125
126 }
127
128 public void doRunTest()
129 {
130
131 }
132
133
134 public void doCreateSession()
135 {
136
137 }
138
139 public void doGetVersion()
140 {
141
142 }
143
144 }