1 /**
2 * Copyright 2005-2006 the original author or authors.
3 *
4 * Licensed under the Gnu General Pubic License, Version 2.0 (the
5 * "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/gpl-license.php
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the Gnu General Public License for more details.
14 */
15 package org.figure8.join.core.messaging;
16
17 import org.figure8.join.util.SpringTestCase;
18
19 import java.util.List;
20 /**
21 * This is a JUnit test for testing our configurable JCA container.
22 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
23 * @version $Revision: 1.2 $
24 */
25 public class ConfigurableJencksContainerTest extends SpringTestCase{
26
27
28
29 /** Spring configuration files */
30 private String[] configLocations = new String[]{"classpath:/org/figure8/join/core/messaging/spring-jca-jencks.xml"};
31
32
33
34
35 /** JMS messages producer */
36 protected JMSProducerBean producer = null;
37 /** The bean wrapping consumer info */
38 protected JMSConsumerBeanInfo consumerInfo = null;
39 /** Our configurable JCA container to test */
40 protected ConfigurableJencksContainer container = null;
41
42
43
44
45 /** Retrieve producer and container after having initialized context. */
46 public void setUp(){
47 super.setUp();
48
49 consumerInfo = new JMSConsumerBeanInfo();
50
51 producer = (JMSProducerBean)context.getBean("simpleProducer");
52
53 container = (ConfigurableJencksContainer)context.getBean("jencks");
54 }
55
56
57
58
59 /** Test the dynamic activation / deactivation of a consumer */
60 public void testConsumerActivationDeactivation(){
61 try{
62
63 consumerInfo.setName("test");
64 consumerInfo.setThreadSafe(true);
65 consumerInfo.setDestination("org.figure8.core.messaging.TestTopic");
66 consumerInfo.setConsumerBeanClass("org.figure8.join.core.messaging.EchoJMSConsumerBean");
67 }
68 catch (Exception e){
69 fail("Consumer info creation should not fail");
70 }
71
72
73
74 EchoJMSConsumerBean consumer = null;
75 try {consumer = (EchoJMSConsumerBean)consumerInfo.getJMSConsumerBean();}
76 catch (Exception e){
77 fail("Consumer creation should not fail");
78 }
79
80
81 try {container.activateJMSConsumerBean(consumerInfo);}
82 catch (Exception e){
83 fail("Consumer activation should not fail");
84 }
85
86
87 consumer.flushMessages();
88 for (int i=0; i<10; i++){
89 String text = "Hello World ! (" + i + ")";
90 producer.sendTextMessage(text);
91 }
92 consumer.waitForMessagesToArrive(10);
93 List messages = consumer.flushMessages();
94 assertEquals("Message count is correct", 10, messages.size());
95
96
97 try {container.deactivateJMSConsumerBean(consumerInfo);}
98 catch (Exception e){
99 fail("Consumer deactivation should not fail");
100 }
101 }
102
103
104
105
106 /** @return configLocations inner field */
107 public String[] getConfigLocations(){
108 return configLocations;
109 }
110 }