dc3b6dccc4b428ff0118a50739d985c83dc36f5b
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / role / RoleContextImplTest.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.openflowplugin.impl.role;
9
10
11 import io.netty.util.HashedWheelTimer;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.mockito.Mock;
17 import org.mockito.Mockito;
18 import org.mockito.runners.MockitoJUnitRunner;
19 import org.opendaylight.controller.md.sal.common.api.clustering.CandidateAlreadyRegisteredException;
20 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
21 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
22 import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
23 import org.opendaylight.openflowplugin.api.openflow.role.RoleManager;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 @RunWith(MockitoJUnitRunner.class)
29 public class RoleContextImplTest {
30
31     private static final Logger LOG = LoggerFactory.getLogger(RoleContextImpl.class);
32
33     @Mock
34     HashedWheelTimer hashedWheelTimer;
35     @Mock
36     private DeviceInfo deviceInfo;
37     @Mock
38     private RoleManager roleManager;
39     @Mock
40     private LifecycleService lifecycleService;
41
42     private final NodeId nodeId = NodeId.getDefaultInstance("openflow:1");
43     private RoleContext roleContext;
44
45     @Before
46     public void setup() throws CandidateAlreadyRegisteredException {
47         roleContext = new RoleContextImpl(deviceInfo, hashedWheelTimer, roleManager);
48         Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
49     }
50
51     @Test
52     public void testCreateRequestContext() throws Exception {
53         roleContext.createRequestContext();
54         Mockito.verify(deviceInfo).reserveXidForDeviceMessage();
55     }
56
57     @Test(expected = NullPointerException.class)
58     public void testSetSalRoleService() throws Exception {
59         roleContext.setSalRoleService(null);
60     }
61
62     @Test
63     public void testGetNodeId() throws Exception {
64         Assert.assertTrue(roleContext.getDeviceInfo().getNodeId().equals(nodeId));
65     }
66 }