KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > usecases > ExceptionListenerTest


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.usecases;
19
20 import javax.jms.ExceptionListener JavaDoc;
21 import javax.jms.JMSException JavaDoc;
22
23 import junit.framework.TestCase;
24
25 /**
26  * @author Oliver Belikan
27  * @version $Revision: 1.1.1.1 $
28  */

29 public class ExceptionListenerTest extends TestCase implements ExceptionListener JavaDoc {
30     boolean isException = false;
31
32
33     public ExceptionListenerTest(String JavaDoc arg) {
34         super(arg);
35     }
36
37
38     public void testOnException() throws Exception JavaDoc {
39         /* TODO not sure yet if this is a valid test
40
41         System.setProperty("activemq.persistenceAdapter",
42                 "org.apache.activemq.store.vm.VMPersistenceAdapter");
43         // configuration of container and all protocolls
44         BrokerContainerImpl container = new
45                 BrokerContainerImpl("DefaultBroker");
46         BrokerConnectorImpl connector = new
47                 BrokerConnectorImpl(container,
48                         "vm://localhost", new DefaultWireFormat());
49         container.start();
50
51         ActiveMQConnectionFactory factory = new
52                 ActiveMQConnectionFactory("vm://localhost");
53         factory.start();
54
55         Connection connection = factory.createConnection();
56         connection.setExceptionListener(this);
57         connection.start();
58         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
59         Destination destination = session.createTopic(getClass().getName());
60         MessageProducer producer = session.createProducer(destination);
61
62         try {
63             Thread.currentThread().sleep(1000);
64         }
65         catch (Exception e) {
66         }
67
68         container.stop();
69
70         // now lets try send
71         try {
72             producer.send(session.createTextMessage("This will never get anywhere"));
73         }
74         catch (JMSException e) {
75             log.info("Caught: " + e);
76         }
77
78         try {
79             Thread.currentThread().sleep(1000);
80         }
81         catch (Exception e) {
82         }
83
84         assertTrue("Should have received an exception", isException);
85         */

86     }
87
88
89     public void onException(JMSException JavaDoc e) {
90         isException = true;
91     }
92 }
93
Popular Tags