e07b772c2c2e8466e4a2f947db43f5d7be846f73
[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.BeforeClass;
14 import org.junit.Rule;
15 import org.junit.Test;
16 import org.junit.rules.ExpectedException;
17 import org.opendaylight.controller.cluster.datastore.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     @Rule
25     public ExpectedException expectedEx = ExpectedException.none();
26
27     @BeforeClass
28     public static void setUpClass(){
29         ShardStrategyFactory.setConfiguration(new ConfigurationImpl("module-shards.conf", "modules.conf"));
30     }
31
32     @Test
33     public void testGetStrategy() {
34         ShardStrategy strategy =
35             ShardStrategyFactory.getStrategy(TestModel.TEST_PATH);
36         assertNotNull(strategy);
37     }
38
39     @Test
40     public void testGetStrategyForKnownModuleName() {
41         ShardStrategy strategy =
42             ShardStrategyFactory.getStrategy(
43                 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         ShardStrategyFactory.getStrategy(null);
54     }
55
56 }