1
1
/*
2
- * Copyright 2002-2021 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -365,24 +365,33 @@ public void testNoListenerAllowed2() {
365
365
@ SuppressWarnings ("unchecked" )
366
366
public void testRoutingConnectionFactory () throws Exception {
367
367
org .springframework .amqp .rabbit .connection .ConnectionFactory connectionFactory1 =
368
- Mockito . mock (org .springframework .amqp .rabbit .connection .ConnectionFactory .class );
368
+ mock (org .springframework .amqp .rabbit .connection .ConnectionFactory .class );
369
369
org .springframework .amqp .rabbit .connection .ConnectionFactory connectionFactory2 =
370
- Mockito .mock (org .springframework .amqp .rabbit .connection .ConnectionFactory .class );
370
+ mock (org .springframework .amqp .rabbit .connection .ConnectionFactory .class );
371
+ org .springframework .amqp .rabbit .connection .ConnectionFactory connectionFactory3 =
372
+ mock (org .springframework .amqp .rabbit .connection .ConnectionFactory .class );
373
+ org .springframework .amqp .rabbit .connection .ConnectionFactory connectionFactory4 =
374
+ mock (org .springframework .amqp .rabbit .connection .ConnectionFactory .class );
371
375
Map <Object , org .springframework .amqp .rabbit .connection .ConnectionFactory > factories =
372
376
new HashMap <Object , org .springframework .amqp .rabbit .connection .ConnectionFactory >(2 );
373
377
factories .put ("foo" , connectionFactory1 );
374
378
factories .put ("bar" , connectionFactory2 );
379
+ factories .put ("baz" , connectionFactory3 );
380
+ factories .put ("qux" , connectionFactory4 );
375
381
376
382
377
383
AbstractRoutingConnectionFactory connectionFactory = new SimpleRoutingConnectionFactory ();
378
384
connectionFactory .setTargetConnectionFactories (factories );
379
385
380
386
final RabbitTemplate template = new RabbitTemplate (connectionFactory );
381
- Expression expression = new SpelExpressionParser ()
387
+ Expression sendExpression = new SpelExpressionParser ()
382
388
.parseExpression ("T(org.springframework.amqp.rabbit.core.RabbitTemplateTests)" +
383
389
".LOOKUP_KEY_COUNT.getAndIncrement() % 2 == 0 ? 'foo' : 'bar'" );
384
- template .setSendConnectionFactorySelectorExpression (expression );
385
- template .setReceiveConnectionFactorySelectorExpression (expression );
390
+ template .setSendConnectionFactorySelectorExpression (sendExpression );
391
+ Expression receiveExpression = new SpelExpressionParser ()
392
+ .parseExpression ("T(org.springframework.amqp.rabbit.core.RabbitTemplateTests)" +
393
+ ".LOOKUP_KEY_COUNT.getAndIncrement() % 2 == 0 ? 'baz' : 'qux'" );
394
+ template .setReceiveConnectionFactorySelectorExpression (receiveExpression );
386
395
387
396
for (int i = 0 ; i < 3 ; i ++) {
388
397
try {
@@ -405,8 +414,10 @@ public void testRoutingConnectionFactory() throws Exception {
405
414
}
406
415
}
407
416
408
- Mockito .verify (connectionFactory1 , Mockito .times (5 )).createConnection ();
409
- Mockito .verify (connectionFactory2 , Mockito .times (4 )).createConnection ();
417
+ Mockito .verify (connectionFactory1 , times (2 )).createConnection ();
418
+ Mockito .verify (connectionFactory2 , times (1 )).createConnection ();
419
+ Mockito .verify (connectionFactory3 , times (3 )).createConnection ();
420
+ Mockito .verify (connectionFactory4 , times (3 )).createConnection ();
410
421
}
411
422
412
423
@ Test
0 commit comments