Merge "Sonar issues"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / statistics / services / dedicated / StatisticsGatheringOnTheFlyServiceTest.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
9 package org.opendaylight.openflowplugin.impl.statistics.services.dedicated;
10
11 import org.junit.Assert;
12 import org.junit.Test;
13 import org.mockito.Mockito;
14 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
15 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier;
16 import org.opendaylight.openflowplugin.impl.services.ServiceMocking;
17 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
18 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
23
24 /**
25  * Test for {@link StatisticsGatheringOnTheFlyService}.
26  */
27 public class StatisticsGatheringOnTheFlyServiceTest extends ServiceMocking {
28
29     public static final NodeId NODE_ID = new NodeId(DUMMY_NODE_ID);
30     private StatisticsGatheringOnTheFlyService statisticsGatheringService;
31
32     @Override
33     protected void setup() {
34         final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
35         statisticsGatheringService = new StatisticsGatheringOnTheFlyService(mockedRequestContextStack, mockedDeviceContext, convertorManager);
36         Mockito.doReturn(NODE_ID).when(mockedPrimConnectionContext).getNodeId();
37         Mockito.when(mockedDeviceInfo.getNodeId()).thenReturn(NODE_ID);
38         Mockito.when(mockedDeviceContext.getDeviceInfo().getNodeId()).thenReturn(NODE_ID);
39     }
40
41     @Test
42     public void testGetStatisticsOfType() throws Exception {
43         final EventIdentifier eventIdentifier = new EventIdentifier("ut-event", "ut-device-id:1");
44         statisticsGatheringService.getStatisticsOfType(eventIdentifier, MultipartType.OFPMPFLOW);
45         Mockito.verify(mockedRequestContextStack).createRequestContext();
46     }
47
48     @Test
49     public void testBuildRequest() throws Exception {
50         final long xidValue = 21L;
51         Xid xid = new Xid(xidValue);
52         final OfHeader request = statisticsGatheringService.buildRequest(xid, MultipartType.OFPMPFLOW);
53         Assert.assertEquals(MultipartRequestInput.class, request.getImplementedInterface());
54         Assert.assertEquals(xidValue, request.getXid().longValue());
55         Assert.assertNotNull(request);
56     }
57 }