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