|
| 1 | +package com.rabbitmq.client.test.functional; |
| 2 | + |
| 3 | +import com.rabbitmq.client.MessageProperties; |
| 4 | +import com.rabbitmq.client.test.BrokerTestCase; |
| 5 | +import com.rabbitmq.tools.Host; |
| 6 | + |
| 7 | +import java.io.IOException; |
| 8 | +import java.util.HashMap; |
| 9 | +import java.util.Map; |
| 10 | + |
| 11 | +/** |
| 12 | + * |
| 13 | + */ |
| 14 | +public class Policies extends BrokerTestCase { |
| 15 | + @Override protected void createResources() throws IOException { |
| 16 | + Host.rabbitmqctl("set_policy AE ^has-ae {\\\"alternate-exchange\\\":\\\"ae\\\"}"); |
| 17 | + channel.exchangeDeclare("has-ae", "fanout"); |
| 18 | + Map<String, Object> args = new HashMap<String, Object>(); |
| 19 | + args.put("alternate-exchange", "ae2"); |
| 20 | + channel.exchangeDeclare("has-ae-args", "fanout", false, false, args); |
| 21 | + } |
| 22 | + |
| 23 | + public void testAlternateExchange() throws IOException { |
| 24 | + String q = channel.queueDeclare().getQueue(); |
| 25 | + channel.exchangeDeclare("ae", "fanout", false, true, null); |
| 26 | + channel.queueBind(q, "ae", ""); |
| 27 | + channel.basicPublish("has-ae", "", MessageProperties.BASIC, "".getBytes()); |
| 28 | + assertDelivered(q, 1); |
| 29 | + } |
| 30 | + |
| 31 | + // i.e. the argument takes priority over the policy |
| 32 | + public void testAlternateExchangeArgs() throws IOException { |
| 33 | + String q = channel.queueDeclare().getQueue(); |
| 34 | + channel.exchangeDeclare("ae2", "fanout", false, true, null); |
| 35 | + channel.queueBind(q, "ae2", ""); |
| 36 | + channel.basicPublish("has-ae-args", "", MessageProperties.BASIC, "".getBytes()); |
| 37 | + assertDelivered(q, 1); |
| 38 | + } |
| 39 | + |
| 40 | + @Override protected void releaseResources() throws IOException { |
| 41 | + Host.rabbitmqctl("clear_policy AE"); |
| 42 | + channel.exchangeDelete("has-ae"); |
| 43 | + } |
| 44 | +} |
0 commit comments