Bug 4105: Add dynamic module/shard config for entity-owners shard
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / shardstrategy / ShardStrategyFactoryTest.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.cluster.datastore.shardstrategy;
10
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import org.junit.Before;
14 import org.junit.Rule;
15 import org.junit.Test;
16 import org.junit.rules.ExpectedException;
17 import org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl;
18 import org.opendaylight.controller.md.cluster.datastore.model.CarsModel;
19 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21
22 public class ShardStrategyFactoryTest {
23
24     ShardStrategyFactory factory;
25
26     @Rule
27     public ExpectedException expectedEx = ExpectedException.none();
28
29     @Before
30     public void setUp() {
31         factory = new ShardStrategyFactory(new ConfigurationImpl("module-shards.conf", "modules.conf"));
32     }
33
34     @Test
35     public void testGetStrategy() {
36         ShardStrategy strategy = factory.getStrategy(TestModel.TEST_PATH);
37         assertNotNull(strategy);
38     }
39
40     @Test
41     public void testGetStrategyForKnownModuleName() {
42         ShardStrategy strategy = factory.getStrategy(YangInstanceIdentifier.of(CarsModel.BASE_QNAME));
43         assertTrue(strategy instanceof ModuleShardStrategy);
44     }
45
46
47     @Test
48     public void testGetStrategyNullPointerExceptionWhenPathIsNull() {
49         expectedEx.expect(NullPointerException.class);
50         expectedEx.expectMessage("path should not be null");
51
52         factory.getStrategy(null);
53     }
54
55 }