ConsensusReplicationRuleConfigurationYamlSwapper implements YamlRuleConfigurationSwapper<YamlConsensusReplicationRuleConfiguration, ConsensusReplicationRuleConfiguration> { @Override public ConsensusReplicationRuleConfiguration swapToObject(final YamlConsensusReplicationRuleConfiguration yamlConfig) { Collection<ConsensusReplicationLogicTableRuleConfiguration> tables = yamlConfig.getTables().stream() .map(logicTableRuleConfigurationYamlSwapper::swapToObject) .collect(Collectors.toList()); return new ConsensusReplicationRuleConfiguration(tables); }  @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 assertSwapToObjectWithMinProperties() { YamlConsensusReplicationLogicTableRuleConfiguration yamlLogicTable = new YamlConsensusReplicationLogicTableRuleConfiguration(); yamlLogicTable.setLogicTable(logicTableName); YamlConsensusReplicationRuleConfiguration yamlConfig = new YamlConsensusReplicationRuleConfiguration(); yamlConfig.setTables(Collections.singleton(yamlLogicTable)); ConsensusReplicationRuleConfiguration config = swapper.swapToObject(yamlConfig); assertNotNull(config); assertNotNull(config.getTables()); assertThat(config.getTables().size(), is(1)); Collection<ConsensusReplicationActualTableRuleConfiguration> resultReplicaGroups = config.getTables().iterator().next().getReplicaGroups(); assertNotNull(resultReplicaGroups); assertTrue(resultReplicaGroups.isEmpty()); }
@Test public void assertSwapToObjectWithMaxProperties() { YamlConsensusReplicationActualTableRuleConfiguration replicaGroup = new YamlConsensusReplicationActualTableRuleConfiguration(); replicaGroup.setPhysicsTable(physicsTable); replicaGroup.setReplicaGroupId(replicaGroupId); replicaGroup.setReplicaPeers(replicaPeers); replicaGroup.setDataSourceName(dataSourceName); Collection<YamlConsensusReplicationActualTableRuleConfiguration> replicaGroups = Collections.singleton(replicaGroup); YamlConsensusReplicationLogicTableRuleConfiguration table = new YamlConsensusReplicationLogicTableRuleConfiguration(); table.setLogicTable(logicTableName); table.setReplicaGroups(replicaGroups); YamlConsensusReplicationRuleConfiguration yamlConfig = new YamlConsensusReplicationRuleConfiguration(); yamlConfig.setTables(Collections.singleton(table)); ConsensusReplicationRuleConfiguration config = swapper.swapToObject(yamlConfig); assertNotNull(config); assertNotNull(config.getTables()); assertThat(config.getTables().size(), is(1)); Collection<ConsensusReplicationActualTableRuleConfiguration> resultReplicaGroups = config.getTables().iterator().next().getReplicaGroups(); assertNotNull(resultReplicaGroups); assertThat(resultReplicaGroups.size(), is(1)); ConsensusReplicationActualTableRuleConfiguration resultReplicaGroup = resultReplicaGroups.iterator().next(); assertThat(resultReplicaGroup.getDataSourceName(), is(dataSourceName)); assertThat(resultReplicaGroup.getPhysicsTable(), is(physicsTable)); assertThat(resultReplicaGroup.getReplicaGroupId(), is(replicaGroupId)); assertThat(resultReplicaGroup.getReplicaPeers(), is(replicaPeers)); }