Search in sources :

Example 6 with RealmConfigData

use of org.keycloak.client.admin.cli.config.RealmConfigData in project keycloak by keycloak.

the class AbstractAdmCliTest method assertFieldsEqualWithExclusions.

void assertFieldsEqualWithExclusions(ConfigData config1, ConfigData config2, String... excluded) {
    HashSet<String> exclusions = new HashSet<>(Arrays.asList(excluded));
    if (!exclusions.contains("serverUrl")) {
        Assert.assertEquals("serverUrl", config1.getServerUrl(), config2.getServerUrl());
    }
    if (!exclusions.contains("realm")) {
        Assert.assertEquals("realm", config1.getRealm(), config2.getRealm());
    }
    if (!exclusions.contains("truststore")) {
        Assert.assertEquals("truststore", config1.getTruststore(), config2.getTruststore());
    }
    if (!exclusions.contains("endpoints")) {
        Map<String, Map<String, RealmConfigData>> endp1 = config1.getEndpoints();
        Map<String, Map<String, RealmConfigData>> endp2 = config2.getEndpoints();
        Iterator<Map.Entry<String, Map<String, RealmConfigData>>> it1 = endp1.entrySet().iterator();
        Iterator<Map.Entry<String, Map<String, RealmConfigData>>> it2 = endp2.entrySet().iterator();
        while (it1.hasNext()) {
            Map.Entry<String, Map<String, RealmConfigData>> ent1 = it1.next();
            Map.Entry<String, Map<String, RealmConfigData>> ent2 = it2.next();
            String serverUrl = ent1.getKey();
            String endpskey = "endpoints." + serverUrl;
            if (!exclusions.contains(endpskey)) {
                Assert.assertEquals(endpskey, ent1.getKey(), ent2.getKey());
                Map<String, RealmConfigData> realms1 = ent1.getValue();
                Map<String, RealmConfigData> realms2 = ent2.getValue();
                Iterator<Map.Entry<String, RealmConfigData>> rit1 = realms1.entrySet().iterator();
                Iterator<Map.Entry<String, RealmConfigData>> rit2 = realms2.entrySet().iterator();
                while (rit1.hasNext()) {
                    Map.Entry<String, RealmConfigData> rent1 = rit1.next();
                    Map.Entry<String, RealmConfigData> rent2 = rit2.next();
                    String realm = rent1.getKey();
                    String rkey = endpskey + "." + realm;
                    if (!exclusions.contains(endpskey)) {
                        Assert.assertEquals(rkey, rent1.getKey(), rent2.getKey());
                        RealmConfigData rdata1 = rent1.getValue();
                        RealmConfigData rdata2 = rent2.getValue();
                        assertFieldsEqualWithExclusions(serverUrl, realm, rdata1, rdata2, excluded);
                    }
                }
            }
        }
    }
}
Also used : RealmConfigData(org.keycloak.client.admin.cli.config.RealmConfigData) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

RealmConfigData (org.keycloak.client.admin.cli.config.RealmConfigData)6 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Test (org.junit.Test)1 ConfigData (org.keycloak.client.admin.cli.config.ConfigData)1 FileConfigHandler (org.keycloak.client.admin.cli.config.FileConfigHandler)1 AccessTokenResponse (org.keycloak.representations.AccessTokenResponse)1 KcAdmExec (org.keycloak.testsuite.cli.KcAdmExec)1