PlaceholderFilter { public static <T> String apply(final String template, final T placeholderSource, final Placeholder<T> placeholder) { return apply(template, PlaceholderFactory.newExpressionResolver(placeholder, placeholderSource)); } private  PlaceholderFilter(); static AuthorizationContext applyHeadersPlaceholderToAuthContext(
            final AuthorizationContext authorizationContext,
            final Map<String, String> headers); static String apply(final String template, final T placeholderSource, final Placeholder<T> placeholder); static String apply(final String template, final ExpressionResolver expressionResolver); static Optional<String> applyOrElseDelete(final String template, final ExpressionResolver resolver); static String applyOrElseRetain(final String template, final ExpressionResolver resolver); static void validate(final String template, final Placeholder<?>... placeholders); static String validateAndReplace(final String template, final String stringUsedInPlaceholderReplacement,
            final Placeholder<?>... placeholders);  }
@Test public void testHeadersPlaceholder() { assertThatExceptionOfType(NullPointerException.class).isThrownBy( () -> headersPlaceholder.resolve(HEADERS, null)); assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy( () -> headersPlaceholder.resolve(HEADERS, "")); assertThatExceptionOfType(UnresolvedPlaceholderException.class).isThrownBy( () -> PlaceholderFilter.apply("{{ header:unknown }}", HEADERS, headersPlaceholder)); assertThatExceptionOfType(UnresolvedPlaceholderException.class).isThrownBy( () -> PlaceholderFilter.apply("{{ {{ header:device-id }} }}", HEADERS, headersPlaceholder)); assertThat(PlaceholderFilter.apply(THING_ID.toString(), HEADERS, headersPlaceholder)) .isEqualTo(THING_ID.toString()); assertThat( PlaceholderFilter.apply("eclipse:ditto:{{ header:device-id }}", HEADERS, headersPlaceholder)).isEqualTo( "eclipse:ditto:device-12345"); }
@Test public void testThingPlaceholder() { assertThatExceptionOfType(NullPointerException.class).isThrownBy( () -> thingPlaceholder.resolve(THING_ID, null)); assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy( () -> thingPlaceholder.resolve(THING_ID, "")); assertThatExceptionOfType(UnresolvedPlaceholderException.class).isThrownBy( () -> PlaceholderFilter.apply("{{ header:unknown }}", THING_ID, thingPlaceholder)); assertThatExceptionOfType(UnresolvedPlaceholderException.class).isThrownBy( () -> PlaceholderFilter.apply("{{ {{ thing:name }} }}", THING_ID, thingPlaceholder)); assertThat(PlaceholderFilter.apply(THING_ID.toString(), THING_ID, thingPlaceholder)) .isEqualTo(THING_ID.toString()); assertThat(PlaceholderFilter.apply("prefix:{{ thing:namespace }}:{{ thing:name }}:suffix", THING_ID, thingPlaceholder)).isEqualTo("prefix:eclipse:ditto:suffix"); assertThat(PlaceholderFilter.apply("testTargetAmqpCon4_{{thing:namespace}}:{{thing:name}}", THING_ID, thingPlaceholder)) .isEqualTo("testTargetAmqpCon4_eclipse:ditto"); assertThat(PlaceholderFilter.apply("testTargetAmqpCon4_{{thing:id}}", THING_ID, thingPlaceholder)).isEqualTo( "testTargetAmqpCon4_eclipse:ditto"); }
@Test public void testTopicPlaceholder() { assertThatExceptionOfType(NullPointerException.class).isThrownBy( () -> topicPlaceholder.resolve(KNOWN_TOPIC_PATH, null)); assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy( () -> topicPlaceholder.resolve(KNOWN_TOPIC_PATH, "")); assertThatExceptionOfType(UnresolvedPlaceholderException.class).isThrownBy( () -> PlaceholderFilter.apply("{{ topic:unknown }}", KNOWN_TOPIC_PATH, topicPlaceholder)); assertThatExceptionOfType(UnresolvedPlaceholderException.class).isThrownBy( () -> PlaceholderFilter.apply("{{ {{ topic:name }} }}", KNOWN_TOPIC_PATH, topicPlaceholder)); assertThat(PlaceholderFilter.apply("eclipse:ditto", KNOWN_TOPIC_PATH, topicPlaceholder)).isEqualTo( "eclipse:ditto"); assertThat(PlaceholderFilter.apply("prefix:{{ topic:channel }}:{{ topic:group }}:suffix", KNOWN_TOPIC_PATH, topicPlaceholder)).isEqualTo("prefix:twin:things:suffix"); assertThat(PlaceholderFilter.apply("{{topic:subject}}", KNOWN_TOPIC_PATH_SUBJECT1, topicPlaceholder)).isEqualTo(KNOWN_SUBJECT); assertThat(PlaceholderFilter.apply("{{ topic:action-subject}}", KNOWN_TOPIC_PATH_SUBJECT2, topicPlaceholder)).isEqualTo(KNOWN_SUBJECT2); }
@Test public void testThingPlaceholderDebug() { assertThat(PlaceholderFilter.apply("testTargetAmqpCon4_{{thing:namespace}}:{{thing:name}}", THING_ID, thingPlaceholder)) .isEqualTo("testTargetAmqpCon4_eclipse:ditto"); }