PrimaryReplicaReplicationRuleConfigurationYamlSwapper implements YamlRuleConfigurationSwapper<YamlPrimaryReplicaReplicationRuleConfiguration, PrimaryReplicaReplicationRuleConfiguration> { @Override public PrimaryReplicaReplicationRuleConfiguration swapToObject(final YamlPrimaryReplicaReplicationRuleConfiguration yamlConfig) { Collection<PrimaryReplicaReplicationDataSourceRuleConfiguration> dataSources = new LinkedList<>(); for (Entry<String, YamlPrimaryReplicaReplicationDataSourceRuleConfiguration> entry : yamlConfig.getDataSources().entrySet()) { dataSources.add(swapToObject(entry.getKey(), entry.getValue())); } Map<String, ShardingSphereAlgorithmConfiguration> loadBalancers = new LinkedHashMap<>(yamlConfig.getLoadBalancers().entrySet().size(), 1); if (null != yamlConfig.getLoadBalancers()) { yamlConfig.getLoadBalancers().forEach((key, value) -> loadBalancers.put(key, algorithmSwapper.swapToObject(value))); } return new PrimaryReplicaReplicationRuleConfiguration(dataSources, loadBalancers); }  @Override YamlPrimaryReplicaReplicationRuleConfiguration swapToYamlConfiguration(final PrimaryReplicaReplicationRuleConfiguration data); @Override PrimaryReplicaReplicationRuleConfiguration swapToObject(final YamlPrimaryReplicaReplicationRuleConfiguration yamlConfig); @Override Class<PrimaryReplicaReplicationRuleConfiguration> getTypeClass(); @Override String getRuleTagName(); @Override int getOrder();  }
@Test public void assertSwapToObjectWithLoadBalanceAlgorithmType() { YamlPrimaryReplicaReplicationRuleConfiguration yamlConfig = createYamlPrimaryReplicaReplicationRuleConfiguration(); yamlConfig.getDataSources().get("primary_replica_ds").setLoadBalancerName("RANDOM"); PrimaryReplicaReplicationRuleConfiguration actual = getPrimaryReplicaReplicationRuleConfigurationYamlSwapper().swapToObject(yamlConfig); assertPrimaryReplicaReplicationRuleConfiguration(actual); assertThat(actual.getDataSources().iterator().next().getLoadBalancerName(), is("RANDOM")); }
@Test public void assertSwapToObjectWithoutLoadBalanceAlgorithm() { YamlPrimaryReplicaReplicationRuleConfiguration yamlConfig = createYamlPrimaryReplicaReplicationRuleConfiguration(); PrimaryReplicaReplicationRuleConfiguration actual = getPrimaryReplicaReplicationRuleConfigurationYamlSwapper().swapToObject(yamlConfig); assertPrimaryReplicaReplicationRuleConfiguration(actual); assertNull(actual.getDataSources().iterator().next().getLoadBalancerName()); }