Search in sources :

Example 1 with TenantClient

use of org.eclipse.hono.client.TenantClient in project hono by eclipse.

the class TenantAmqpIT method prepareDeviceRegistry.

/**
 * Starts the device registry, connects a client and provides a tenant API client.
 *
 * @param ctx The vert.x test context.
 */
@BeforeClass
public static void prepareDeviceRegistry(final TestContext ctx) {
    client = DeviceRegistryAmqpTestSupport.prepareDeviceRegistryClient(vertx);
    client.connect(new ProtonClientOptions()).compose(c -> c.getOrCreateTenantClient()).setHandler(ctx.asyncAssertSuccess(r -> {
        tenantClient = r;
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) TestContext(io.vertx.ext.unit.TestContext) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) Constants(org.eclipse.hono.util.Constants) TimeUnit(java.util.concurrent.TimeUnit) Rule(org.junit.Rule) ProtonClientOptions(io.vertx.proton.ProtonClientOptions) TenantClient(org.eclipse.hono.client.TenantClient) Timeout(org.junit.rules.Timeout) HonoClient(org.eclipse.hono.client.HonoClient) ProtonClientOptions(io.vertx.proton.ProtonClientOptions) BeforeClass(org.junit.BeforeClass)

Example 2 with TenantClient

use of org.eclipse.hono.client.TenantClient in project hono by eclipse.

the class AbstractVertxBasedHttpProtocolAdapterTest method setup.

/**
 * Sets up common fixture.
 */
@SuppressWarnings("unchecked")
@Before
public void setup() {
    config = new HttpProtocolAdapterProperties();
    config.setInsecurePortEnabled(true);
    regClient = mock(RegistrationClient.class);
    final JsonObject result = new JsonObject().put(RegistrationConstants.FIELD_ASSERTION, "token");
    when(regClient.assertRegistration(anyString(), any())).thenReturn(Future.succeededFuture(result));
    tenantClient = mock(TenantClient.class);
    when(tenantClient.get(anyString())).thenAnswer(invocation -> {
        return Future.succeededFuture(TenantObject.from(invocation.getArgument(0), true));
    });
    tenantServiceClient = mock(HonoClient.class);
    when(tenantServiceClient.connect(any(Handler.class))).thenReturn(Future.succeededFuture(tenantServiceClient));
    when(tenantServiceClient.getOrCreateTenantClient()).thenReturn(Future.succeededFuture(tenantClient));
    messagingClient = mock(HonoClient.class);
    when(messagingClient.connect(any(Handler.class))).thenReturn(Future.succeededFuture(messagingClient));
    registrationServiceClient = mock(HonoClient.class);
    when(registrationServiceClient.connect(any(Handler.class))).thenReturn(Future.succeededFuture(registrationServiceClient));
    when(registrationServiceClient.getOrCreateRegistrationClient(anyString())).thenReturn(Future.succeededFuture(regClient));
    credentialsAuthProvider = mock(HonoClientBasedAuthProvider.class);
    when(credentialsAuthProvider.start()).thenReturn(Future.succeededFuture());
}
Also used : HonoClient(org.eclipse.hono.client.HonoClient) RegistrationClient(org.eclipse.hono.client.RegistrationClient) TenantClient(org.eclipse.hono.client.TenantClient) JsonObject(io.vertx.core.json.JsonObject) Handler(io.vertx.core.Handler) HonoClientBasedAuthProvider(org.eclipse.hono.service.auth.device.HonoClientBasedAuthProvider) Before(org.junit.Before)

Example 3 with TenantClient

use of org.eclipse.hono.client.TenantClient in project hono by eclipse.

the class AbstractVertxBasedMqttProtocolAdapterTest method setup.

/**
 * Creates clients for the needed micro services and sets the configuration to enable the insecure port.
 */
@Before
@SuppressWarnings("unchecked")
public void setup() {
    config = new ProtocolAdapterProperties();
    config.setInsecurePortEnabled(true);
    regClient = mock(RegistrationClient.class);
    final JsonObject result = new JsonObject().put(RegistrationConstants.FIELD_ASSERTION, "token");
    when(regClient.assertRegistration(anyString(), any())).thenReturn(Future.succeededFuture(result));
    tenantClient = mock(TenantClient.class);
    when(tenantClient.get(anyString())).thenAnswer(invocation -> {
        return Future.succeededFuture(TenantObject.from(invocation.getArgument(0), true));
    });
    tenantServiceClient = mock(HonoClient.class);
    when(tenantServiceClient.connect(any(Handler.class))).thenReturn(Future.succeededFuture(tenantServiceClient));
    when(tenantServiceClient.getOrCreateTenantClient()).thenReturn(Future.succeededFuture(tenantClient));
    messagingClient = mock(HonoClient.class);
    when(messagingClient.connect(any(Handler.class))).thenReturn(Future.succeededFuture(messagingClient));
    deviceRegistrationServiceClient = mock(HonoClient.class);
    when(deviceRegistrationServiceClient.connect(any(Handler.class))).thenReturn(Future.succeededFuture(deviceRegistrationServiceClient));
    when(deviceRegistrationServiceClient.getOrCreateRegistrationClient(anyString())).thenReturn(Future.succeededFuture(regClient));
    credentialsAuthProvider = mock(HonoClientBasedAuthProvider.class);
    when(credentialsAuthProvider.start()).thenReturn(Future.succeededFuture());
}
Also used : ProtocolAdapterProperties(org.eclipse.hono.config.ProtocolAdapterProperties) HonoClient(org.eclipse.hono.client.HonoClient) RegistrationClient(org.eclipse.hono.client.RegistrationClient) TenantClient(org.eclipse.hono.client.TenantClient) JsonObject(io.vertx.core.json.JsonObject) Handler(io.vertx.core.Handler) HonoClientBasedAuthProvider(org.eclipse.hono.service.auth.device.HonoClientBasedAuthProvider) Before(org.junit.Before)

Aggregations

HonoClient (org.eclipse.hono.client.HonoClient)3 TenantClient (org.eclipse.hono.client.TenantClient)3 Handler (io.vertx.core.Handler)2 JsonObject (io.vertx.core.json.JsonObject)2 RegistrationClient (org.eclipse.hono.client.RegistrationClient)2 HonoClientBasedAuthProvider (org.eclipse.hono.service.auth.device.HonoClientBasedAuthProvider)2 Before (org.junit.Before)2 Vertx (io.vertx.core.Vertx)1 TestContext (io.vertx.ext.unit.TestContext)1 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)1 ProtonClientOptions (io.vertx.proton.ProtonClientOptions)1 HttpURLConnection (java.net.HttpURLConnection)1 TimeUnit (java.util.concurrent.TimeUnit)1 ServiceInvocationException (org.eclipse.hono.client.ServiceInvocationException)1 ProtocolAdapterProperties (org.eclipse.hono.config.ProtocolAdapterProperties)1 Constants (org.eclipse.hono.util.Constants)1 AfterClass (org.junit.AfterClass)1 BeforeClass (org.junit.BeforeClass)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1