2 * Copyright 2011 GRNET S.A. All rights reserved.
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 * The views and conclusions contained in the software and
31 * documentation are those of the authors and should not be
32 * interpreted as representing official policies, either expressed
33 * or implied, of GRNET S.A.
36 package gr.grnet.aquarium.messaging
38 import amqp.rabbitmq.confmodel._
40 import org.junit.Assert._
41 import com.ckkloverdos.resource.DefaultResourceContext
42 import com.ckkloverdos.props.Props
43 import com.ckkloverdos.maybe.Just
44 import com.thoughtworks.xstream.XStream
45 import gr.grnet.aquarium.util.xstream.XStreamHelpers
49 * @author Christos KK Loverdos <loverdos@gmail.com>.
53 val rabbitmq = "rabbitmq"
55 val aquarium_dev = "aquarium_dev"
57 val producers = "producers"
58 val consumers = "consumers"
62 val configurations = "configuration.properties"
64 val aquarium_dev = "aquarium_dev.properties"
66 val main_producer = "main_producer.properties"
68 val main_consumer = "main_consumer.properties"
72 val configurations = "configurations"
75 val addresses = "addresses"
76 val username = "username"
77 val password = "password"
79 val virtualHost = "virtualHost"
81 val connections = "connections"
84 val exchange = "exchange"
85 val exchangeType = "exchangeType"
86 val exchangeIsDurable = "exchangeIsDurable"
87 val producers = "producers"
88 val consumers = "consumers"
91 val routingKey = "routingKey"
98 val aquarium_dev = "aquarium_dev"
99 val localhost = "localhost"
102 val baseRC = DefaultResourceContext
103 val rabbitmqRC = baseRC / RCFolders.rabbitmq
106 def testConfigurationsExist {
107 assertTrue(rabbitmqRC.getResource(PropFiles.configurations).isJust)
111 def testConfigurations {
112 val props = Props(PropFiles.configurations, rabbitmqRC).getOr(Props.empty)
113 val confList = props.getTrimmedList(PropKeys.configurations)
114 assertEquals(List(PropValues.aquarium_dev, PropValues.localhost), confList)
116 val xs = XStreamHelpers.newXStream
118 val cm1 = new RabbitMQConsumerModel("queue1")
119 val pm1 = new RabbitMQProducerModel("routing.key.1")
120 val con1 = new RabbitMQConnectionModel("exchnage1", "direct", true, List(pm1), List(cm1))
121 val conf1 = new RabbitMQConfigurationModel("aquarium", "aquarium", "localhost", 5672, Nil, "/", List(con1))
122 val confs = new RabbitMQConfigurationsModel2(List(conf1))
124 val xml = xs.toXML(confs)
127 val xml2 = """<gr.grnet.aquarium.messaging.amqp.rabbitmq.confmodel.RabbitMQConfigurationsModel2>
128 <configurations class="List">
129 <RabbitMQConfigurationModel>
130 <username>aquarium</username>
131 <password>aquarium</password>
132 <host>localhost</host>
134 <addresses class="Nil"/>
135 <virtualHost>/</virtualHost>
136 <connections class="List">
137 <RabbitMQConnectionModel>
138 <exchange>exchnage1</exchange>
139 <exchangeType>direct</exchangeType>
140 <isDurable>true</isDurable>
141 <producers class="List">
142 <RabbitMQProducerModel>
143 <routingKey>routing.key.1</routingKey>
144 </RabbitMQProducerModel>
146 <consumers class="List">
147 <RabbitMQConsumerModel>
148 <queue>queue1</queue>
149 </RabbitMQConsumerModel>
151 </RabbitMQConnectionModel>
153 </RabbitMQConfigurationModel>
155 </gr.grnet.aquarium.messaging.amqp.rabbitmq.confmodel.RabbitMQConfigurationsModel2>"""
156 for(model2 <- XStreamHelpers.parseType[RabbitMQConfigurationsModel2](xml2, xs)) {
157 println(model2.configurations(0).addresses)
162 def testConfigurationAquarium_DevExists {
163 val aquariumDevRC = rabbitmqRC / RCFolders.aquarium_dev
164 assertTrue(aquariumDevRC.getResource(PropFiles.aquarium_dev).isJust)
168 def testConfigurationAquarium_Dev {
169 val props = Props(PropFiles.aquarium_dev, rabbitmqRC / RCFolders.aquarium_dev).getOr(Props.empty)
171 assertTrue(props.get(PropKeys.username).isJust)
172 assertTrue(props.get(PropKeys.password).isJust)
173 assertTrue(props.get(PropKeys.addresses).isJust)
174 assertTrue(props.get(PropKeys.host).isJust)
175 assertTrue(props.get(PropKeys.virtualHost).isJust)
176 assertTrue(props.get(PropKeys.port).isJust)
177 assertTrue(props.get(PropKeys.connections).isJust)
179 assertEquals(Just(PropValues.aquarium_dev), props.get(PropKeys.connections))
183 def testConnectionAquarium_DevExists {
184 val aquariumDevRC2 = rabbitmqRC / RCFolders.aquarium_dev / RCFolders.aquarium_dev
185 assertTrue(aquariumDevRC2.getResource(PropFiles.aquarium_dev).isJust)
189 def testConnectionAquarium_Dev {
190 val props = Props(PropFiles.aquarium_dev, rabbitmqRC / RCFolders.aquarium_dev / RCFolders.aquarium_dev).getOr(Props.empty)
192 assertTrue(props.get(PropKeys.exchange).isJust)
193 assertTrue(props.get(PropKeys.exchangeType).isJust)
194 assertTrue(props.get(PropKeys.exchangeIsDurable).isJust)
195 assertTrue(props.get(PropKeys.producers).isJust)
196 assertTrue(props.get(PropKeys.consumers).isJust)
198 assertEquals(List("main_producer"), props.getTrimmedList(PropKeys.producers))
199 assertEquals(List("main_consumer"), props.getTrimmedList(PropKeys.consumers))
203 def testProducerMainProducerExists {
204 val rc = rabbitmqRC / RCFolders.aquarium_dev / RCFolders.aquarium_dev / RCFolders.producers
205 assertTrue(rc.getResource(PropFiles.main_producer).isJust)
209 def testProducerMainProducer {
210 val props = Props(PropFiles.main_producer, rabbitmqRC / RCFolders.aquarium_dev / RCFolders.aquarium_dev / RCFolders.producers).getOr(Props.empty)
212 assertTrue(props.get(PropKeys.routingKey).isJust)
219 def testConsumerMainConsumerExists {
220 val rc = rabbitmqRC / RCFolders.aquarium_dev / RCFolders.aquarium_dev / RCFolders.consumers
221 assertTrue(rc.getResource(PropFiles.main_consumer).isJust)
225 def testConsumerMainConsumer {
226 val props = Props(PropFiles.main_consumer, rabbitmqRC / RCFolders.aquarium_dev / RCFolders.aquarium_dev / RCFolders.consumers).getOr(Props.empty)
228 assertTrue(props.get(PropKeys.queue).isJust)