ab74ba811a6348c4969a2408644b0e48502af076
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / shardstrategy / ShardStrategyFactoryTest.java
1 package org.opendaylight.controller.cluster.datastore.shardstrategy;
2
3 import org.junit.BeforeClass;
4 import org.junit.Rule;
5 import org.junit.Test;
6 import org.junit.rules.ExpectedException;
7 import org.opendaylight.controller.cluster.datastore.ConfigurationImpl;
8 import org.opendaylight.controller.md.cluster.datastore.model.CarsModel;
9 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
10 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
11
12 import static junit.framework.Assert.assertNotNull;
13 import static junit.framework.Assert.assertTrue;
14
15 public class ShardStrategyFactoryTest {
16
17     @Rule
18     public ExpectedException expectedEx = ExpectedException.none();
19
20     @BeforeClass
21     public static void setUpClass(){
22         ShardStrategyFactory.setConfiguration(new ConfigurationImpl("module-shards.conf", "modules.conf"));
23     }
24
25     @Test
26     public void testGetStrategy() {
27         ShardStrategy strategy =
28             ShardStrategyFactory.getStrategy(TestModel.TEST_PATH);
29         assertNotNull(strategy);
30     }
31
32     @Test
33     public void testGetStrategyForKnownModuleName() {
34         ShardStrategy strategy =
35             ShardStrategyFactory.getStrategy(
36                 YangInstanceIdentifier.of(CarsModel.BASE_QNAME));
37         assertTrue(strategy instanceof ModuleShardStrategy);
38     }
39
40
41     @Test
42     public void testGetStrategyNullPointerExceptionWhenPathIsNull() {
43         expectedEx.expect(NullPointerException.class);
44         expectedEx.expectMessage("path should not be null");
45
46         ShardStrategyFactory.getStrategy(null);
47     }
48
49 }