2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.impl.role;
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;
28 @RunWith(MockitoJUnitRunner.class)
29 public class RoleContextImplTest {
31 private static final Logger LOG = LoggerFactory.getLogger(RoleContextImpl.class);
34 HashedWheelTimer hashedWheelTimer;
36 private DeviceInfo deviceInfo;
38 private RoleManager roleManager;
40 private LifecycleService lifecycleService;
42 private final NodeId nodeId = NodeId.getDefaultInstance("openflow:1");
43 private RoleContext roleContext;
46 public void setup() throws CandidateAlreadyRegisteredException {
47 roleContext = new RoleContextImpl(deviceInfo, hashedWheelTimer, roleManager);
48 Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
52 public void testCreateRequestContext() throws Exception {
53 roleContext.createRequestContext();
54 Mockito.verify(deviceInfo).reserveXidForDeviceMessage();
57 @Test(expected = NullPointerException.class)
58 public void testSetSalRoleService() throws Exception {
59 roleContext.setSalRoleService(null);
63 public void testGetNodeId() throws Exception {
64 Assert.assertTrue(roleContext.getDeviceInfo().getNodeId().equals(nodeId));