|
| 1 | +package com.rabbitmq.client.test.functional; |
| 2 | + |
| 3 | +import com.rabbitmq.client.AMQP; |
| 4 | +import com.rabbitmq.client.Channel; |
| 5 | +import com.rabbitmq.client.test.BrokerTestCase; |
| 6 | + |
| 7 | +import java.io.IOException; |
| 8 | +import java.util.HashMap; |
| 9 | + |
| 10 | +public class HeadersExchangeValidation extends BrokerTestCase { |
| 11 | + |
| 12 | + public void testHeadersValidation() throws IOException |
| 13 | + { |
| 14 | + AMQP.Queue.DeclareOk ok = channel.queueDeclare(); |
| 15 | + String queue = ok.getQueue(); |
| 16 | + |
| 17 | + HashMap<String, Object> arguments = new HashMap<String, Object>(); |
| 18 | + failBind(queue, arguments); |
| 19 | + |
| 20 | + arguments.put("x-match", 23); |
| 21 | + failBind(queue, arguments); |
| 22 | + |
| 23 | + arguments.put("x-match", "all or any I don't mind"); |
| 24 | + failBind(queue, arguments); |
| 25 | + |
| 26 | + arguments.put("x-match", "all"); |
| 27 | + succeedBind(queue, arguments); |
| 28 | + |
| 29 | + arguments.put("x-match", "any"); |
| 30 | + succeedBind(queue, arguments); |
| 31 | + } |
| 32 | + |
| 33 | + private void failBind(String queue, HashMap<String, Object> arguments) { |
| 34 | + try { |
| 35 | + Channel ch = connection.createChannel(); |
| 36 | + ch.queueBind(queue, "amq.headers", "", arguments); |
| 37 | + fail("Expected failure"); |
| 38 | + } catch (IOException e) { |
| 39 | + checkShutdownSignal(AMQP.PRECONDITION_FAILED, e); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + private void succeedBind(String queue, HashMap<String, Object> arguments) throws IOException { |
| 44 | + Channel ch = connection.createChannel(); |
| 45 | + ch.queueBind(queue, "amq.headers", "", arguments); |
| 46 | + ch.close(); |
| 47 | + } |
| 48 | +} |
0 commit comments