ConfigCenter { public Optional<RuleSchemaMetaData> loadMetaData(final String schemaName) { String path = repository.get(node.getTablePath(schemaName)); if (Strings.isNullOrEmpty(path)) { return Optional.empty(); } return Optional.of(new RuleSchemaMetaDataYamlSwapper().swapToObject(YamlEngine.unmarshal(path, YamlRuleSchemaMetaData.class))); } ConfigCenter(final ConfigurationRepository repository); void persistConfigurations(final String schemaName, final Map<String, DataSourceConfiguration> dataSourceConfigs,
                                      final Collection<RuleConfiguration> ruleConfigurations, final boolean isOverwrite); void persistGlobalConfiguration(final Authentication authentication, final Properties props, final boolean isOverwrite); @Subscribe synchronized void renew(final DataSourcePersistEvent event); @Subscribe synchronized void renew(final RulePersistEvent event); @Subscribe synchronized void renew(final SchemaNamePersistEvent event); @Subscribe synchronized void renew(final MetaDataPersistEvent event); Map<String, DataSourceConfiguration> loadDataSourceConfigurations(final String schemaName); Collection<RuleConfiguration> loadRuleConfigurations(final String schemaName); Authentication loadAuthentication(); Properties loadProperties(); Collection<String> getAllSchemaNames(); boolean hasRuleConfiguration(final String schemaName); boolean hasDataSourceConfiguration(final String schemaName); void persistMetaData(final String schemaName, final RuleSchemaMetaData ruleSchemaMetaData); Optional<RuleSchemaMetaData> loadMetaData(final String schemaName); void deleteSchema(final String schemaName);  }
@Test public void assertLoadMetaData() { when(configurationRepository.get("/schemas/sharding_db/table")).thenReturn(readYAML(META_DATA_YAML)); ConfigCenter configCenter = new ConfigCenter(configurationRepository); Optional<RuleSchemaMetaData> optionalRuleSchemaMetaData = configCenter.loadMetaData("sharding_db"); assertTrue(optionalRuleSchemaMetaData.isPresent()); Optional<RuleSchemaMetaData> empty = configCenter.loadMetaData("test"); assertThat(empty, is(Optional.empty())); RuleSchemaMetaData ruleSchemaMetaData = optionalRuleSchemaMetaData.get(); verify(configurationRepository).get(eq("/schemas/sharding_db/table")); assertNotNull(ruleSchemaMetaData); assertNotNull(ruleSchemaMetaData.getConfiguredSchemaMetaData()); assertNotNull(ruleSchemaMetaData.getUnconfiguredSchemaMetaDataMap()); assertThat(ruleSchemaMetaData.getConfiguredSchemaMetaData().getAllTableNames(), is(Collections.singleton("t_order"))); assertThat(ruleSchemaMetaData.getConfiguredSchemaMetaData().get("t_order").getIndexes().keySet(), is(Collections.singleton("primary"))); assertThat(ruleSchemaMetaData.getConfiguredSchemaMetaData().getAllColumnNames("t_order").size(), is(1)); assertThat(ruleSchemaMetaData.getConfiguredSchemaMetaData().get("t_order").getColumns().keySet(), is(Collections.singleton("id"))); assertThat(ruleSchemaMetaData.getUnconfiguredSchemaMetaDataMap().keySet(), is(Collections.singleton("ds_0"))); assertThat(ruleSchemaMetaData.getUnconfiguredSchemaMetaDataMap().get("ds_0"), is(Collections.singletonList("t_user"))); }