76cb7334fab2b9935032e83967f4bfc1e54bf43b
[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
14 import org.junit.Before;
15 import org.junit.Rule;
16 import org.junit.Test;
17 import org.junit.rules.ExpectedException;
18 import org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl;
19 import org.opendaylight.controller.md.cluster.datastore.model.CarsModel;
20 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22
23 public class ShardStrategyFactoryTest {
24
25     ShardStrategyFactory factory;
26
27     @Rule
28     public ExpectedException expectedEx = ExpectedException.none();
29
30     @Before
31     public void setUp() {
32         factory = new ShardStrategyFactory(new ConfigurationImpl("module-shards.conf", "modules.conf"));
33     }
34
35     @Test
36     public void testGetStrategy() {
37         ShardStrategy strategy = factory.getStrategy(TestModel.TEST_PATH);
38         assertNotNull(strategy);
39     }
40
41     @Test
42     public void testGetStrategyForKnownModuleName() {
43         ShardStrategy strategy = factory.getStrategy(YangInstanceIdentifier.of(CarsModel.BASE_QNAME));
44         assertTrue(strategy instanceof ModuleShardStrategy);
45     }
46
47
48     @Test
49     public void testGetStrategyNullPointerExceptionWhenPathIsNull() {
50         expectedEx.expect(NullPointerException.class);
51         expectedEx.expectMessage("path should not be null");
52
53         factory.getStrategy(null);
54     }
55 }