RabbitMQValidator extends AbstractProtocolValidator { @Override protected void validateSource(final Source source, final DittoHeaders dittoHeaders, final Supplier<String> sourceDescription) { source.getEnforcement().ifPresent(enforcement -> { validateTemplate(enforcement.getInput(), dittoHeaders, PlaceholderFactory.newHeadersPlaceholder()); enforcement.getFilters().forEach(filterTemplate -> validateTemplate(filterTemplate, dittoHeaders, PlaceholderFactory.newThingPlaceholder(), PlaceholderFactory.newPolicyPlaceholder(), PlaceholderFactory.newEntityPlaceholder())); }); source.getHeaderMapping().ifPresent(mapping -> validateHeaderMapping(mapping, dittoHeaders)); }  static RabbitMQValidator newInstance(); @Override ConnectionType type(); @Override void validate(final Connection connection, final DittoHeaders dittoHeaders, final ActorSystem actorSystem);  }
@Test public void testValidHeaderMapping() { final Source source = newSourceBuilder() .headerMapping(TestConstants.HEADER_MAPPING) .build(); UNDER_TEST.validateSource(source, DittoHeaders.empty(), () -> "testSource"); }
@Test public void testInvalidHeaderMappingThrowsException() { final Map<String, String> mapping = new HashMap<>(TestConstants.HEADER_MAPPING.getMapping()); mapping.put("thingId", "{{ thing:invalid }}"); final Source source = newSourceBuilder() .headerMapping(ConnectivityModelFactory.newHeaderMapping(mapping)) .build(); Assertions.assertThatExceptionOfType(ConnectionConfigurationInvalidException.class) .isThrownBy(() -> UNDER_TEST.validateSource(source, DittoHeaders.empty(), () -> "testSource")) .withCauseInstanceOf(UnresolvedPlaceholderException.class); }
@Test public void testInvalidInputThrowsException() { final Source source = newSourceBuilder() .enforcement(ConnectivityModelFactory.newEnforcement("{{ thing:id }}", "{{ thing:namespace }}")) .build(); Assertions.assertThatExceptionOfType(ConnectionConfigurationInvalidException.class) .isThrownBy(() -> UNDER_TEST.validateSource(source, DittoHeaders.empty(), () -> "testSource")) .withCauseInstanceOf(UnresolvedPlaceholderException.class); }
@Test public void testInvalidMatcherThrowsException() { final Source source = newSourceBuilder() .enforcement(ConnectivityModelFactory.newEnforcement( "{{ header:device_id }}", "{{ header:ditto }}")) .build(); Assertions.assertThatExceptionOfType(ConnectionConfigurationInvalidException.class) .isThrownBy(() -> UNDER_TEST.validateSource(source, DittoHeaders.empty(), () -> "testSource")) .withCauseInstanceOf(UnresolvedPlaceholderException.class); }