use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class EventHttpIT method testEventIsRejectedForUnsupportedQosLevel.
/**
* Checks an event with an unsupported device QoS level is rejected.
*
* @param ctx The test context.
*
* @throws InterruptedException if the test fails.
*/
@Test
public void testEventIsRejectedForUnsupportedQosLevel(final VertxTestContext ctx) throws InterruptedException {
final VertxTestContext setup = new VertxTestContext();
final Tenant tenant = new Tenant();
final MultiMap requestHeaders = MultiMap.caseInsensitiveMultiMap().add(HttpHeaders.CONTENT_TYPE, "text/plain").add(HttpHeaders.AUTHORIZATION, authorization).add(HttpHeaders.ORIGIN, ORIGIN_URI).add(Constants.HEADER_QOS_LEVEL, String.valueOf(QoS.AT_MOST_ONCE.ordinal()));
helper.registry.addDeviceForTenant(tenantId, tenant, deviceId, PWD).onComplete(setup.succeedingThenComplete());
assertThat(setup.awaitCompletion(5, TimeUnit.SECONDS)).isTrue();
if (setup.failed()) {
ctx.failNow(setup.causeOfFailure());
return;
}
httpClient.create(getEndpointUri(), Buffer.buffer("hello"), requestHeaders, ResponsePredicate.status(HttpURLConnection.HTTP_BAD_REQUEST)).onComplete(ctx.succeedingThenComplete());
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class EventHttpIT method testEventMessageAlreadySentIsDeliveredWhenConsumerConnects.
/**
* Verifies that an event message from a device has been successfully sent and a north bound application,
* which connects after the event has been sent, can successfully receive those event message.
*
* @param ctx The vert.x test context.
* @throws InterruptedException if test execution gets interrupted.
*/
@Test
public void testEventMessageAlreadySentIsDeliveredWhenConsumerConnects(final VertxTestContext ctx) throws InterruptedException {
final VertxTestContext setup = new VertxTestContext();
final String messagePayload = UUID.randomUUID().toString();
final MultiMap requestHeaders = MultiMap.caseInsensitiveMultiMap().add(HttpHeaders.CONTENT_TYPE, "text/plain").add(HttpHeaders.AUTHORIZATION, authorization).add(HttpHeaders.ORIGIN, ORIGIN_URI);
helper.registry.addDeviceForTenant(tenantId, new Tenant(), deviceId, PWD).onComplete(setup.succeedingThenComplete());
assertThat(setup.awaitCompletion(IntegrationTestSupport.getTestSetupTimeout(), TimeUnit.SECONDS)).isTrue();
if (setup.failed()) {
ctx.failNow(setup.causeOfFailure());
return;
}
// WHEN a device that belongs to the tenant publishes an event
httpClient.create(getEndpointUri(), Buffer.buffer(messagePayload), requestHeaders, ResponsePredicate.status(HttpURLConnection.HTTP_ACCEPTED)).onSuccess(eventSent -> {
// THEN create a consumer once the event message has been successfully sent
createConsumer(tenantId, msg -> {
// THEN verify that the event message has been received by the consumer
logger.debug("event message has been received by the consumer");
ctx.verify(() -> assertThat(msg.getPayload().toString()).isEqualTo(messagePayload));
ctx.completeNow();
});
}).onFailure(ctx::failNow);
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class TelemetryHttpIT method testUploadMessageFailsForNoConsumer.
/**
* Verifies that the upload of a telemetry message fails with a 503 status code
* when there is no consumer.
*
* @param ctx The test context
*/
@Test
@AssumeMessagingSystem(type = MessagingType.amqp)
public void testUploadMessageFailsForNoConsumer(final VertxTestContext ctx) {
// GIVEN a device
final Tenant tenant = new Tenant();
helper.registry.addDeviceForTenant(tenantId, tenant, deviceId, PWD).compose(ok -> {
// WHEN the device tries to upload a telemetry message while there is no consumer for it
final MultiMap requestHeaders = MultiMap.caseInsensitiveMultiMap().add(HttpHeaders.CONTENT_TYPE, "text/plain").add(HttpHeaders.AUTHORIZATION, authorization);
return httpClient.create(getEndpointUri(), Buffer.buffer("hello"), requestHeaders, // THEN the message gets rejected by the HTTP adapter with a 503
ResponsePredicate.status(HttpURLConnection.HTTP_UNAVAILABLE));
}).onComplete(ctx.succeeding(response -> {
ctx.verify(() -> {
final var body = response.bodyAsJsonObject();
assertThat(body.getString(RequestResponseApiConstants.FIELD_ERROR)).isEqualTo(ServiceInvocationException.getLocalizedMessage(NoConsumerException.CLIENT_FACING_MESSAGE_KEY));
});
ctx.completeNow();
}));
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class TelemetryHttpIT method testUploadMessagesUsingClientCertificateWithAlias.
/**
* Verifies that a number of messages uploaded to Hono's HTTP adapter using client certificate based authentication
* can be successfully consumed via the AMQP Messaging Network.
* <p>
* The device's tenant is being determined using the requested host name contained in the client's SNI TLS
* extension.
*
* @param ctx The test context.
* @throws InterruptedException if the test fails.
*/
@Test
public void testUploadMessagesUsingClientCertificateWithAlias(final VertxTestContext ctx) throws InterruptedException {
assumeTrue(IntegrationTestSupport.isTrustAnchorGroupsSupported(), "device registry does not support trust anchor groups");
assumeTrue(IntegrationTestSupport.isTenantAliasSupported(), "device registry does not support tenant aliases");
final VertxTestContext setup = new VertxTestContext();
final MultiMap requestHeaders = MultiMap.caseInsensitiveMultiMap().add(HttpHeaders.CONTENT_TYPE, "text/plain").add(HttpHeaders.ORIGIN, ORIGIN_URI);
helper.getCertificate(deviceCert.certificatePath()).compose(cert -> helper.registry.addTenant(helper.getRandomTenantId(), Tenants.createTenantForTrustAnchor(cert).setTrustAnchorGroup("test-group")).map(cert)).compose(cert -> helper.registry.addDeviceForTenant(tenantId, Tenants.createTenantForTrustAnchor(cert).setTrustAnchorGroup("test-group").setAlias("test-alias"), deviceId, cert)).onComplete(setup.succeedingThenComplete());
assertThat(setup.awaitCompletion(5, TimeUnit.SECONDS)).isTrue();
if (setup.failed()) {
ctx.failNow(setup.causeOfFailure());
return;
}
final RequestOptions options = new RequestOptions().setHost("test-alias." + IntegrationTestSupport.HTTP_HOST).setPort(IntegrationTestSupport.HTTPS_PORT).setURI(getEndpointUri()).setHeaders(requestHeaders);
testUploadMessages(ctx, tenantId, null, count -> httpClientWithClientCert.create(options, Buffer.buffer("hello " + count), ResponsePredicate.status(HttpURLConnection.HTTP_ACCEPTED)), 10, QoS.AT_MOST_ONCE);
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class HttpTestBase method testUploadMessagesWithTtdThatReplyWithCommand.
/**
* Verifies that the HTTP adapter delivers a command to a device and accepts the corresponding
* response from the device.
*
* @param endpointConfig The endpoints to use for sending/receiving commands.
* @param ctx The test context.
* @throws InterruptedException if the test fails.
*/
@ParameterizedTest(name = IntegrationTestSupport.PARAMETERIZED_TEST_NAME_PATTERN)
@MethodSource("commandAndControlVariants")
public void testUploadMessagesWithTtdThatReplyWithCommand(final HttpCommandEndpointConfiguration endpointConfig, final VertxTestContext ctx) throws InterruptedException {
final Tenant tenant = new Tenant();
testUploadMessagesWithTtdThatReplyWithCommand(endpointConfig, tenant, ctx);
}
Aggregations