Search in sources :

Example 1 with DecrementKeyGenerator

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);
}
Also used : TableRule(io.shardingjdbc.core.rule.TableRule) Collection(java.util.Collection) IncrementKeyGenerator(io.shardingjdbc.spring.fixture.IncrementKeyGenerator) DecrementKeyGenerator(io.shardingjdbc.spring.fixture.DecrementKeyGenerator) Test(org.junit.Test)

Aggregations

TableRule (io.shardingjdbc.core.rule.TableRule)1 DecrementKeyGenerator (io.shardingjdbc.spring.fixture.DecrementKeyGenerator)1 IncrementKeyGenerator (io.shardingjdbc.spring.fixture.IncrementKeyGenerator)1 Collection (java.util.Collection)1 Test (org.junit.Test)1