Revision 3c96bea0 logic/src/test/scala/gr/grnet/aquarium/messaging/MessagingTest.scala
b/logic/src/test/scala/gr/grnet/aquarium/messaging/MessagingTest.scala | ||
---|---|---|
35 | 35 |
|
36 | 36 |
package gr.grnet.aquarium.messaging |
37 | 37 |
|
38 |
import amqp.rabbitmq.confmodel._ |
|
38 |
import amqp.rabbitmq.v091.confmodel._ |
|
39 |
import amqp.rabbitmq.v091.RabbitMQConfigurations.{PropFiles, RCFolders} |
|
40 |
import amqp.rabbitmq.v091.{RabbitMQConsumer, RabbitMQConfigurations} |
|
39 | 41 |
import org.junit.Test |
40 | 42 |
import org.junit.Assert._ |
41 | 43 |
import com.ckkloverdos.resource.DefaultResourceContext |
42 |
import com.ckkloverdos.props.Props |
|
43 |
import com.ckkloverdos.maybe.Just |
|
44 |
import com.thoughtworks.xstream.XStream |
|
45 | 44 |
import gr.grnet.aquarium.util.xstream.XStreamHelpers |
45 |
import gr.grnet.aquarium.util.Loggable |
|
46 | 46 |
|
47 | 47 |
/** |
48 | 48 |
* |
49 | 49 |
* @author Christos KK Loverdos <loverdos@gmail.com>. |
50 | 50 |
*/ |
51 |
class MessagingTest { |
|
52 |
object RCFolders { |
|
53 |
val rabbitmq = "rabbitmq" |
|
54 |
|
|
55 |
val aquarium_dev = "aquarium_dev" |
|
56 |
|
|
57 |
val producers = "producers" |
|
58 |
val consumers = "consumers" |
|
59 |
} |
|
60 |
|
|
61 |
object PropFiles { |
|
62 |
val configurations = "configuration.properties" |
|
63 |
|
|
64 |
val aquarium_dev = "aquarium_dev.properties" |
|
65 |
|
|
66 |
val main_producer = "main_producer.properties" |
|
67 |
|
|
68 |
val main_consumer = "main_consumer.properties" |
|
69 |
} |
|
70 |
|
|
71 |
object PropKeys { |
|
72 |
val configurations = "configurations" |
|
73 |
|
|
74 |
// configuration |
|
75 |
val addresses = "addresses" |
|
76 |
val username = "username" |
|
77 |
val password = "password" |
|
78 |
val host = "host" |
|
79 |
val virtualHost = "virtualHost" |
|
80 |
val port = "port" |
|
81 |
val connections = "connections" |
|
82 |
|
|
83 |
// connection |
|
84 |
val exchange = "exchange" |
|
85 |
val exchangeType = "exchangeType" |
|
86 |
val exchangeIsDurable = "exchangeIsDurable" |
|
87 |
val producers = "producers" |
|
88 |
val consumers = "consumers" |
|
89 |
|
|
90 |
// producer |
|
91 |
val routingKey = "routingKey" |
|
92 |
|
|
93 |
// consumer |
|
94 |
val queue = "queue" |
|
95 |
} |
|
96 |
|
|
97 |
object PropValues { |
|
98 |
val aquarium_dev = "aquarium_dev" |
|
99 |
val localhost = "localhost" |
|
100 |
} |
|
51 |
class MessagingTest extends Loggable { |
|
101 | 52 |
|
102 | 53 |
val baseRC = DefaultResourceContext |
103 | 54 |
val rabbitmqRC = baseRC / RCFolders.rabbitmq |
104 | 55 |
|
105 |
@Test |
|
106 |
def testConfigurationsExist { |
|
107 |
assertTrue(rabbitmqRC.getResource(PropFiles.configurations).isJust) |
|
108 |
} |
|
109 |
|
|
110 |
@Test |
|
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) |
|
115 |
|
|
56 |
private def _genTestConf: String = { |
|
57 |
val consmod1 = new RabbitMQConsumerModel("consumer1", "queue1") |
|
58 |
val prodmod1 = new RabbitMQProducerModel("producer1", "routing.key.all") |
|
59 |
val conn1 = new RabbitMQConnectionModel( |
|
60 |
"local_connection", |
|
61 |
"aquarium_exchange", |
|
62 |
"direct", |
|
63 |
true, |
|
64 |
List(prodmod1), |
|
65 |
List(consmod1) |
|
66 |
) |
|
67 |
val conf1 = new RabbitMQConfigurationModel( |
|
68 |
"localhost_aquarium", |
|
69 |
"aquarium", |
|
70 |
"aquarium", |
|
71 |
"localhost", |
|
72 |
5672, |
|
73 |
Nil, |
|
74 |
"/", |
|
75 |
List(conn1) |
|
76 |
) |
|
77 |
|
|
78 |
val model = new RabbitMQConfigurationsModel(List(conf1)) |
|
116 | 79 |
val xs = XStreamHelpers.newXStream |
80 |
val xml = xs.toXML(model) |
|
117 | 81 |
|
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)) |
|
123 |
|
|
124 |
val xml = xs.toXML(confs) |
|
125 |
println(xml) |
|
126 |
|
|
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> |
|
133 |
<port>5672</port> |
|
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> |
|
145 |
</producers> |
|
146 |
<consumers class="List"> |
|
147 |
<RabbitMQConsumerModel> |
|
148 |
<queue>queue1</queue> |
|
149 |
</RabbitMQConsumerModel> |
|
150 |
</consumers> |
|
151 |
</RabbitMQConnectionModel> |
|
152 |
</connections> |
|
153 |
</RabbitMQConfigurationModel> |
|
154 |
</configurations> |
|
155 |
</gr.grnet.aquarium.messaging.amqp.rabbitmq.confmodel.RabbitMQConfigurationsModel2>""" |
|
156 |
for(model2 <- XStreamHelpers.parseType[RabbitMQConfigurationsModel2](xml2, xs)) { |
|
157 |
println(model2.configurations(0).addresses) |
|
158 |
} |
|
82 |
xml |
|
159 | 83 |
} |
160 |
|
|
161 | 84 |
@Test |
162 |
def testConfigurationAquarium_DevExists { |
|
163 |
val aquariumDevRC = rabbitmqRC / RCFolders.aquarium_dev |
|
164 |
assertTrue(aquariumDevRC.getResource(PropFiles.aquarium_dev).isJust) |
|
165 |
} |
|
166 |
|
|
167 |
@Test |
|
168 |
def testConfigurationAquarium_Dev { |
|
169 |
val props = Props(PropFiles.aquarium_dev, rabbitmqRC / RCFolders.aquarium_dev).getOr(Props.empty) |
|
170 |
|
|
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) |
|
178 |
|
|
179 |
assertEquals(Just(PropValues.aquarium_dev), props.get(PropKeys.connections)) |
|
180 |
} |
|
181 |
|
|
182 |
@Test |
|
183 |
def testConnectionAquarium_DevExists { |
|
184 |
val aquariumDevRC2 = rabbitmqRC / RCFolders.aquarium_dev / RCFolders.aquarium_dev |
|
185 |
assertTrue(aquariumDevRC2.getResource(PropFiles.aquarium_dev).isJust) |
|
186 |
} |
|
187 |
|
|
188 |
@Test |
|
189 |
def testConnectionAquarium_Dev { |
|
190 |
val props = Props(PropFiles.aquarium_dev, rabbitmqRC / RCFolders.aquarium_dev / RCFolders.aquarium_dev).getOr(Props.empty) |
|
191 |
|
|
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) |
|
197 |
|
|
198 |
assertEquals(List("main_producer"), props.getTrimmedList(PropKeys.producers)) |
|
199 |
assertEquals(List("main_consumer"), props.getTrimmedList(PropKeys.consumers)) |
|
200 |
} |
|
201 |
|
|
202 |
@Test |
|
203 |
def testProducerMainProducerExists { |
|
204 |
val rc = rabbitmqRC / RCFolders.aquarium_dev / RCFolders.aquarium_dev / RCFolders.producers |
|
205 |
assertTrue(rc.getResource(PropFiles.main_producer).isJust) |
|
206 |
} |
|
207 |
|
|
208 |
@Test |
|
209 |
def testProducerMainProducer { |
|
210 |
val props = Props(PropFiles.main_producer, rabbitmqRC / RCFolders.aquarium_dev / RCFolders.aquarium_dev / RCFolders.producers).getOr(Props.empty) |
|
211 |
|
|
212 |
assertTrue(props.get(PropKeys.routingKey).isJust) |
|
85 |
def testConfigurationsExist { |
|
86 |
assertTrue(rabbitmqRC.getResource(PropFiles.configurations).isJust) |
|
213 | 87 |
} |
214 | 88 |
|
215 |
|
|
216 |
|
|
217 |
|
|
218 | 89 |
@Test |
219 |
def testConsumerMainConsumerExists { |
|
220 |
val rc = rabbitmqRC / RCFolders.aquarium_dev / RCFolders.aquarium_dev / RCFolders.consumers |
|
221 |
assertTrue(rc.getResource(PropFiles.main_consumer).isJust) |
|
90 |
def testLocalProducer { |
|
91 |
val maybeConfs = RabbitMQConfigurations(baseRC) |
|
92 |
assertTrue(maybeConfs.isJust) |
|
93 |
for { |
|
94 |
confs <- maybeConfs |
|
95 |
conf <- confs.findConfiguration("localhost_aquarium") |
|
96 |
conn <- conf.findConnection("local_connection") |
|
97 |
producer <- conn.findProducer("producer1") |
|
98 |
} yield { |
|
99 |
logger.debug("Publishing a message from %s".format(producer)) |
|
100 |
producer.publish("Test") |
|
101 |
} |
|
222 | 102 |
} |
223 | 103 |
|
224 |
@Test |
|
225 |
def testConsumerMainConsumer { |
|
226 |
val props = Props(PropFiles.main_consumer, rabbitmqRC / RCFolders.aquarium_dev / RCFolders.aquarium_dev / RCFolders.consumers).getOr(Props.empty) |
|
227 |
|
|
228 |
assertTrue(props.get(PropKeys.queue).isJust) |
|
229 |
} |
|
230 | 104 |
} |
Also available in: Unified diff