use of org.eclipse.hono.adapter.lora.providers.LoraProvider in project hono by eclipse.
the class LoraProtocolAdapterTest method getLoraProviderMock.
private LoraProvider getLoraProviderMock(final LoraMessage message) {
final LoraProvider provider = mock(LoraProvider.class);
when(provider.getProviderName()).thenReturn(TEST_PROVIDER);
when(provider.pathPrefixes()).thenReturn(Set.of("/bumlux"));
when(provider.getMessage(any(RoutingContext.class))).thenReturn(message);
return provider;
}
use of org.eclipse.hono.adapter.lora.providers.LoraProvider in project hono by eclipse.
the class LoraProtocolAdapterTest method handleProviderRouteDiscardsOtherMessages.
/**
* Verifies that the provider route discards other messages.
*/
@Test
public void handleProviderRouteDiscardsOtherMessages() {
givenATelemetrySenderForAnyTenant();
final LoraMessage message = mock(LoraMessage.class);
when(message.getType()).thenReturn(LoraMessageType.UNKNOWN);
final LoraProvider providerMock = getLoraProviderMock(message);
final HttpContext httpContext = newHttpContext();
adapter.handleProviderRoute(httpContext, providerMock);
verify(httpContext.getRoutingContext()).put(LoraConstants.APP_PROPERTY_ORIG_LORA_PROVIDER, TEST_PROVIDER);
assertNoTelemetryMessageHasBeenSentDownstream();
verify(httpContext.response()).setStatusCode(HttpResponseStatus.ACCEPTED.code());
verify(processMessageSpan).finish();
}
use of org.eclipse.hono.adapter.lora.providers.LoraProvider in project hono by eclipse.
the class LoraProtocolAdapter method addRoutes.
@Override
protected void addRoutes(final Router router) {
// the LoraWAN adapter always requires network providers to authenticate
setupAuthorization(router);
for (final LoraProvider provider : loraProviders) {
for (final String pathPrefix : provider.pathPrefixes()) {
router.route(HttpMethod.OPTIONS, pathPrefix).handler(this::handleOptionsRoute);
router.route(provider.acceptedHttpMethod(), pathPrefix).consumes(provider.acceptedContentType()).handler(ctx -> this.handleProviderRoute(HttpContext.from(ctx), provider));
router.route(provider.acceptedHttpMethod(), pathPrefix).handler(ctx -> {
LOG.debug("request does not contain content-type header, will return 400 ...");
handle400(ctx, ERROR_MSG_MISSING_OR_UNSUPPORTED_CONTENT_TYPE);
});
}
}
}
Aggregations