01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.bpmscript.jbi;
18:
19: import java.util.Enumeration;
20:
21: import javax.jms.Connection;
22: import javax.jms.Message;
23: import javax.jms.MessageConsumer;
24: import javax.jms.MessageProducer;
25: import javax.jms.ObjectMessage;
26: import javax.jms.Queue;
27: import javax.jms.QueueBrowser;
28: import javax.jms.Session;
29:
30: import junit.framework.TestCase;
31:
32: import org.apache.activemq.ActiveMQConnectionFactory;
33: import org.apache.activemq.xbean.BrokerFactoryBean;
34: import org.apache.log4j.BasicConfigurator;
35: import org.springframework.core.io.ClassPathResource;
36:
37: public class BrowserTest extends TestCase {
38:
39: protected final transient org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
40: .getLog(getClass());
41:
42: protected void setUp() throws Exception {
43: super .setUp();
44: }
45:
46: protected void tearDown() throws Exception {
47: super .tearDown();
48: }
49:
50: public void testSomething() throws Exception {
51: BasicConfigurator.configure();
52: BrokerFactoryBean bean = new BrokerFactoryBean();
53: bean.setConfig(new ClassPathResource("inmemoryactivemq.xml"));
54: bean.afterPropertiesSet();
55:
56: ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
57: Connection connection = connectionFactory.createConnection();
58: connection.start();
59: Session session = connection.createSession(false,
60: Session.AUTO_ACKNOWLEDGE);
61: Queue queue = session
62: .createQueue("org.bpmscript.jbi.BrowserTestQueue");
63: MessageProducer producer = session.createProducer(queue);
64:
65: try {
66: ObjectMessage message = session
67: .createObjectMessage("Hello World!");
68: producer.send(message);
69: QueueBrowser browser = session.createBrowser(queue);
70:
71: Enumeration enumeration = browser.getEnumeration();
72: assertTrue(enumeration.hasMoreElements());
73:
74: MessageConsumer consumer = session.createConsumer(queue);
75: Message amessage = consumer.receiveNoWait();
76: assertNotNull(amessage);
77:
78: } finally {
79: // clear out old messages
80: MessageConsumer consumer = session.createConsumer(queue);
81: Message message = null;
82: while ((message = consumer.receiveNoWait()) != null) {
83: log.info("this shouldn't be here:" + message);
84: }
85: }
86:
87: session.close();
88: connection.stop();
89: connection.close();
90:
91: bean.destroy();
92: }
93:
94: }
|