GovernanceConfigurationYamlSwapper implements YamlSwapper<YamlGovernanceConfiguration, GovernanceConfiguration> { @Override public GovernanceConfiguration swapToObject(final YamlGovernanceConfiguration yamlConfig) { GovernanceCenterConfiguration registryCenter = governanceCenterConfigurationSwapper.swapToObject(yamlConfig.getRegistryCenter()); if (null == yamlConfig.getAdditionalConfigCenter()) { return new GovernanceConfiguration(yamlConfig.getName(), registryCenter, yamlConfig.isOverwrite()); } GovernanceCenterConfiguration additionalConfigCenter = governanceCenterConfigurationSwapper.swapToObject(yamlConfig.getAdditionalConfigCenter()); return new GovernanceConfiguration(yamlConfig.getName(), registryCenter, additionalConfigCenter, yamlConfig.isOverwrite()); }  @Override YamlGovernanceConfiguration swapToYamlConfiguration(final GovernanceConfiguration data); @Override GovernanceConfiguration swapToObject(final YamlGovernanceConfiguration yamlConfig);  }
@Test public void assertSwapToGovernanceConfigurationWithoutAdditionalConfigCenterConfiguration() { YamlGovernanceConfiguration expected = createYamlGovernanceConfigurationWithoutAdditionalConfigCenterConfiguration(); GovernanceConfiguration actual = new GovernanceConfigurationYamlSwapper().swapToObject(expected); assertThat(actual.getName(), is(expected.getName())); assertThat(actual.isOverwrite(), is(expected.isOverwrite())); assertThat(actual.getRegistryCenterConfiguration().getType(), is(expected.getRegistryCenter().getType())); assertThat(actual.getRegistryCenterConfiguration().getServerLists(), is(expected.getRegistryCenter().getServerLists())); assertThat(actual.getRegistryCenterConfiguration().getProps(), is(expected.getRegistryCenter().getProps())); assertFalse(actual.getAdditionalConfigCenterConfiguration().isPresent()); }
@Test public void assertSwapToGovernanceConfigurationWithAdditionalConfigCenterConfiguration() { YamlGovernanceConfiguration expected = createYamlGovernanceConfigurationWithAdditionalConfigCenterConfiguration(); GovernanceConfiguration actual = new GovernanceConfigurationYamlSwapper().swapToObject(expected); assertThat(actual.getName(), is(expected.getName())); assertThat(actual.isOverwrite(), is(expected.isOverwrite())); assertThat(actual.getRegistryCenterConfiguration().getType(), is(expected.getRegistryCenter().getType())); assertThat(actual.getRegistryCenterConfiguration().getServerLists(), is(expected.getRegistryCenter().getServerLists())); assertThat(actual.getRegistryCenterConfiguration().getProps(), is(expected.getRegistryCenter().getProps())); assertTrue(actual.getAdditionalConfigCenterConfiguration().isPresent()); assertThat(actual.getAdditionalConfigCenterConfiguration().get().getType(), is(expected.getAdditionalConfigCenter().getType())); assertThat(actual.getAdditionalConfigCenterConfiguration().get().getServerLists(), is(expected.getAdditionalConfigCenter().getServerLists())); assertThat(actual.getAdditionalConfigCenterConfiguration().get().getProps(), is(expected.getAdditionalConfigCenter().getProps())); }