Search in sources :

Example 1 with NoopSpan

use of io.opentracing.noop.NoopSpan in project hono by eclipse.

the class AbstractCredentialsServiceTest method testGetCredentialsPreservesOriginalErrorStatus.

/**
 * Verifies that when the <em>processGet</em> method returns an error result, its status
 * is adopted for the <em>get</em> method result.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testGetCredentialsPreservesOriginalErrorStatus(final VertxTestContext ctx) {
    final AbstractCredentialsService credentialsService = new AbstractCredentialsService() {

        @Override
        protected Future<CredentialsResult<JsonObject>> processGet(final TenantKey tenant, final CredentialKey key, final JsonObject clientContext, final Span span) {
            return Future.succeededFuture(CredentialsResult.from(HttpURLConnection.HTTP_BAD_GATEWAY));
        }
    };
    final String tenantId = "tenant";
    final String type = CredentialsConstants.SECRETS_TYPE_HASHED_PASSWORD;
    final String authId = UUID.randomUUID().toString();
    final NoopSpan span = NoopSpan.INSTANCE;
    credentialsService.get(tenantId, type, authId, span).onComplete(ctx.succeeding(getCredentialsResult -> {
        ctx.verify(() -> {
            assertThat(getCredentialsResult.getCacheDirective()).isNotNull();
            assertThat(getCredentialsResult.getCacheDirective()).isEqualTo(CacheDirective.noCacheDirective());
            assertThat(getCredentialsResult.getStatus()).isEqualTo(HttpURLConnection.HTTP_BAD_GATEWAY);
        });
        // another test with auto-provisioning enabled
        credentialsService.setDeviceAndGatewayAutoProvisioner(getDeviceAndGatewayAutoProvisionerMock());
        credentialsService.get(tenantId, type, authId, span).onComplete(ctx.succeeding(getCredentialsResult2 -> {
            ctx.verify(() -> {
                assertThat(getCredentialsResult2.getCacheDirective()).isNotNull();
                assertThat(getCredentialsResult2.getCacheDirective()).isEqualTo(CacheDirective.noCacheDirective());
                assertThat(getCredentialsResult2.getStatus()).isEqualTo(HttpURLConnection.HTTP_BAD_GATEWAY);
            });
            ctx.completeNow();
        }));
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) CacheDirective(org.eclipse.hono.util.CacheDirective) VertxTestContext(io.vertx.junit5.VertxTestContext) CredentialsManagementService(org.eclipse.hono.service.management.credentials.CredentialsManagementService) CredentialsResult(org.eclipse.hono.util.CredentialsResult) MessagingClientProvider(org.eclipse.hono.client.util.MessagingClientProvider) Vertx(io.vertx.core.Vertx) UUID(java.util.UUID) Truth.assertThat(com.google.common.truth.Truth.assertThat) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) CredentialsConstants(org.eclipse.hono.util.CredentialsConstants) Timeout(io.vertx.junit5.Timeout) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) DeviceManagementService(org.eclipse.hono.service.management.device.DeviceManagementService) DeviceAndGatewayAutoProvisioner(org.eclipse.hono.service.management.device.DeviceAndGatewayAutoProvisioner) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) TenantKey(org.eclipse.hono.deviceregistry.service.tenant.TenantKey) Span(io.opentracing.Span) JsonObject(io.vertx.core.json.JsonObject) NoopSpan(io.opentracing.noop.NoopSpan) Mockito.mock(org.mockito.Mockito.mock) NoopSpan(io.opentracing.noop.NoopSpan) TenantKey(org.eclipse.hono.deviceregistry.service.tenant.TenantKey) JsonObject(io.vertx.core.json.JsonObject) CredentialsResult(org.eclipse.hono.util.CredentialsResult) Span(io.opentracing.Span) NoopSpan(io.opentracing.noop.NoopSpan) Test(org.junit.jupiter.api.Test)

Aggregations

Truth.assertThat (com.google.common.truth.Truth.assertThat)1 Span (io.opentracing.Span)1 NoopSpan (io.opentracing.noop.NoopSpan)1 Future (io.vertx.core.Future)1 Vertx (io.vertx.core.Vertx)1 JsonObject (io.vertx.core.json.JsonObject)1 Timeout (io.vertx.junit5.Timeout)1 VertxExtension (io.vertx.junit5.VertxExtension)1 VertxTestContext (io.vertx.junit5.VertxTestContext)1 HttpURLConnection (java.net.HttpURLConnection)1 UUID (java.util.UUID)1 TimeUnit (java.util.concurrent.TimeUnit)1 MessagingClientProvider (org.eclipse.hono.client.util.MessagingClientProvider)1 TenantKey (org.eclipse.hono.deviceregistry.service.tenant.TenantKey)1 CredentialsManagementService (org.eclipse.hono.service.management.credentials.CredentialsManagementService)1 DeviceAndGatewayAutoProvisioner (org.eclipse.hono.service.management.device.DeviceAndGatewayAutoProvisioner)1 DeviceManagementService (org.eclipse.hono.service.management.device.DeviceManagementService)1 CacheDirective (org.eclipse.hono.util.CacheDirective)1 CredentialsConstants (org.eclipse.hono.util.CredentialsConstants)1 CredentialsResult (org.eclipse.hono.util.CredentialsResult)1