Search in sources :

Example 1 with HttpAdapterMetrics

use of org.eclipse.hono.adapter.http.HttpAdapterMetrics in project hono by eclipse.

the class LoraProtocolAdapterTest method setUp.

/**
 * Sets up the fixture.
 */
@BeforeEach
public void setUp() {
    vertx = mock(Vertx.class);
    final Context context = VertxMockSupport.mockContext(vertx);
    webClient = mock(WebClient.class);
    this.properties = givenDefaultConfigurationProperties();
    createClients();
    prepareClients();
    processMessageSpan = mock(Span.class);
    when(processMessageSpan.context()).thenReturn(mock(SpanContext.class));
    final Span otherSpan = mock(Span.class);
    when(otherSpan.context()).thenReturn(mock(SpanContext.class));
    final SpanBuilder processMessageSpanBuilder = mock(SpanBuilder.class, withSettings().defaultAnswer(RETURNS_SELF));
    when(processMessageSpanBuilder.start()).thenReturn(processMessageSpan);
    final SpanBuilder otherSpanBuilder = mock(SpanBuilder.class, withSettings().defaultAnswer(RETURNS_SELF));
    when(otherSpanBuilder.start()).thenReturn(otherSpan);
    final Tracer tracer = mock(Tracer.class);
    when(tracer.buildSpan(eq(LoraProtocolAdapter.SPAN_NAME_PROCESS_MESSAGE))).thenReturn(processMessageSpanBuilder);
    when(tracer.buildSpan(argThat(opName -> !opName.equals(LoraProtocolAdapter.SPAN_NAME_PROCESS_MESSAGE)))).thenReturn(otherSpanBuilder);
    final HttpAdapterMetrics metrics = mock(HttpAdapterMetrics.class);
    when(metrics.startTimer()).thenReturn(mock(Sample.class));
    adapter = new LoraProtocolAdapter(webClient);
    adapter.setConfig(properties);
    adapter.setTracer(tracer);
    adapter.init(vertx, context);
    adapter.setMetrics(metrics);
    setServiceClients(adapter);
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) Context(io.vertx.core.Context) CommandContext(org.eclipse.hono.client.command.CommandContext) HttpContext(org.eclipse.hono.service.http.HttpContext) SpanContext(io.opentracing.SpanContext) HttpURLConnection(java.net.HttpURLConnection) BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) LoraProviderMalformedPayloadException(org.eclipse.hono.adapter.lora.providers.LoraProviderMalformedPayloadException) RoutingContext(io.vertx.ext.web.RoutingContext) Context(io.vertx.core.Context) RETURNS_SELF(org.mockito.Mockito.RETURNS_SELF) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) CommandContext(org.eclipse.hono.client.command.CommandContext) Set(java.util.Set) RegistrationAssertion(org.eclipse.hono.util.RegistrationAssertion) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Future(io.vertx.core.Future) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) Buffer(io.vertx.core.buffer.Buffer) CommandConsumer(org.eclipse.hono.client.command.CommandConsumer) VertxMockSupport(org.eclipse.hono.test.VertxMockSupport) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Span(io.opentracing.Span) Mockito.withSettings(org.mockito.Mockito.withSettings) CommandEndpoint(org.eclipse.hono.util.CommandEndpoint) HttpAdapterMetrics(org.eclipse.hono.adapter.http.HttpAdapterMetrics) QoS(org.eclipse.hono.util.QoS) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) HttpContext(org.eclipse.hono.service.http.HttpContext) HttpServerRequest(io.vertx.core.http.HttpServerRequest) HttpResponse(io.vertx.ext.web.client.HttpResponse) LoraProvider(org.eclipse.hono.adapter.lora.providers.LoraProvider) WebClient(io.vertx.ext.web.client.WebClient) Command(org.eclipse.hono.client.command.Command) HashMap(java.util.HashMap) ClientErrorException(org.eclipse.hono.client.ClientErrorException) SpanBuilder(io.opentracing.Tracer.SpanBuilder) DeviceUser(org.eclipse.hono.service.auth.DeviceUser) TracingHandler(org.eclipse.hono.service.http.TracingHandler) ProtocolAdapterTestSupport(org.eclipse.hono.adapter.test.ProtocolAdapterTestSupport) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArgumentMatchers.isNull(org.mockito.ArgumentMatchers.isNull) Tracer(io.opentracing.Tracer) Vertx(io.vertx.core.Vertx) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) Sample(io.micrometer.core.instrument.Timer.Sample) Mockito.verify(org.mockito.Mockito.verify) SpanContext(io.opentracing.SpanContext) HttpRequest(io.vertx.ext.web.client.HttpRequest) HttpProtocolAdapterProperties(org.eclipse.hono.adapter.http.HttpProtocolAdapterProperties) Handler(io.vertx.core.Handler) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SpanBuilder(io.opentracing.Tracer.SpanBuilder) SpanContext(io.opentracing.SpanContext) Tracer(io.opentracing.Tracer) Sample(io.micrometer.core.instrument.Timer.Sample) Vertx(io.vertx.core.Vertx) WebClient(io.vertx.ext.web.client.WebClient) Span(io.opentracing.Span) HttpAdapterMetrics(org.eclipse.hono.adapter.http.HttpAdapterMetrics) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with HttpAdapterMetrics

use of org.eclipse.hono.adapter.http.HttpAdapterMetrics in project hono by eclipse.

the class VertxBasedHttpProtocolAdapterTest method deployAdapter.

/**
 * Creates and deploys the adapter instance under test.
 * <p>
 * The service clients' behavior is newly configured per test case
 * in {@link VertxBasedHttpProtocolAdapterTest#configureServiceClients(TestInfo)}.
 *
 * @param ctx The vert.x test context.
 */
