ShardingStrategyConfigurationYamlSwapper implements YamlSwapper<YamlShardingStrategyConfiguration, ShardingStrategyConfiguration> { @Override public YamlShardingStrategyConfiguration swapToYamlConfiguration(final ShardingStrategyConfiguration data) { YamlShardingStrategyConfiguration result = new YamlShardingStrategyConfiguration(); if (data instanceof StandardShardingStrategyConfiguration) { result.setStandard(createYamlStandardShardingStrategyConfiguration((StandardShardingStrategyConfiguration) data)); } if (data instanceof ComplexShardingStrategyConfiguration) { result.setComplex(createYamlComplexShardingStrategyConfiguration((ComplexShardingStrategyConfiguration) data)); } if (data instanceof HintShardingStrategyConfiguration) { result.setHint(createYamlHintShardingStrategyConfiguration((HintShardingStrategyConfiguration) data)); } if (data instanceof NoneShardingStrategyConfiguration) { result.setNone(new YamlNoneShardingStrategyConfiguration()); } return result; }  @Override YamlShardingStrategyConfiguration swapToYamlConfiguration(final ShardingStrategyConfiguration data); @Override ShardingStrategyConfiguration swapToObject(final YamlShardingStrategyConfiguration yamlConfig);  }
@Test public void assertSwapToYamlWithStandard() { YamlShardingStrategyConfiguration actual = shardingStrategyConfigurationYamlSwapper.swapToYamlConfiguration(new StandardShardingStrategyConfiguration("id", "standard")); assertThat(actual.getStandard().getShardingColumn(), is("id")); assertThat(actual.getStandard().getShardingAlgorithmName(), is("standard")); assertNull(actual.getComplex()); assertNull(actual.getHint()); assertNull(actual.getNone()); }
@Test public void assertSwapToYamlWithComplex() { YamlShardingStrategyConfiguration actual = shardingStrategyConfigurationYamlSwapper.swapToYamlConfiguration(new ComplexShardingStrategyConfiguration("id, creation_date", "complex")); assertThat(actual.getComplex().getShardingColumns(), is("id, creation_date")); assertThat(actual.getComplex().getShardingAlgorithmName(), is("complex")); assertNull(actual.getStandard()); assertNull(actual.getHint()); assertNull(actual.getNone()); }
@Test public void assertSwapToYamlWithHint() { HintShardingAlgorithm hintShardingAlgorithm = mock(HintShardingAlgorithm.class); when(hintShardingAlgorithm.getType()).thenReturn("HINT_TEST"); YamlShardingStrategyConfiguration actual = shardingStrategyConfigurationYamlSwapper.swapToYamlConfiguration(new HintShardingStrategyConfiguration("hint")); assertThat(actual.getHint().getShardingAlgorithmName(), is("hint")); assertNull(actual.getStandard()); assertNull(actual.getComplex()); assertNull(actual.getNone()); }
@Test public void assertSwapToYamlWithNone() { YamlShardingStrategyConfiguration actual = shardingStrategyConfigurationYamlSwapper.swapToYamlConfiguration(new NoneShardingStrategyConfiguration()); assertNull(actual.getStandard()); assertNull(actual.getComplex()); assertNull(actual.getHint()); assertThat(actual.getNone(), instanceOf(YamlNoneShardingStrategyConfiguration.class)); }