Search in sources :

Example 11 with ResourceLimits

use of org.eclipse.hono.util.ResourceLimits in project hono by eclipse.

the class HonoEventConnectionEventProducerTest method testConnectedSucceeds.

@Test
void testConnectedSucceeds(final VertxTestContext ctx) {
    final String tenantId = "tenant";
    final Device authenticatedDevice = new Device(tenantId, "device");
    tenant = new TenantObject(tenantId, true).setResourceLimits(new ResourceLimits().setMaxTtl(500));
    when(tenantClient.get(anyString(), any())).thenReturn(Future.succeededFuture(tenant));
    producer.connected(context, "device-internal-id", "custom-adapter", authenticatedDevice, new JsonObject(), null).onComplete(ctx.succeeding(ok -> {
        ctx.verify(() -> {
            verify(sender).sendEvent(eq(tenant), any(RegistrationAssertion.class), eq(EventConstants.EVENT_CONNECTION_NOTIFICATION_CONTENT_TYPE), any(), any(), any());
        });
        ctx.completeNow();
    }));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) ResourceLimits(org.eclipse.hono.util.ResourceLimits) EventSender(org.eclipse.hono.client.telemetry.EventSender) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RegistrationAssertion(org.eclipse.hono.util.RegistrationAssertion) Mockito.when(org.mockito.Mockito.when) TenantClient(org.eclipse.hono.client.registry.TenantClient) VertxExtension(io.vertx.junit5.VertxExtension) EventConstants(org.eclipse.hono.util.EventConstants) Future(io.vertx.core.Future) Device(org.eclipse.hono.auth.Device) Mockito.verify(org.mockito.Mockito.verify) TenantObject(org.eclipse.hono.util.TenantObject) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) TenantObject(org.eclipse.hono.util.TenantObject) Device(org.eclipse.hono.auth.Device) ResourceLimits(org.eclipse.hono.util.ResourceLimits) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 12 with ResourceLimits

use of org.eclipse.hono.util.ResourceLimits in project hono by eclipse.

the class PrometheusBasedAsyncCacheLoaderTest method testExecuteQuerySetsAuthHeader.

/**
 * Verifies that the Basic authentication header is set if username and password have been
 * configured.
 */
@Test
public void testExecuteQuerySetsAuthHeader() {
    config.setUsername("hono");
    config.setPassword("hono-secret");
    givenCurrentConnections(0);
    final TenantObject tenant = TenantObject.from(Constants.DEFAULT_TENANT, true).setResourceLimits(new ResourceLimits().setMaxConnections(10));
    final var key = new LimitedResourceKey(tenant.getTenantId(), (tenantId, ctx) -> Future.succeededFuture(tenant));
    final var result = loader.asyncLoad(key, executor);
    assertThat(result.isDone()).isTrue();
    verify(bufferReq).basicAuthentication(eq("hono"), eq("hono-secret"));
}
Also used : TenantObject(org.eclipse.hono.util.TenantObject) ResourceLimits(org.eclipse.hono.util.ResourceLimits) Test(org.junit.jupiter.api.Test)

Example 13 with ResourceLimits

use of org.eclipse.hono.util.ResourceLimits in project hono by eclipse.

the class ProtonBasedDownstreamSenderTest method testDownstreamEventHasCreationTimeAndTtl.

/**
 * Verifies that a downstream event always contains a creation-time
 * and a time-to-live as defined at the tenant level.
 */
@Test
public void testDownstreamEventHasCreationTimeAndTtl() {
    final TenantObject tenant = TenantObject.from(Constants.DEFAULT_TENANT, true);
    final RegistrationAssertion device = new RegistrationAssertion("4711");
    tenant.setResourceLimits(new ResourceLimits().setMaxTtl(60L));
    // WHEN sending a message without specifying any properties
    sender.sendEvent(tenant, device, "text/plain", Buffer.buffer("hello"), null, span.context());
    // THEN the message contains a creation-time
    verify(protonSender).send(argThat(message -> message.getCreationTime() > 0 && message.getTtl() == 60000L), VertxMockSupport.anyHandler());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) CsvSource(org.junit.jupiter.params.provider.CsvSource) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) AmqpClientUnitTestHelper(org.eclipse.hono.client.amqp.test.AmqpClientUnitTestHelper) HashMap(java.util.HashMap) ClientErrorException(org.eclipse.hono.client.ClientErrorException) Supplier(java.util.function.Supplier) Constants(org.eclipse.hono.util.Constants) EventBus(io.vertx.core.eventbus.EventBus) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) Message(org.apache.qpid.proton.message.Message) HonoConnection(org.eclipse.hono.client.HonoConnection) ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties) ResourceLimits(org.eclipse.hono.util.ResourceLimits) Tracer(io.opentracing.Tracer) NoopTracerFactory(io.opentracing.noop.NoopTracerFactory) Vertx(io.vertx.core.Vertx) ServerErrorException(org.eclipse.hono.client.ServerErrorException) RegistrationAssertion(org.eclipse.hono.util.RegistrationAssertion) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) MessageHelper(org.eclipse.hono.util.MessageHelper) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Mockito.verify(org.mockito.Mockito.verify) TenantObject(org.eclipse.hono.util.TenantObject) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Buffer(io.vertx.core.buffer.Buffer) VertxMockSupport(org.eclipse.hono.test.VertxMockSupport) Span(io.opentracing.Span) ProtonSender(io.vertx.proton.ProtonSender) SendMessageSampler(org.eclipse.hono.client.SendMessageSampler) NoopSpan(io.opentracing.noop.NoopSpan) QoS(org.eclipse.hono.util.QoS) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) TenantObject(org.eclipse.hono.util.TenantObject) RegistrationAssertion(org.eclipse.hono.util.RegistrationAssertion) ResourceLimits(org.eclipse.hono.util.ResourceLimits) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ResourceLimits (org.eclipse.hono.util.ResourceLimits)13 Test (org.junit.jupiter.api.Test)12 TenantObject (org.eclipse.hono.util.TenantObject)9 VertxTestContext (io.vertx.junit5.VertxTestContext)7 Truth.assertThat (com.google.common.truth.Truth.assertThat)6 VertxExtension (io.vertx.junit5.VertxExtension)6 Map (java.util.Map)6 RegistrationAssertion (org.eclipse.hono.util.RegistrationAssertion)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)6 JsonObject (io.vertx.core.json.JsonObject)5 Mockito.mock (org.mockito.Mockito.mock)5 Mockito.when (org.mockito.Mockito.when)5 Tracer (io.opentracing.Tracer)4 NoopSpan (io.opentracing.noop.NoopSpan)4 Vertx (io.vertx.core.Vertx)4 Buffer (io.vertx.core.buffer.Buffer)4 EventBus (io.vertx.core.eventbus.EventBus)4 HttpURLConnection (java.net.HttpURLConnection)4 Constants (org.eclipse.hono.util.Constants)4