private static JsonObject newRegistrationAssertionResult(final String token) { return newRegistrationAssertionResult(token, null); }
/** * Verifies that the registration assertion is set on a downstream message. */ @Test public void testAddPropertiesAddsRegistrationAssertion() { final Message message = ProtonHelper.message(); adapter.addProperties(message, newRegistrationAssertionResult("token")); assertThat(MessageHelper.getRegistrationAssertion(message), is("token")); }
/** * Verifies that the adapter successfully retrieves a registration assertion * for an existing device. * * @param ctx The vert.x test context. */ @Test public void testGetRegistrationAssertionSucceedsForExistingDevice(final TestContext ctx) { // GIVEN an adapter connected to a registration service final JsonObject assertionResult = newRegistrationAssertionResult("token"); when(registrationClient.assertRegistration(eq("device"), any())).thenReturn(Future.succeededFuture(assertionResult)); when(registrationClient.assertRegistration(eq("device"), any(), any())).thenReturn(Future.succeededFuture(assertionResult)); // WHEN an assertion for the device is retrieved adapter.getRegistrationAssertion("tenant", "device", null).setHandler(ctx.asyncAssertSuccess(result -> { // THEN the result contains the registration assertion ctx.assertEquals(assertionResult, result); })); adapter.getRegistrationAssertion("tenant", "device", null, mock(SpanContext.class)).setHandler(ctx.asyncAssertSuccess(result -> { // THEN the result contains the registration assertion ctx.assertEquals(assertionResult, result); })); }
/** * Verifies that the registered default content type is set on a downstream message. */ @Test public void testAddPropertiesAddsDefaultContentType() { final Message message = ProtonHelper.message(); adapter.addProperties(message, newRegistrationAssertionResult("token", "application/hono")); assertThat(MessageHelper.getRegistrationAssertion(message), is("token")); assertThat(message.getContentType(), is("application/hono")); }
/** * Verifies that the fall back content type is set on a downstream message * if no default has been configured for the device. */ @Test public void testAddPropertiesAddsFallbackContentType() { final Message message = ProtonHelper.message(); adapter.addProperties(message, newRegistrationAssertionResult("token")); assertThat(MessageHelper.getRegistrationAssertion(message), is("token")); assertThat(message.getContentType(), is(AbstractProtocolAdapterBase.CONTENT_TYPE_OCTET_STREAM)); }
/** * Verifies that the registered default content type is not set on a downstream message * that already contains a content type. */ @Test public void testAddPropertiesDoesNotAddDefaultContentType() { final Message message = ProtonHelper.message(); message.setContentType("application/existing"); adapter.addProperties(message, newRegistrationAssertionResult("token", "application/hono")); assertThat(MessageHelper.getRegistrationAssertion(message), is("token")); assertThat(message.getContentType(), is("application/existing")); }
/** * Verifies that the adapter's name is set on a downstream message. */ @Test public void testAddPropertiesAddsAdapterName() { final Message message = ProtonHelper.message(); adapter.addProperties(message, newRegistrationAssertionResult("token")); assertThat( MessageHelper.getApplicationProperty( message.getApplicationProperties(), MessageHelper.APP_PROPERTY_ORIG_ADAPTER, String.class), is(ADAPTER_NAME)); }
/** * Verifies that the registration assertion is not set on a downstream message * if the downstream peer does not require it. */ @Test public void testAddPropertiesOmitsRegistrationAssertion() { final Message message = ProtonHelper.message(); adapter.addProperties(message, newRegistrationAssertionResult("token"), false); assertNull(MessageHelper.getRegistrationAssertion(message)); }