use of org.eclipse.hono.service.http.HttpContext in project hono by eclipse.
the class AbstractVertxBasedHttpProtocolAdapterTest method testUploadCommandResponseFailsForDisabledTenant.
/**
* Verifies that the adapter fails the upload of a command response with a 403
* if the adapter is disabled for the device's tenant.
*/
@Test
public void testUploadCommandResponseFailsForDisabledTenant() {
// GIVEN an adapter that is not enabled for a device's tenant
final TenantObject to = TenantObject.from("tenant", true);
to.addAdapter(new Adapter(Constants.PROTOCOL_ADAPTER_TYPE_HTTP).setEnabled(Boolean.FALSE));
when(tenantClient.get(eq("tenant"), (SpanContext) any())).thenReturn(Future.succeededFuture(to));
givenAnAdapter(properties);
// WHEN a device publishes a command response
final Buffer payload = Buffer.buffer("some payload");
final HttpContext ctx = newHttpContext(payload, "application/text", mock(HttpServerRequest.class), mock(HttpServerResponse.class));
adapter.uploadCommandResponseMessage(ctx, "tenant", "device", CMD_REQ_ID, 200);
// THEN the device gets a 403
assertContextFailedWithClientError(ctx, HttpURLConnection.HTTP_FORBIDDEN);
// and the response has been reported as undeliverable
verify(metrics).reportCommand(eq(Direction.RESPONSE), eq("tenant"), eq(to), eq(ProcessingOutcome.UNPROCESSABLE), eq(payload.length()), any());
}
Aggregations