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();
}));
}));
}
Aggregations