use of io.shardingjdbc.spring.fixture.DecrementKeyGenerator in project sharding-jdbc by shardingjdbc.
the class GenerateKeyDBUnitTest method assertGenerateKeyColumn.
@SuppressWarnings("unchecked")
@Test
public void assertGenerateKeyColumn() {
Object shardingContext = FieldValueUtil.getFieldValue(shardingDataSource, "shardingContext", true);
assertNotNull(shardingContext);
Object shardingRule = FieldValueUtil.getFieldValue(shardingContext, "shardingRule");
assertNotNull(shardingRule);
Object defaultKeyGenerator = FieldValueUtil.getFieldValue(shardingRule, "defaultKeyGenerator");
assertNotNull(defaultKeyGenerator);
assertTrue(defaultKeyGenerator instanceof IncrementKeyGenerator);
Object tableRules = FieldValueUtil.getFieldValue(shardingRule, "tableRules");
assertNotNull(tableRules);
assertThat(((Collection<TableRule>) tableRules).size(), is(2));
Iterator<TableRule> tableRuleIterator = ((Collection<TableRule>) tableRules).iterator();
TableRule orderRule = tableRuleIterator.next();
assertThat(orderRule.getGenerateKeyColumn(), is("order_id"));
TableRule orderItemRule = tableRuleIterator.next();
assertThat(orderItemRule.getGenerateKeyColumn(), is("order_item_id"));
assertTrue(orderItemRule.getKeyGenerator() instanceof DecrementKeyGenerator);
}
Aggregations