ShardingAutoTableRuleConfigurationYamlSwapper implements YamlSwapper<YamlShardingAutoTableRuleConfiguration, ShardingAutoTableRuleConfiguration> { @Override public YamlShardingAutoTableRuleConfiguration swapToYamlConfiguration(final ShardingAutoTableRuleConfiguration data) { YamlShardingAutoTableRuleConfiguration result = new YamlShardingAutoTableRuleConfiguration(); result.setLogicTable(data.getLogicTable()); result.setActualDataSources(data.getActualDataSources()); if (null != data.getShardingStrategy()) { result.setShardingStrategy(shardingStrategyYamlSwapper.swapToYamlConfiguration(data.getShardingStrategy())); } if (null != data.getKeyGenerateStrategy()) { result.setKeyGenerateStrategy(keyGenerateStrategyYamlSwapper.swapToYamlConfiguration(data.getKeyGenerateStrategy())); } return result; }  @Override YamlShardingAutoTableRuleConfiguration swapToYamlConfiguration(final ShardingAutoTableRuleConfiguration data); @Override ShardingAutoTableRuleConfiguration swapToObject(final YamlShardingAutoTableRuleConfiguration yamlConfig);  }
@Test public void assertSwapToYamlWithMinProperties() { YamlShardingAutoTableRuleConfiguration actual = tableYamlSwapper.swapToYamlConfiguration(new ShardingAutoTableRuleConfiguration("tbl", "ds0,ds1")); assertThat(actual.getLogicTable(), is("tbl")); assertThat(actual.getActualDataSources(), is("ds0,ds1")); assertNull(actual.getShardingStrategy()); assertNull(actual.getKeyGenerateStrategy()); }
@Test public void assertSwapToYamlWithMaxProperties() { ShardingAutoTableRuleConfiguration shardingTableRuleConfig = new ShardingAutoTableRuleConfiguration("tbl", "ds0,ds1"); shardingTableRuleConfig.setShardingStrategy(mock(StandardShardingStrategyConfiguration.class)); shardingTableRuleConfig.setKeyGenerateStrategy(mock(KeyGenerateStrategyConfiguration.class)); YamlShardingAutoTableRuleConfiguration actual = tableYamlSwapper.swapToYamlConfiguration(shardingTableRuleConfig); assertThat(actual.getLogicTable(), is("tbl")); assertThat(actual.getActualDataSources(), is("ds0,ds1")); assertNotNull(actual.getShardingStrategy()); assertNotNull(actual.getKeyGenerateStrategy()); }