KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > ra > ActiveMQAsfEndpointWorkerTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.ra;
19
20 import org.apache.activemq.ra.ActiveMQActivationSpec;
21 import org.apache.activemq.ra.ActiveMQEndpointActivationKey;
22 import org.apache.activemq.ra.ActiveMQEndpointWorker;
23 import org.apache.activemq.ra.ActiveMQResourceAdapter;
24 import org.jmock.cglib.Mock;
25 import org.jmock.cglib.MockObjectTestCase;
26 import org.jmock.core.Constraint;
27
28 import javax.jms.Connection JavaDoc;
29 import javax.jms.Topic JavaDoc;
30 import javax.resource.spi.BootstrapContext JavaDoc;
31 import javax.resource.spi.endpoint.MessageEndpointFactory JavaDoc;
32
33
34 /**
35  * @author <a HREF="mailto:michael.gaffney@panacya.com">Michael Gaffney </a>
36  */

37 public class ActiveMQAsfEndpointWorkerTest extends MockObjectTestCase {
38
39     private ActiveMQEndpointWorker worker;
40     private Mock mockResourceAdapter;
41     private Mock mockActivationKey;
42     private Mock mockEndpointFactory;
43     private Mock mockBootstrapContext;
44     private ActiveMQActivationSpec stubActivationSpec;
45     private Mock mockConnection;
46
47     public ActiveMQAsfEndpointWorkerTest(String JavaDoc name) {
48         setName(name);
49     }
50     
51     public void testTopicSubscriberDurableNoDups() throws Exception JavaDoc {
52
53         /*
54         Constraint[] args = {isA(Topic.class), eq(stubActivationSpec.getSubscriptionId()), NULL,
55                                 ANYTHING, ANYTHING};
56         
57         mockConnection.expects(once())
58                             .method("createDurableConnectionConsumer")
59                                 .with(args)
60                                     .will(returnValue(null));
61         worker.start();
62         verifyMocks();
63         */

64     }
65
66     protected void setUp() throws Exception JavaDoc {
67         setupStubs();
68         setupMocks();
69         setupEndpointWorker();
70     }
71
72     private void setupStubs() {
73         stubActivationSpec = new ActiveMQActivationSpec();
74         stubActivationSpec.setDestination("some.topic");
75         stubActivationSpec.setDestinationType("javax.jms.Topic");
76         stubActivationSpec.setSubscriptionDurability(ActiveMQActivationSpec.DURABLE_SUBSCRIPTION);
77         stubActivationSpec.setClientId("foo");
78         stubActivationSpec.setSubscriptionName("bar");
79     }
80
81     private void setupMocks() {
82         mockResourceAdapter = new Mock(ActiveMQResourceAdapter.class);
83         mockActivationKey = new Mock(ActiveMQEndpointActivationKey.class);
84         mockEndpointFactory = new Mock(MessageEndpointFactory JavaDoc.class);
85         mockBootstrapContext = new Mock(BootstrapContext JavaDoc.class);
86         mockConnection = new Mock(Connection JavaDoc.class);
87         
88         mockActivationKey.expects(atLeastOnce())
89                             .method("getMessageEndpointFactory")
90                                 .will(returnValue((MessageEndpointFactory JavaDoc) mockEndpointFactory.proxy()));
91         
92         mockActivationKey.expects(atLeastOnce())
93                             .method("getActivationSpec")
94                                 .will(returnValue(stubActivationSpec));
95
96         mockResourceAdapter.expects(atLeastOnce())
97                             .method("getBootstrapContext")
98                                 .will(returnValue((BootstrapContext JavaDoc) mockBootstrapContext.proxy()));
99
100         mockBootstrapContext.expects(atLeastOnce())
101                             .method("getWorkManager")
102                                 .will(returnValue(null));
103
104         final boolean isTransactedResult = true;
105         setupIsTransacted(isTransactedResult);
106     }
107
108     private void setupIsTransacted(final boolean transactedResult) {
109         mockEndpointFactory.expects(atLeastOnce())
110                             .method("isDeliveryTransacted")
111                                 .with(ANYTHING)
112                                     .will(returnValue(transactedResult));
113     }
114
115     private void setupEndpointWorker() throws Exception JavaDoc {
116         worker = new ActiveMQEndpointWorker((ActiveMQResourceAdapter)mockResourceAdapter.proxy(),
117                                                (ActiveMQEndpointActivationKey)mockActivationKey.proxy());
118     }
119
120     private void verifyMocks() {
121         mockResourceAdapter.verify();
122         mockActivationKey.verify();
123         mockEndpointFactory.verify();
124         mockBootstrapContext.verify();
125         mockConnection.verify();
126     }
127
128 }
129
Popular Tags