use of org.apache.qpid.proton.engine.Record in project hono by eclipse.
the class AmqpServiceBaseTest method newConnection.
private static ProtonConnection newConnection(final HonoUser user) {
final Record attachments = new RecordImpl();
attachments.set(Constants.KEY_CONNECTION_ID, String.class, CON_ID);
attachments.set(Constants.KEY_CLIENT_PRINCIPAL, HonoUser.class, user);
final ProtonConnection con = mock(ProtonConnection.class);
when(con.attachments()).thenReturn(attachments);
when(con.getRemoteContainer()).thenReturn("test-client");
return con;
}
use of org.apache.qpid.proton.engine.Record in project hono by eclipse.
the class AbstractHonoClientTest method testCreateSenderFails.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void testCreateSenderFails(final Supplier<ErrorCondition> errorSupplier, final Predicate<Throwable> failureAssertion) {
final Record attachments = new RecordImpl();
final ProtonSender sender = mock(ProtonSender.class);
when(sender.getRemoteCondition()).thenReturn(errorSupplier.get());
when(sender.attachments()).thenReturn(attachments);
final ProtonConnection con = mock(ProtonConnection.class);
when(con.createSender(anyString())).thenReturn(sender);
final Future<ProtonSender> result = AbstractHonoClient.createSender(context, props, con, "target", ProtonQoS.AT_LEAST_ONCE, null);
final ArgumentCaptor<Handler> openHandler = ArgumentCaptor.forClass(Handler.class);
verify(sender).openHandler(openHandler.capture());
openHandler.getValue().handle(Future.failedFuture(new IllegalStateException()));
assertTrue(result.failed());
assertTrue(failureAssertion.test(result.cause()));
}
use of org.apache.qpid.proton.engine.Record in project vertx-proton by vert-x3.
the class ProtonReceiverImplTest method testAttachments.
@Test
public void testAttachments() {
Connection conn = Connection.Factory.create();
Session sess = conn.session();
Receiver r = sess.receiver("name");
ProtonReceiverImpl receiver = new ProtonReceiverImpl(r);
Record attachments = receiver.attachments();
assertNotNull("Expected attachments but got null", attachments);
assertSame("Got different attachments on subsequent call", attachments, receiver.attachments());
String key = "My-Connection-Key";
assertNull("Expected attachment to be null", attachments.get(key, Connection.class));
attachments.set(key, Connection.class, conn);
assertNotNull("Expected attachment to be returned", attachments.get(key, Connection.class));
assertSame("Expected attachment to be given object", conn, attachments.get(key, Connection.class));
}
use of org.apache.qpid.proton.engine.Record in project hono by eclipse.
the class AbstractHonoClientTest method testCreateReceiverFails.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void testCreateReceiverFails(final Supplier<ErrorCondition> errorSupplier, final Predicate<Throwable> failureAssertion) {
final Record attachments = new RecordImpl();
final ProtonReceiver receiver = mock(ProtonReceiver.class);
when(receiver.getRemoteCondition()).thenReturn(errorSupplier.get());
when(receiver.attachments()).thenReturn(attachments);
final ProtonConnection con = mock(ProtonConnection.class);
when(con.createReceiver(anyString())).thenReturn(receiver);
final Future<ProtonReceiver> result = AbstractHonoClient.createReceiver(context, props, con, "source", ProtonQoS.AT_LEAST_ONCE, (delivery, msg) -> {
}, null);
final ArgumentCaptor<Handler> openHandler = ArgumentCaptor.forClass(Handler.class);
verify(receiver).openHandler(openHandler.capture());
openHandler.getValue().handle(Future.failedFuture(new IllegalStateException()));
assertTrue(result.failed());
assertTrue(failureAssertion.test(result.cause()));
}
use of org.apache.qpid.proton.engine.Record in project hono by eclipse.
the class HonoMessagingTest method newConnection.
private static ProtonConnection newConnection(final HonoUser user) {
final Record attachments = new RecordImpl();
attachments.set(Constants.KEY_CONNECTION_ID, String.class, CON_ID);
attachments.set(Constants.KEY_CLIENT_PRINCIPAL, HonoUser.class, user);
final ProtonConnection con = mock(ProtonConnection.class);
when(con.attachments()).thenReturn(attachments);
when(con.getRemoteContainer()).thenReturn("test-client");
return con;
}
Aggregations