Search in sources :

Example 1 with IndyHttpConfig

use of org.commonjava.indy.subsys.http.conf.IndyHttpConfig in project indy by Commonjava.

the class IndySiteConfigLookupTest method checkHttpConfigLoad.

@Test
public void checkHttpConfigLoad() throws Exception {
    File pemFile = testFolder.newFile("keycloak.pem");
    final String _URI = "http://site.com";
    final String _PROXY_HOST = "http://proxy.com";
    final String _PROXY_PORT = "8001";
    final String _PEM = "AAAAFFFFFSDADFADSFASDFASDFASDFASDFASDF";
    final String _KEY_PASSWORD = "testme";
    final String _KEYCLOAK_URI = "http://keycloak.com";
    final String _KEYCLOAK_PEM_PATH = pemFile.getAbsolutePath();
    IOUtils.write(_PEM, new FileOutputStream(pemFile));
    final class TestIndyHttpConfig extends IndyHttpConfig {

        @Override
        public Map<String, String> getConfiguration() {
            Map<String, String> parameters = new HashMap<>();
            parameters.put("uri", _URI);
            parameters.put("proxy.host", _PROXY_HOST);
            parameters.put("proxy.port", _PROXY_PORT);
            parameters.put("key.cert.pem", _PEM);
            parameters.put("key.password", _KEY_PASSWORD);
            parameters.put("keycloak_yourdomain_com.uri", _KEYCLOAK_URI);
            parameters.put("keycloak_yourdomain_com.key.cert.pem.path", _KEYCLOAK_PEM_PATH);
            return parameters;
        }
    }
    IndyHttpConfig config = new TestIndyHttpConfig();
    config.sectionComplete("http");
    IndySiteConfigLookup lookup = new IndySiteConfigLookup(null, config);
    SiteConfig siteConfig = lookup.lookup(DEFAULT_SITE);
    assertThat(siteConfig.getUri(), equalTo(_URI));
    assertThat(siteConfig.getProxyHost(), equalTo(_PROXY_HOST));
    assertThat(siteConfig.getProxyPort(), equalTo(Integer.parseInt(_PROXY_PORT)));
    assertThat(siteConfig.getKeyCertPem(), equalTo(_PEM));
    assertThat(siteConfig.getAttribute(PASSWORD_PREFIX + PasswordType.KEY.name()), equalTo(_KEY_PASSWORD));
    SiteConfig keycloakConfig = lookup.lookup("keycloak.yourdomain.com");
    assertThat(keycloakConfig.getUri(), equalTo(_KEYCLOAK_URI));
    assertThat(keycloakConfig.getKeyCertPem(), equalTo(_PEM));
}
Also used : HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) SiteConfig(org.commonjava.util.jhttpc.model.SiteConfig) File(java.io.File) IndyHttpConfig(org.commonjava.indy.subsys.http.conf.IndyHttpConfig) Test(org.junit.Test)

Aggregations

File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 HashMap (java.util.HashMap)1 IndyHttpConfig (org.commonjava.indy.subsys.http.conf.IndyHttpConfig)1 SiteConfig (org.commonjava.util.jhttpc.model.SiteConfig)1 Test (org.junit.Test)1