e86b377cb6cdfafa5cbfc2d7dc00da197a4f9f9c
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / DefaultConfigParamsImplTest.java
1 /*
2  * Copyright (c) 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 package org.opendaylight.controller.cluster.raft;
9
10 import static org.junit.Assert.assertEquals;
11 import org.junit.Test;
12 import org.opendaylight.controller.cluster.raft.policy.DefaultRaftPolicy;
13 import org.opendaylight.controller.cluster.raft.policy.RaftPolicy;
14 import org.opendaylight.controller.cluster.raft.policy.TestRaftPolicy;
15
16 public class DefaultConfigParamsImplTest {
17
18     @Test
19     public void testGetRaftPolicyWithDefault(){
20         DefaultConfigParamsImpl params = new DefaultConfigParamsImpl();
21
22         assertEquals("Default instance", DefaultRaftPolicy.INSTANCE, params.getRaftPolicy());
23     }
24
25     @Test
26     public void testGetRaftPolicyInvalidClassName(){
27         DefaultConfigParamsImpl params = new DefaultConfigParamsImpl();
28         params.setCustomRaftPolicyImplementationClass("foobar");
29
30         assertEquals("Default instance", DefaultRaftPolicy.INSTANCE, params.getRaftPolicy());
31     }
32
33     @Test
34     public void testGetRaftPolicyValidClassNameButInvalidType(){
35         DefaultConfigParamsImpl params = new DefaultConfigParamsImpl();
36         params.setCustomRaftPolicyImplementationClass("java.lang.String");
37
38         assertEquals("Default instance", DefaultRaftPolicy.INSTANCE, params.getRaftPolicy());
39     }
40
41     @Test
42     public void testGetRaftPolicyValidClass(){
43         DefaultConfigParamsImpl params1 = new DefaultConfigParamsImpl();
44         params1.setCustomRaftPolicyImplementationClass("org.opendaylight.controller.cluster.raft.policy.TestRaftPolicy");
45         RaftPolicy behavior1 = params1.getRaftPolicy();
46
47         assertEquals("TestCustomBehavior", TestRaftPolicy.class, behavior1.getClass());
48         assertEquals("Same instance returned", behavior1, params1.getRaftPolicy());
49
50         DefaultConfigParamsImpl params2 = new DefaultConfigParamsImpl();
51         RaftPolicy behavior2 = params2.getRaftPolicy();
52         params1.setCustomRaftPolicyImplementationClass("org.opendaylight.controller.cluster.raft.policy.TestRaftPolicy");
53
54         assertEquals("Default instance", DefaultRaftPolicy.INSTANCE, behavior2);
55         assertEquals("Default instance", DefaultRaftPolicy.INSTANCE, params2.getRaftPolicy());
56
57     }
58
59
60 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.