|
19 | 19 |
|
20 | 20 | import static com.rabbitmq.client.amqp.Management.ExchangeType.FANOUT;
|
21 | 21 | import static com.rabbitmq.client.amqp.impl.TestConditions.BrokerVersion.RABBITMQ_4_1_0;
|
| 22 | +import static com.rabbitmq.client.amqp.impl.TestConditions.BrokerVersion.RABBITMQ_4_2_0; |
22 | 23 | import static com.rabbitmq.client.amqp.impl.TestUtils.*;
|
23 | 24 | import static java.nio.charset.StandardCharsets.*;
|
24 | 25 | import static java.util.concurrent.TimeUnit.SECONDS;
|
25 | 26 | import static org.apache.qpid.protonj2.client.DeliveryMode.AT_LEAST_ONCE;
|
26 | 27 | import static org.apache.qpid.protonj2.client.DeliveryState.released;
|
27 | 28 | import static org.assertj.core.api.Assertions.*;
|
28 | 29 | import static org.assertj.core.api.Assertions.assertThat;
|
| 30 | +import static org.assertj.core.api.InstanceOfAssertFactories.*; |
29 | 31 |
|
30 | 32 | import com.rabbitmq.client.amqp.Environment;
|
31 | 33 | import com.rabbitmq.client.amqp.Management;
|
@@ -423,4 +425,76 @@ void dynamicReceiver() throws Exception {
|
423 | 425 | assertThat(delivery.message().body()).isEqualTo(body);
|
424 | 426 | }
|
425 | 427 | }
|
| 428 | + |
| 429 | + @Test |
| 430 | + @BrokerVersionAtLeast(RABBITMQ_4_2_0) |
| 431 | + void refuseLinkSenderToMissingExchangeShouldReturnNotFound() throws Exception { |
| 432 | + try (Client client = client()) { |
| 433 | + org.apache.qpid.protonj2.client.Connection c = connection(client); |
| 434 | + Session s = c.openSession(); |
| 435 | + assertThatThrownBy( |
| 436 | + () -> ExceptionUtils.wrapGet(s.openSender("/exchanges/missing").openFuture())) |
| 437 | + .isInstanceOf(ClientLinkRemotelyClosedException.class) |
| 438 | + .asInstanceOf(throwable(ClientLinkRemotelyClosedException.class)) |
| 439 | + .matches(e -> "amqp:not-found".equals(e.getErrorCondition().condition())); |
| 440 | + checkSession(s); |
| 441 | + } |
| 442 | + } |
| 443 | + |
| 444 | + @Test |
| 445 | + @BrokerVersionAtLeast(RABBITMQ_4_2_0) |
| 446 | + void refuseLinkSenderToInvalidAddressShouldReturnInvalidField() throws Exception { |
| 447 | + try (Client client = client()) { |
| 448 | + org.apache.qpid.protonj2.client.Connection c = connection(client); |
| 449 | + Session s = c.openSession(); |
| 450 | + assertThatThrownBy(() -> ExceptionUtils.wrapGet(s.openSender("/fruit/orange").openFuture())) |
| 451 | + .isInstanceOf(ClientLinkRemotelyClosedException.class) |
| 452 | + .asInstanceOf(throwable(ClientLinkRemotelyClosedException.class)) |
| 453 | + .matches(e -> "amqp:invalid-field".equals(e.getErrorCondition().condition())); |
| 454 | + checkSession(s); |
| 455 | + } |
| 456 | + } |
| 457 | + |
| 458 | + @Test |
| 459 | + @BrokerVersionAtLeast(RABBITMQ_4_2_0) |
| 460 | + void refuseLinkReceiverToMissingQueueShouldReturnNotFound() throws Exception { |
| 461 | + try (Client client = client()) { |
| 462 | + org.apache.qpid.protonj2.client.Connection c = connection(client); |
| 463 | + Session s = c.openSession().openFuture().get(10, SECONDS); |
| 464 | + assertThatThrownBy( |
| 465 | + () -> |
| 466 | + ExceptionUtils.wrapGet( |
| 467 | + s.openReceiver("/queues/missing", new ReceiverOptions().creditWindow(0)) |
| 468 | + .openFuture())) |
| 469 | + .isInstanceOf(ClientLinkRemotelyClosedException.class) |
| 470 | + .asInstanceOf(throwable(ClientLinkRemotelyClosedException.class)) |
| 471 | + .matches(e -> "amqp:not-found".equals(e.getErrorCondition().condition())); |
| 472 | + checkSession(s); |
| 473 | + } |
| 474 | + } |
| 475 | + |
| 476 | + @Test |
| 477 | + @BrokerVersionAtLeast(RABBITMQ_4_2_0) |
| 478 | + void refuseLinkReceiverToInvalidAddressShouldReturnInvalidField() throws Exception { |
| 479 | + try (Client client = client()) { |
| 480 | + org.apache.qpid.protonj2.client.Connection c = connection(client); |
| 481 | + Session s = c.openSession().openFuture().get(10, SECONDS); |
| 482 | + assertThatThrownBy( |
| 483 | + () -> |
| 484 | + ExceptionUtils.wrapGet( |
| 485 | + s.openReceiver("/fruit/orange", new ReceiverOptions().creditWindow(0)) |
| 486 | + .openFuture())) |
| 487 | + .isInstanceOf(ClientLinkRemotelyClosedException.class) |
| 488 | + .asInstanceOf(throwable(ClientLinkRemotelyClosedException.class)) |
| 489 | + .matches(e -> "amqp:invalid-field".equals(e.getErrorCondition().condition())); |
| 490 | + checkSession(s); |
| 491 | + } |
| 492 | + } |
| 493 | + |
| 494 | + private static void checkSession(Session s) throws Exception { |
| 495 | + ReceiverOptions receiverOptions = new ReceiverOptions(); |
| 496 | + receiverOptions.sourceOptions().capabilities("temporary-queue"); |
| 497 | + Receiver receiver = s.openDynamicReceiver(receiverOptions); |
| 498 | + receiver.openFuture().get(10, SECONDS); |
| 499 | + } |
426 | 500 | }
|
0 commit comments