@SuppressWarnings("unchecked")
@BeforeAll
public void deployAdapter(final VertxTestContext ctx) {
    vertx = Vertx.vertx();
    usernamePasswordAuthProvider = mock(DeviceCredentialsAuthProvider.class);
    final HttpAdapterMetrics metrics = mock(HttpAdapterMetrics.class);
    when(metrics.startTimer()).thenReturn(Timer.start());
    this.properties = givenDefaultConfigurationProperties();
    createClients();
    adapter = new VertxBasedHttpProtocolAdapter();
    adapter.setConfig(properties);
    adapter.setUsernamePasswordAuthProvider(usernamePasswordAuthProvider);
    adapter.setMetrics(metrics);
    setServiceClients(adapter);
    vertx.deployVerticle(adapter, ctx.succeeding(deploymentId -> {
        final WebClientOptions options = new WebClientOptions().setDefaultHost(HOST).setDefaultPort(adapter.getInsecurePort());
        httpClient = WebClient.create(vertx, options);
        ctx.completeNow();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) WebClientOptions(io.vertx.ext.web.client.WebClientOptions) BeforeEach(org.junit.jupiter.api.BeforeEach) ResponsePredicate(io.vertx.ext.web.client.predicate.ResponsePredicate) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) LoggerFactory(org.slf4j.LoggerFactory) MultiMap(io.vertx.core.MultiMap) Timeout(io.vertx.junit5.Timeout) AfterAll(org.junit.jupiter.api.AfterAll) MessagingType(org.eclipse.hono.util.MessagingType) TestInstance(org.junit.jupiter.api.TestInstance) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Mockito.doAnswer(org.mockito.Mockito.doAnswer) JsonObject(io.vertx.core.json.JsonObject) JsonHelper(org.eclipse.hono.util.JsonHelper) CommandContext(org.eclipse.hono.client.command.CommandContext) HttpHeaders(io.vertx.core.http.HttpHeaders) Lifecycle(org.junit.jupiter.api.TestInstance.Lifecycle) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) TestInfo(org.junit.jupiter.api.TestInfo) Test(org.junit.jupiter.api.Test) User(io.vertx.ext.auth.User) CommandConsumer(org.eclipse.hono.client.command.CommandConsumer) VertxMockSupport(org.eclipse.hono.test.VertxMockSupport) UsernamePasswordCredentials(org.eclipse.hono.adapter.auth.device.UsernamePasswordCredentials) HttpAdapterMetrics(org.eclipse.hono.adapter.http.HttpAdapterMetrics) QoS(org.eclipse.hono.util.QoS) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) VertxTestContext(io.vertx.junit5.VertxTestContext) HttpResponse(io.vertx.ext.web.client.HttpResponse) ProtonDelivery(io.vertx.proton.ProtonDelivery) WebClient(io.vertx.ext.web.client.WebClient) ResponsePredicateResult(io.vertx.ext.web.client.predicate.ResponsePredicateResult) ClientErrorException(org.eclipse.hono.client.ClientErrorException) Constants(org.eclipse.hono.util.Constants) DeviceUser(org.eclipse.hono.service.auth.DeviceUser) ProtocolAdapterTestSupport(org.eclipse.hono.adapter.test.ProtocolAdapterTestSupport) Timer(io.micrometer.core.instrument.Timer) HttpUtils(org.eclipse.hono.service.http.HttpUtils) AsyncResult(io.vertx.core.AsyncResult) CommandConstants(org.eclipse.hono.util.CommandConstants) Logger(org.slf4j.Logger) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) ServerErrorException(org.eclipse.hono.client.ServerErrorException) Mockito.when(org.mockito.Mockito.when) CredentialsConstants(org.eclipse.hono.util.CredentialsConstants) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) DeviceCredentialsAuthProvider(org.eclipse.hono.adapter.auth.device.DeviceCredentialsAuthProvider) HttpProtocolAdapterProperties(org.eclipse.hono.adapter.http.HttpProtocolAdapterProperties) Handler(io.vertx.core.Handler) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DeviceCredentialsAuthProvider(org.eclipse.hono.adapter.auth.device.DeviceCredentialsAuthProvider) WebClientOptions(io.vertx.ext.web.client.WebClientOptions) HttpAdapterMetrics(org.eclipse.hono.adapter.http.HttpAdapterMetrics) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

Future (io.vertx.core.Future)2 Handler (io.vertx.core.Handler)2 Vertx (io.vertx.core.Vertx)2 JsonObject (io.vertx.core.json.JsonObject)2 HttpResponse (io.vertx.ext.web.client.HttpResponse)2 WebClient (io.vertx.ext.web.client.WebClient)2 HttpURLConnection (java.net.HttpURLConnection)2 HttpAdapterMetrics (org.eclipse.hono.adapter.http.HttpAdapterMetrics)2 HttpProtocolAdapterProperties (org.eclipse.hono.adapter.http.HttpProtocolAdapterProperties)2 ProtocolAdapterTestSupport (org.eclipse.hono.adapter.test.ProtocolAdapterTestSupport)2 ClientErrorException (org.eclipse.hono.client.ClientErrorException)2 CommandConsumer (org.eclipse.hono.client.command.CommandConsumer)2 CommandContext (org.eclipse.hono.client.command.CommandContext)2 DeviceUser (org.eclipse.hono.service.auth.DeviceUser)2 VertxMockSupport (org.eclipse.hono.test.VertxMockSupport)2 QoS (org.eclipse.hono.util.QoS)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Test (org.junit.jupiter.api.Test)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2