CreateShardingRuleStatementContextConverter implements SQLStatementContextConverter<CreateShardingRuleStatementContext, YamlShardingRuleConfiguration> { @Override public YamlShardingRuleConfiguration convert(final CreateShardingRuleStatementContext context) { YamlShardingRuleConfiguration result = new YamlShardingRuleConfiguration(); for (TableRuleSegment each : context.getSqlStatement().getTables()) { result.getShardingAlgorithms().put(getAlgorithmName(each.getLogicTable(), each.getAlgorithmType()), createAlgorithmConfiguration(each, context.getAlgorithmProperties(each))); result.getAutoTables().put(each.getLogicTable(), createAutoTableRuleConfiguration(each)); } return result; }  @Override YamlShardingRuleConfiguration convert(final CreateShardingRuleStatementContext context);  }
@Test public void generate() { YamlShardingRuleConfiguration rule = new CreateShardingRuleStatementContextConverter().convert(context); assertTrue(rule.getTables().isEmpty()); assertThat(rule.getAutoTables().size(), is(1)); assertThat(rule.getAutoTables().get(segment.getLogicTable()).getActualDataSources(), is("ds0,ds1")); assertThat(rule.getAutoTables().get(segment.getLogicTable()).getShardingStrategy().getStandard().getShardingColumn(), is("order_id")); assertThat(rule.getAutoTables().get(segment.getLogicTable()).getShardingStrategy().getStandard().getShardingAlgorithmName(), is("t_order_MOD")); assertTrue(rule.getShardingAlgorithms().containsKey("t_order_MOD")); assertThat(rule.getShardingAlgorithms().get("t_order_MOD").getType(), is("MOD")); }