@Test public void sessionTransactedTestActiveJTATx() throws Exception { try { qraConnectionFactory.createContext(JMSContext.SESSION_TRANSACTED); fail(); } catch (JMSRuntimeException e) { //pass } }
@Test public void sessionTransactedTestNoActiveJTATx() throws Exception { try { qraConnectionFactory.createContext(JMSContext.SESSION_TRANSACTED); fail("Exception expected"); } catch (JMSRuntimeException ignored) { } }
@Test public void clientAckTestActiveJTATx() throws Exception { try { qraConnectionFactory.createContext(JMSContext.CLIENT_ACKNOWLEDGE); fail(); } catch (JMSRuntimeException e) { //pass } }
@Test public void sessionNotTransactedTestNoActiveJTATx() throws Exception { JMSContext context = qraConnectionFactory.createContext(JMSContext.AUTO_ACKNOWLEDGE); assertEquals(context.getSessionMode(), JMSContext.AUTO_ACKNOWLEDGE); }
@Test public void testCreateContextThrowsException() throws Exception { JMSContext jmsctx = qraConnectionFactory.createContext(); try { jmsctx.createContext(JMSContext.AUTO_ACKNOWLEDGE); fail("expected JMSRuntimeException"); } catch (JMSRuntimeException e) { //pass } catch (Exception e) { fail("wrong exception thrown: " + e); } }
@Test public void clientAckTestNoActiveJTATx() throws Exception { ((DummyTransactionManager) ServiceUtils.getTransactionManager()).tx = new DummyTransaction(); JMSContext context = qraConnectionFactory.createContext(JMSContext.CLIENT_ACKNOWLEDGE); assertEquals(context.getSessionMode(), JMSContext.AUTO_ACKNOWLEDGE); }
@Test public void sessionTransactedTestNoActiveJTATx() throws Exception { ((DummyTransactionManager) ServiceUtils.getTransactionManager()).tx = new DummyTransaction(); JMSContext context = qraConnectionFactory.createContext(JMSContext.SESSION_TRANSACTED); assertEquals(context.getSessionMode(), JMSContext.AUTO_ACKNOWLEDGE); }
@Test public void testJMSContextConsumerThrowsMessageFormatExceptionOnMalformedBody() throws Exception { Queue queue = createQueue(true, "ContextMalformedBodyTestQueue"); JMSContext context = qraConnectionFactory.createContext(); JMSProducer producer = context.createProducer(); TextMessage message = context.createTextMessage("TestMessage"); producer.send(queue, message); JMSConsumer consumer = context.createConsumer(queue); try { consumer.receiveBody(Boolean.class); fail("Should thrown MessageFormatException"); } catch (MessageFormatRuntimeException mfre) { // Do nothing test passed } catch (Exception e) { fail("Threw wrong exception, should be MessageFormatRuntimeException, instead got: " + e.getClass().getCanonicalName()); } } }
@Test public void testJMSContext() throws Exception { resourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); JMSContext jmsctx = qraConnectionFactory.createContext(JMSContext.DUPS_OK_ACKNOWLEDGE); assertEquals(JMSContext.DUPS_OK_ACKNOWLEDGE, jmsctx.getSessionMode()); }
@Test public void testSimpleSendNoXAJMSContext() throws Exception { Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE); try (ClientSessionFactory sf = locator.createSessionFactory(); ClientSession session = sf.createSession(); ClientConsumer consVerify = session.createConsumer(MDBQUEUE); JMSContext jmsctx = qraConnectionFactory.createContext(); ) { session.start(); // These next 4 lines could be written in a single line however it makes difficult for debugging JMSProducer producer = jmsctx.createProducer(); producer.setProperty("strvalue", "hello"); TextMessage msgsend = jmsctx.createTextMessage("hello"); producer.send(q, msgsend); ClientMessage msg = consVerify.receive(1000); assertNotNull(msg); assertEquals("hello", msg.getStringProperty("strvalue")); } }
@Test public void testSimpleSendNoXAJMSContext() throws Exception { Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE); try (ClientSessionFactory sf = locator.createSessionFactory(); ClientSession session = sf.createSession(); ClientConsumer consVerify = session.createConsumer(MDBQUEUE); JMSContext jmsctx = qraConnectionFactory.createContext(); ) { session.start(); // These next 4 lines could be written in a single line however it makes difficult for debugging JMSProducer producer = jmsctx.createProducer(); producer.setProperty("strvalue", "hello"); TextMessage msgsend = jmsctx.createTextMessage("hello"); producer.send(q, msgsend); ClientMessage msg = consVerify.receive(1000); assertNotNull(msg); assertEquals("hello", msg.getStringProperty("strvalue")); } }