private AbstractProtocolAdapterBase<ProtocolAdapterProperties> newProtocolAdapter( final ProtocolAdapterProperties props, final String typeName, final Handler<Void> startupHandler) { return newProtocolAdapter(props, typeName, startupHandler, null, null); }
private AbstractProtocolAdapterBase<ProtocolAdapterProperties> newProtocolAdapter(final ProtocolAdapterProperties props) { return newProtocolAdapter(props, ADAPTER_NAME); }
/** * Verifies that any general message with a payload is approved. * * @param ctx The vert.x test context. */ @Test public void testNonEmptyGeneralMessage(final TestContext ctx) { // GIVEN an adapter adapter = newProtocolAdapter(properties, null); // WHEN an non empty event with a non empty payload is approved, no error message must be returned final Buffer payload = Buffer.buffer("test"); final String arbitraryContentType = "bum/lux"; // arbitrary content-type needs non empty payload ctx.assertTrue(adapter.isPayloadOfIndicatedType(payload, arbitraryContentType)); }
/** * Verifies that any non empty message without a content type is approved. * * @param ctx The vert.x test context. */ @Test public void testNonEmptyMessageWithoutContentType(final TestContext ctx) { // GIVEN an adapter adapter = newProtocolAdapter(properties, null); // WHEN an event without content type and a non empty payload is approved, no error message must be returned final Buffer payload = Buffer.buffer("test"); // arbitrary content-type needs non empty payload ctx.assertTrue(adapter.isPayloadOfIndicatedType(payload, null)); }
/** * Verifies that any empty notification with a payload is an error. * * @param ctx The vert.x test context. */ @Test public void testEmptyNotificationWithPayload(final TestContext ctx) { // GIVEN an adapter adapter = newProtocolAdapter(properties, null); // WHEN an empty event with a non empty payload is approved, an error message must be returned final Buffer payload = Buffer.buffer("test"); final String contentType = EventConstants.CONTENT_TYPE_EMPTY_NOTIFICATION; ctx.assertFalse(adapter.isPayloadOfIndicatedType(payload, contentType)); }
adapter = newProtocolAdapter(properties); adapter.setTenantServiceClient(tenantService); adapter.setRegistrationServiceClient(registrationService);
/** * Verifies that the helper approves empty notification without payload. * * @param ctx The vert.x test context. */ @Test public void testEmptyNotificationWithoutPayload(final TestContext ctx) { // GIVEN an adapter adapter = newProtocolAdapter(properties, null); // WHEN an empty event with an empty payload is approved, no error message must be returned final Buffer payload = null; final String contentType = EventConstants.CONTENT_TYPE_EMPTY_NOTIFICATION; ctx.assertTrue(adapter.isPayloadOfIndicatedType(payload, contentType)); }
/** * Verifies that any empty general message is an error. * * @param ctx The vert.x test context. */ @Test public void testEmptyGeneralMessage(final TestContext ctx) { // GIVEN an adapter adapter = newProtocolAdapter(properties, null); // WHEN an event with content type and an empty payload is approved, an error message must be returned final Buffer payload = null; final String arbitraryContentType = "bum/lux"; // arbitrary content-type needs non empty payload ctx.assertFalse(adapter.isPayloadOfIndicatedType(payload, arbitraryContentType)); } }
/** * Verifies that an adapter that does not define a type name * cannot be started. * * @param ctx The vert.x test context. */ @Test public void testStartInternalFailsIfNoTypeNameIsDefined(final TestContext ctx) { // GIVEN an adapter that does not define a type name adapter = newProtocolAdapter(properties, null); adapter.setRegistrationServiceClient(mock(HonoClient.class)); // WHEN starting the adapter // THEN startup fails adapter.startInternal().setHandler(ctx.asyncAssertFailure()); }
private void givenAnAdapterConfiguredWithServiceClients( final Handler<Void> startupHandler, final Handler<Void> commandConnectionEstablishedHandler, final Handler<Void> commandConnectionLostHandler) { adapter = newProtocolAdapter(properties, "test", startupHandler, commandConnectionEstablishedHandler, commandConnectionLostHandler); adapter.setCredentialsServiceClient(credentialsService); adapter.setHonoMessagingClient(messagingService); adapter.setRegistrationServiceClient(registrationService); adapter.setTenantServiceClient(tenantService); adapter.setCommandConnection(commandConnection); }
/** * Verifies that the adapter fails a request to retrieve a token for a gateway that does not * belong to the same tenant as the device it wants to act on behalf of. * * @param ctx The vert.x test context. */ @Test public void testGetRegistrationAssertionFailsWith403ForNonMatchingTenant(final TestContext ctx) { // GIVEN an adapter adapter = newProtocolAdapter(properties, null); // WHEN a gateway tries to get an assertion for a device from another tenant adapter.getRegistrationAssertion( "tenant A", "device", new Device("tenant B", "gateway"), mock(SpanContext.class)).setHandler(ctx.asyncAssertFailure(t -> { // THEN the request fails with a 403 Forbidden error ctx.assertEquals(HttpURLConnection.HTTP_FORBIDDEN, ((ClientErrorException) t).getErrorCode()); })); }