WebAdminConfiguration { public static Builder builder() { return new Builder(); } @VisibleForTesting  WebAdminConfiguration(boolean enabled, Optional<PortSupplier> port, Optional<TlsConfiguration> tlsConfiguration,
                          boolean enableCORS, String urlCORSOrigin, String host, List<String> additionalRoutes); static Builder builder(); List<String> getAdditionalRoutes(); boolean isEnabled(); String getUrlCORSOrigin(); PortSupplier getPort(); TlsConfiguration getTlsConfiguration(); boolean isEnableCORS(); boolean isTlsEnabled(); String getHost(); @Override final boolean equals(Object o); @Override final int hashCode(); static final boolean DEFAULT_CORS_DISABLED; static final String CORS_ALL_ORIGINS; static final String DEFAULT_HOST; static final WebAdminConfiguration DISABLED_CONFIGURATION; static final WebAdminConfiguration TEST_CONFIGURATION; }
@Test public void buildShouldThrowWhenNoPortButEnabled() { expectedException.expect(IllegalStateException.class); WebAdminConfiguration.builder().enabled().build(); }
@Test public void buildShouldWorkWithoutPortWhenDisabled() { assertThat(WebAdminConfiguration.builder() .disabled() .build()) .extracting(WebAdminConfiguration::isEnabled) .isEqualTo(false); }
@Test public void buildShouldFailOnNoEnable() { expectedException.expect(IllegalStateException.class); WebAdminConfiguration.builder().port(PORT).build(); }
@Test public void builderShouldBuildWithRightPort() { assertThat( WebAdminConfiguration.builder() .enabled() .port(PORT) .build()) .extracting(WebAdminConfiguration::getPort) .isEqualTo(PORT); }
@Test public void builderShouldBuildWithEnable() { assertThat( WebAdminConfiguration.builder() .enabled() .port(PORT) .build()) .extracting(WebAdminConfiguration::isEnabled) .isEqualTo(true); }
@Test public void builderShouldAcceptHttps() { TlsConfiguration tlsConfiguration = TlsConfiguration.builder() .selfSigned("abcd", "efgh") .build(); assertThat( WebAdminConfiguration.builder() .enabled() .tls(tlsConfiguration) .port(PORT) .build()) .extracting(WebAdminConfiguration::getTlsConfiguration) .isEqualTo(tlsConfiguration); }
@Test public void builderShouldReturnTlsEnableWhenTlsConfiguration() { TlsConfiguration tlsConfiguration = TlsConfiguration.builder() .selfSigned("abcd", "efgh") .build(); assertThat( WebAdminConfiguration.builder() .enabled() .tls(tlsConfiguration) .port(PORT) .build()) .extracting(WebAdminConfiguration::getTlsConfiguration) .isEqualTo(tlsConfiguration); }
@Test public void builderShouldReturnTlsDisableWhenNoTlsConfiguration() { assertThat( WebAdminConfiguration.builder() .enabled() .port(PORT) .build()) .extracting(WebAdminConfiguration::isTlsEnabled) .isEqualTo(false); }
@Test public void builderShouldCORSEnabled() { assertThat( WebAdminConfiguration.builder() .enabled() .port(PORT) .corsEnabled() .build()) .extracting(WebAdminConfiguration::isEnableCORS) .isEqualTo(true); }
@Test public void builderShouldAcceptAllOriginsByDefault() { assertThat( WebAdminConfiguration.builder() .enabled() .port(PORT) .corsEnabled() .build()) .extracting(WebAdminConfiguration::getUrlCORSOrigin) .isEqualTo("*"); }
@Test public void builderShouldCORSDisabled() { assertThat( WebAdminConfiguration.builder() .enabled() .port(PORT) .corsDisabled() .build()) .extracting(WebAdminConfiguration::isEnableCORS) .isEqualTo(false); }
@Test public void builderShouldCORSWithOrigin() { String origin = "linagora.com"; assertThat( WebAdminConfiguration.builder() .enabled() .port(PORT) .corsEnabled() .urlCORSOrigin(origin) .build()) .extracting(WebAdminConfiguration::getUrlCORSOrigin) .isEqualTo(origin); }
@Test public void builderShouldDefineHostWithDefault() { assertThat( WebAdminConfiguration.builder() .enabled() .port(PORT) .build()) .extracting(WebAdminConfiguration::getHost) .isEqualTo(WebAdminConfiguration.DEFAULT_HOST); }
@Test public void builderShouldDefineHostWithSetting() { String host = "any.host"; assertThat( WebAdminConfiguration.builder() .enabled() .port(PORT) .host(host) .build()) .extracting(WebAdminConfiguration::getHost) .isEqualTo(host); }