use of org.eclipse.hono.config.ClientConfigProperties in project hono by eclipse.
the class StandaloneEventApiTest method prepareHonoServer.
/**
* Sets up Hono Messaging service.
*
* @param ctx The test context.
*/
@BeforeClass
public static void prepareHonoServer(final TestContext ctx) {
vertx = Vertx.vertx();
downstreamAdapter = new MessageDiscardingDownstreamAdapter(vertx);
final HonoMessagingConfigProperties configProperties = new HonoMessagingConfigProperties();
configProperties.setInsecurePort(0);
final EventEndpoint eventEndpoint = new EventEndpoint(vertx);
eventEndpoint.setMetrics(mock(MessagingMetrics.class));
eventEndpoint.setEventAdapter(downstreamAdapter);
eventEndpoint.setRegistrationAssertionValidator(assertionHelper);
eventEndpoint.setConfiguration(configProperties);
server = new HonoMessaging();
server.setSaslAuthenticatorFactory(new HonoSaslAuthenticatorFactory(TestSupport.createAuthenticationService(createUser())));
server.setConfig(configProperties);
server.addEndpoint(eventEndpoint);
Future<String> serverTracker = Future.future();
vertx.deployVerticle(server, serverTracker.completer());
serverTracker.compose(s -> {
final ClientConfigProperties clientProps = new ClientConfigProperties();
clientProps.setName("test");
clientProps.setHost(server.getInsecurePortBindAddress());
clientProps.setPort(server.getInsecurePort());
clientProps.setUsername(USER);
clientProps.setPassword(PWD);
client = new HonoClientImpl(vertx, clientProps);
return client.connect(new ProtonClientOptions());
}).setHandler(ctx.asyncAssertSuccess());
}
use of org.eclipse.hono.config.ClientConfigProperties in project hono by eclipse.
the class ClientTestBase method connect.
/**
* Sets up the environment:
* <ol>
* <li>connect to the AMQP messaging network</li>
* <li>connects to the Hono Server</li>
* <li>connects to the Hono Device Registry</li>
* <li>creates a RegistrationClient for TEST_TENANT_ID</li>
* <li>creates a MessageSender for TEST_TENANT_ID</li>
* </ul>
*
* @param ctx The test context
*/
@Before
public void connect(final TestContext ctx) {
final ClientConfigProperties downstreamProps = new ClientConfigProperties();
downstreamProps.setHost(IntegrationTestSupport.DOWNSTREAM_HOST);
downstreamProps.setPort(IntegrationTestSupport.DOWNSTREAM_PORT);
downstreamProps.setPathSeparator(IntegrationTestSupport.PATH_SEPARATOR);
downstreamProps.setUsername(IntegrationTestSupport.RESTRICTED_CONSUMER_NAME);
downstreamProps.setPassword(IntegrationTestSupport.RESTRICTED_CONSUMER_PWD);
downstreamClient = new HonoClientImpl(vertx, ConnectionFactoryBuilder.newBuilder(downstreamProps).vertx(vertx).build(), downstreamProps);
final ClientConfigProperties honoProps = new ClientConfigProperties();
honoProps.setHost(IntegrationTestSupport.HONO_HOST);
honoProps.setPort(IntegrationTestSupport.HONO_PORT);
honoProps.setUsername(IntegrationTestSupport.HONO_USER);
honoProps.setPassword(IntegrationTestSupport.HONO_PWD);
honoClient = new HonoClientImpl(vertx, ConnectionFactoryBuilder.newBuilder(honoProps).vertx(vertx).build(), honoProps);
final ClientConfigProperties registryProps = new ClientConfigProperties();
registryProps.setHost(IntegrationTestSupport.HONO_DEVICEREGISTRY_HOST);
registryProps.setPort(IntegrationTestSupport.HONO_DEVICEREGISTRY_AMQP_PORT);
registryProps.setUsername(IntegrationTestSupport.HONO_USER);
registryProps.setPassword(IntegrationTestSupport.HONO_PWD);
honoDeviceRegistryClient = new HonoClientImpl(vertx, ConnectionFactoryBuilder.newBuilder(registryProps).vertx(vertx).build(), registryProps);
final ProtonClientOptions options = new ProtonClientOptions();
// connect to AMQP messaging network
final Future<HonoClient> downstreamTracker = downstreamClient.connect(options);
// create sender
final Future<MessageSender> senderTracker = honoClient.connect(options).compose(connectedClient -> createProducer(TEST_TENANT_ID)).map(s -> {
sender = s;
return s;
});
// create registration client
final Future<RegistrationClient> registrationClientTracker = honoDeviceRegistryClient.connect(options).compose(connectedClient -> connectedClient.getOrCreateRegistrationClient(TEST_TENANT_ID)).map(c -> {
registrationClient = c;
return c;
});
CompositeFuture.all(downstreamTracker, senderTracker, registrationClientTracker).setHandler(ctx.asyncAssertSuccess(s -> {
LOGGER.info("connections to Hono server, Hono device registry and AMQP messaging network established");
}));
}
use of org.eclipse.hono.config.ClientConfigProperties in project hono by eclipse.
the class AbstractHonoClientTest method setUp.
/**
* Sets up the fixture.
*/
@SuppressWarnings("unchecked")
@Before
public void setUp() {
props = new ClientConfigProperties();
context = mock(Context.class);
doAnswer(invocation -> {
final Handler<Void> handler = invocation.getArgument(0);
handler.handle(null);
return null;
}).when(context).runOnContext(any(Handler.class));
}
use of org.eclipse.hono.config.ClientConfigProperties in project hono by eclipse.
the class EventConsumerImplTest method testCreateRegistersBiConsumerAsMessageHandler.
/**
* Verifies that the message delivery for a received event is forwarded to the
* registered event consumer.
*
* @param ctx The test context.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testCreateRegistersBiConsumerAsMessageHandler(final TestContext ctx) {
// GIVEN an event consumer that releases all messages
final Async consumerCreation = ctx.async();
final BiConsumer<ProtonDelivery, Message> eventConsumer = (delivery, message) -> {
ProtonHelper.released(delivery, true);
};
final RecordImpl attachments = new RecordImpl();
final Source source = mock(Source.class);
when(source.toString()).thenReturn("event/tenant");
final ProtonReceiver receiver = mock(ProtonReceiver.class);
when(receiver.getSource()).thenReturn(source);
when(receiver.attachments()).thenReturn(attachments);
when(receiver.getRemoteQoS()).thenReturn(ProtonQoS.AT_LEAST_ONCE);
when(receiver.open()).then(answer -> {
consumerCreation.complete();
return receiver;
});
final ProtonConnection con = mock(ProtonConnection.class);
when(con.createReceiver(anyString())).thenReturn(receiver);
when(receiver.openHandler(any(Handler.class))).thenAnswer(invocation -> {
final Handler handler = invocation.getArgument(0);
handler.handle(Future.succeededFuture(receiver));
return receiver;
});
final ArgumentCaptor<ProtonMessageHandler> messageHandler = ArgumentCaptor.forClass(ProtonMessageHandler.class);
EventConsumerImpl.create(vertx.getOrCreateContext(), new ClientConfigProperties(), con, "tenant", eventConsumer, open -> {
}, remoteDetach -> {
});
consumerCreation.await();
verify(receiver).handler(messageHandler.capture());
// WHEN an event is received
final ProtonDelivery delivery = mock(ProtonDelivery.class);
final Message msg = mock(Message.class);
messageHandler.getValue().handle(delivery, msg);
// THEN the message is released and settled
verify(delivery).disposition(any(Released.class), eq(Boolean.TRUE));
}
use of org.eclipse.hono.config.ClientConfigProperties in project hono by eclipse.
the class EventSenderImplTest method setUp.
/**
* Sets up the fixture.
*/
@Before
public void setUp() {
vertx = mock(Vertx.class);
context = HonoClientUnitTestHelper.mockContext(vertx);
sender = HonoClientUnitTestHelper.mockProtonSender();
config = new ClientConfigProperties();
}
Aggregations