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.Properties;
20:
21: import javax.jms.Connection;
22: import javax.jms.Message;
23: import javax.jms.MessageConsumer;
24: import javax.jms.Queue;
25: import javax.jms.Session;
26:
27: import junit.framework.TestCase;
28:
29: import org.apache.activemq.ActiveMQConnectionFactory;
30: import org.apache.activemq.xbean.BrokerFactoryBean;
31: import org.apache.log4j.PropertyConfigurator;
32: import org.springframework.core.io.ClassPathResource;
33:
34: public class JmsAlarmTest extends TestCase {
35:
36: protected final transient org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
37: .getLog(getClass());
38:
39: protected void setUp() throws Exception {
40: super .setUp();
41: }
42:
43: protected void tearDown() throws Exception {
44: super .tearDown();
45: }
46:
47: public void testSomething() throws Exception {
48:
49: Properties properties = new Properties();
50: properties.put("log4j.rootCategory", "INFO, stdout");
51: properties.put("log4j.appender.stdout",
52: "org.apache.log4j.ConsoleAppender");
53: properties.put("log4j.appender.stdout.layout",
54: "org.apache.log4j.PatternLayout");
55: PropertyConfigurator.configure(properties);
56:
57: boolean keepgoing = true;
58:
59: while (keepgoing) {
60:
61: BrokerFactoryBean bean = new BrokerFactoryBean();
62: bean
63: .setConfig(new ClassPathResource(
64: "inmemoryactivemq.xml"));
65: bean.afterPropertiesSet();
66:
67: ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
68: Connection connection = connectionFactory
69: .createConnection();
70: connection.start();
71: Session session = connection.createSession(false,
72: Session.AUTO_ACKNOWLEDGE);
73: Queue queue = session
74: .createQueue("org.bpmscript.jbi.JmsAlarmComponentTestQueue");
75:
76: MessageConsumer consumer = session.createConsumer(queue);
77: Message message = null;
78: int counter = 0;
79: while ((message = consumer.receiveNoWait()) != null) {
80: log.info("removed message " + message);
81: counter++;
82: }
83:
84: if (counter == 0) {
85: keepgoing = false;
86: }
87:
88: consumer.close();
89: session.close();
90: connection.stop();
91: connection.close();
92: bean.destroy();
93: }
94:
95: }
96:
97: }
|