1 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 ; 29 import javax.jms.Topic ; 30 import javax.resource.spi.BootstrapContext ; 31 import javax.resource.spi.endpoint.MessageEndpointFactory ; 32 33 34 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 name) { 48 setName(name); 49 } 50 51 public void testTopicSubscriberDurableNoDups() throws Exception { 52 53 64 } 65 66 protected void setUp() throws Exception { 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 .class); 85 mockBootstrapContext = new Mock(BootstrapContext .class); 86 mockConnection = new Mock(Connection .class); 87 88 mockActivationKey.expects(atLeastOnce()) 89 .method("getMessageEndpointFactory") 90 .will(returnValue((MessageEndpointFactory ) 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 ) 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 { 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 |