CamelMailetContainerModule extends AbstractModule { @VisibleForTesting HierarchicalConfiguration<ImmutableNode> getMailetContextConfiguration(ConfigurationProvider configurationProvider) throws ConfigurationException { HierarchicalConfiguration<ImmutableNode> mailetContainerConfiguration = configurationProvider.getConfiguration("mailetcontainer"); try { return mailetContainerConfiguration.configurationAt("context"); } catch (ConfigurationRuntimeException e) { LOGGER.warn("Could not locate configuration for Mailet context. Assuming empty configuration for this component."); return new BaseHierarchicalConfiguration(); } }  @Singleton @Provides DefaultCamelContext provideCamelContext(); static final TransportProcessorCheck.Impl BCC_Check; }
@Test void getMailetContextConfigurationShouldReturnEmptyWhenNoContextSection() throws Exception { ConfigurationProvider configurationProvider = mock(ConfigurationProvider.class); when(configurationProvider.getConfiguration("mailetcontainer")) .thenReturn(new BaseHierarchicalConfiguration()); CamelMailetContainerModule testee = new CamelMailetContainerModule(); assertThat(testee.getMailetContextConfiguration(configurationProvider).size()) .isEqualTo(0); }
@Test void getMailetContextConfigurationShouldThrowOnInvalidXML() throws Exception { ConfigurationProvider configurationProvider = mock(ConfigurationProvider.class); when(configurationProvider.getConfiguration("mailetcontainer")) .thenThrow(new ConfigurationRuntimeException()); CamelMailetContainerModule testee = new CamelMailetContainerModule(); assertThatThrownBy(() -> testee.getMailetContextConfiguration(configurationProvider)) .isInstanceOf(ConfigurationRuntimeException.class); }
@Test void getMailetContextConfigurationShouldReturnConfigurationWhenSome() throws Exception { XMLConfiguration configuration = FileConfigurationProvider.getConfig(new ByteArrayInputStream(( "<mailetcontainer>" + " <context>" + " <key>value</key>" + " </context>" + "</mailetcontainer>") .getBytes(StandardCharsets.UTF_8))); ConfigurationProvider configurationProvider = mock(ConfigurationProvider.class); when(configurationProvider.getConfiguration("mailetcontainer")).thenReturn(configuration); CamelMailetContainerModule testee = new CamelMailetContainerModule(); HierarchicalConfiguration<ImmutableNode> mailetContextConfiguration = testee.getMailetContextConfiguration(configurationProvider); assertThat(mailetContextConfiguration.getString("key")) .isEqualTo("value"); }