AuthenticationYamlSwapper implements YamlSwapper<YamlAuthenticationConfiguration, Authentication> { @Override public Authentication swapToObject(final YamlAuthenticationConfiguration yamlConfig) { Authentication result = new Authentication(); if (null == yamlConfig) { return result; } result.getUsers().putAll(Maps.transformValues(yamlConfig.getUsers(), proxyUserYamlSwapper::swapToObject)); return result; }  @Override YamlAuthenticationConfiguration swapToYamlConfiguration(final Authentication data); @Override Authentication swapToObject(final YamlAuthenticationConfiguration yamlConfig);  }
@Test public void assertSwapToObject() { YamlProxyUserConfiguration user1 = new YamlProxyUserConfiguration(); user1.setPassword("pwd1"); user1.setAuthorizedSchemas("db1"); YamlProxyUserConfiguration user2 = new YamlProxyUserConfiguration(); user2.setPassword("pwd2"); user2.setAuthorizedSchemas("db2,db1"); Map<String, YamlProxyUserConfiguration> users = new HashMap<>(2, 1); users.put("user1", user1); users.put("user2", user2); YamlAuthenticationConfiguration yamlConfig = new YamlAuthenticationConfiguration(); yamlConfig.setUsers(users); Authentication actual = new AuthenticationYamlSwapper().swapToObject(yamlConfig); assertThat(actual.getUsers().size(), is(2)); assertThat(actual.getUsers().get("user1").getAuthorizedSchemas().size(), is(1)); assertThat(actual.getUsers().get("user2").getAuthorizedSchemas().size(), is(2)); }
@Test public void assertSwapToObjectForNull() { Authentication actual = new AuthenticationYamlSwapper().swapToObject(null); assertTrue(actual.getUsers().isEmpty()); }