ConsensusReplicationRuleConfigurationYamlSwapper implements YamlRuleConfigurationSwapper<YamlConsensusReplicationRuleConfiguration, ConsensusReplicationRuleConfiguration> { @Override public YamlConsensusReplicationRuleConfiguration swapToYamlConfiguration(final ConsensusReplicationRuleConfiguration data) { Collection<YamlConsensusReplicationLogicTableRuleConfiguration> yamlTables = data.getTables().stream() .map(logicTableRuleConfigurationYamlSwapper::swapToYamlConfiguration) .collect(Collectors.toList()); YamlConsensusReplicationRuleConfiguration result = new YamlConsensusReplicationRuleConfiguration(); result.setTables(yamlTables); return result; }  @Override YamlConsensusReplicationRuleConfiguration swapToYamlConfiguration(final ConsensusReplicationRuleConfiguration data); @Override ConsensusReplicationRuleConfiguration swapToObject(final YamlConsensusReplicationRuleConfiguration yamlConfig); @Override Class<ConsensusReplicationRuleConfiguration> getTypeClass(); @Override String getRuleTagName(); @Override int getOrder();  }
@Test public void assertSwapToYamlConfigurationWithMinProperties() { YamlConsensusReplicationRuleConfiguration yamlConfig = swapper.swapToYamlConfiguration(new ConsensusReplicationRuleConfiguration( Collections.singleton(new ConsensusReplicationLogicTableRuleConfiguration(logicTableName, null)))); assertNotNull(yamlConfig); assertNotNull(yamlConfig.getTables()); assertThat(yamlConfig.getTables().size(), is(1)); Collection<YamlConsensusReplicationActualTableRuleConfiguration> resultReplicaGroups = yamlConfig.getTables().iterator().next().getReplicaGroups(); assertNotNull(resultReplicaGroups); assertTrue(resultReplicaGroups.isEmpty()); }
@Test public void assertSwapToYamlConfigurationWithMaxProperties() { ConsensusReplicationActualTableRuleConfiguration replicaGroup = new ConsensusReplicationActualTableRuleConfiguration(physicsTable, replicaGroupId, replicaPeers, dataSourceName); Collection<ConsensusReplicationActualTableRuleConfiguration> replicaGroups = Collections.singleton(replicaGroup); ConsensusReplicationLogicTableRuleConfiguration table = new ConsensusReplicationLogicTableRuleConfiguration(logicTableName, replicaGroups); YamlConsensusReplicationRuleConfiguration yamlConfig = swapper.swapToYamlConfiguration(new ConsensusReplicationRuleConfiguration(Collections.singleton(table))); assertNotNull(yamlConfig); assertNotNull(yamlConfig.getTables()); assertThat(yamlConfig.getTables().size(), is(1)); Collection<YamlConsensusReplicationActualTableRuleConfiguration> resultReplicaGroups = yamlConfig.getTables().iterator().next().getReplicaGroups(); assertNotNull(resultReplicaGroups); assertThat(resultReplicaGroups.size(), is(1)); YamlConsensusReplicationActualTableRuleConfiguration resultReplicaGroup = resultReplicaGroups.iterator().next(); assertThat(resultReplicaGroup.getDataSourceName(), is(dataSourceName)); assertThat(resultReplicaGroup.getPhysicsTable(), is(physicsTable)); assertThat(resultReplicaGroup.getReplicaGroupId(), is(replicaGroupId)); assertThat(resultReplicaGroup.getReplicaPeers(), is(replicaPeers)); }