Search in sources :

Example 1 with HonoClientBasedAuthProvider

use of org.eclipse.hono.service.auth.device.HonoClientBasedAuthProvider in project hono by eclipse.

the class AbstractProtocolAdapterBaseTest method testStartInternalConnectsToServices.

/**
 * Verifies that the adapter connects to required services during
 * startup and invokes the <em>doStart</em> method.
 *
 * @param ctx The vert.x test context.
 */
@SuppressWarnings("unchecked")
@Test
public void testStartInternalConnectsToServices(final TestContext ctx) {
    // GIVEN an adapter configured with service clients
    final Handler<Void> startupHandler = mock(Handler.class);
    adapter = newProtocolAdapter(properties, "test", startupHandler);
    final HonoClient tenantService = mock(HonoClient.class);
    when(tenantService.connect(any(Handler.class))).thenReturn(Future.succeededFuture(tenantService));
    adapter.setTenantServiceClient(tenantService);
    final HonoClient registrationService = mock(HonoClient.class);
    when(registrationService.connect(any(Handler.class))).thenReturn(Future.succeededFuture(registrationService));
    adapter.setRegistrationServiceClient(registrationService);
    final HonoClient messagingService = mock(HonoClient.class);
    when(messagingService.connect(any(Handler.class))).thenReturn(Future.succeededFuture(messagingService));
    adapter.setHonoMessagingClient(messagingService);
    final HonoClientBasedAuthProvider authProvider = mock(HonoClientBasedAuthProvider.class);
    when(authProvider.start()).thenReturn(Future.succeededFuture());
    adapter.setCredentialsAuthProvider(authProvider);
    // WHEN starting the adapter
    adapter.startInternal().setHandler(ctx.asyncAssertSuccess(ok -> {
        // THEN the service clients have connected
        verify(tenantService).connect(any(Handler.class));
        verify(registrationService).connect(any(Handler.class));
        verify(messagingService).connect(any(Handler.class));
        verify(authProvider).start();
        // and the startup handler has been invoked
        verify(startupHandler).handle(null);
    }));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) HttpURLConnection(java.net.HttpURLConnection) TestContext(io.vertx.ext.unit.TestContext) RunWith(org.junit.runner.RunWith) ClientErrorException(org.eclipse.hono.client.ClientErrorException) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) Assert.assertThat(org.junit.Assert.assertThat) Timeout(org.junit.rules.Timeout) Message(org.apache.qpid.proton.message.Message) RegistrationClient(org.eclipse.hono.client.RegistrationClient) JsonObject(io.vertx.core.json.JsonObject) HonoClient(org.eclipse.hono.client.HonoClient) Before(org.junit.Before) ProtocolAdapterProperties(org.eclipse.hono.config.ProtocolAdapterProperties) RegistrationConstants(org.eclipse.hono.util.RegistrationConstants) Test(org.junit.Test) ProtonHelper(io.vertx.proton.ProtonHelper) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) MessageHelper(org.eclipse.hono.util.MessageHelper) Future(io.vertx.core.Future) Mockito(org.mockito.Mockito) HonoClientBasedAuthProvider(org.eclipse.hono.service.auth.device.HonoClientBasedAuthProvider) Rule(org.junit.Rule) Device(org.eclipse.hono.service.auth.device.Device) Handler(io.vertx.core.Handler) HonoClient(org.eclipse.hono.client.HonoClient) Handler(io.vertx.core.Handler) HonoClientBasedAuthProvider(org.eclipse.hono.service.auth.device.HonoClientBasedAuthProvider) Test(org.junit.Test)

Aggregations

Future (io.vertx.core.Future)1 Handler (io.vertx.core.Handler)1 JsonObject (io.vertx.core.json.JsonObject)1 TestContext (io.vertx.ext.unit.TestContext)1 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)1 ProtonHelper (io.vertx.proton.ProtonHelper)1 HttpURLConnection (java.net.HttpURLConnection)1 Message (org.apache.qpid.proton.message.Message)1 ClientErrorException (org.eclipse.hono.client.ClientErrorException)1 HonoClient (org.eclipse.hono.client.HonoClient)1 RegistrationClient (org.eclipse.hono.client.RegistrationClient)1 ServiceInvocationException (org.eclipse.hono.client.ServiceInvocationException)1 ProtocolAdapterProperties (org.eclipse.hono.config.ProtocolAdapterProperties)1 Device (org.eclipse.hono.service.auth.device.Device)1 HonoClientBasedAuthProvider (org.eclipse.hono.service.auth.device.HonoClientBasedAuthProvider)1 MessageHelper (org.eclipse.hono.util.MessageHelper)1 RegistrationConstants (org.eclipse.hono.util.RegistrationConstants)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1 Assert.assertThat (org.junit.Assert.assertThat)1 Before (org.junit.Before)1