OPNFLWPLUG-1032: Neon-MRI: Bump odlparent, yangtools, mdsal
[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.datastore.MultipartWriterProviderFactory;
17 import org.opendaylight.openflowplugin.impl.services.ServiceMocking;
18 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
19 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
25
26 /**
27  * Test for {@link StatisticsGatheringOnTheFlyService}.
28  */
29 public class StatisticsGatheringOnTheFlyServiceTest extends ServiceMocking {
30
31     public static final NodeId NODE_ID = new NodeId(DUMMY_NODE_ID);
32     private StatisticsGatheringOnTheFlyService<MultipartReply> statisticsGatheringService;
33
34     @Override
35     protected void setup() {
36         final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
37         statisticsGatheringService =
38                 new StatisticsGatheringOnTheFlyService<>(mockedRequestContextStack,
39                                                          mockedDeviceContext,
40                                                          convertorManager,
41                                                          MultipartWriterProviderFactory
42                                                                  .createDefaultProvider(mockedDeviceContext));
43         Mockito.when(mockedDeviceInfo.getNodeId()).thenReturn(NODE_ID);
44         Mockito.when(mockedDeviceContext.getDeviceInfo().getNodeId()).thenReturn(NODE_ID);
45     }
46
47     @Test
48     public void testGetStatisticsOfType() throws Exception {
49         final EventIdentifier eventIdentifier = new EventIdentifier("ut-event", "ut-device-id:1");
50         statisticsGatheringService.getStatisticsOfType(eventIdentifier, MultipartType.OFPMPFLOW);
51         Mockito.verify(mockedRequestContextStack).createRequestContext();
52     }
53
54     @Test
55     public void testBuildRequest() throws Exception {
56         final long xidValue = 21L;
57         Xid xid = new Xid(xidValue);
58         final OfHeader request = statisticsGatheringService.buildRequest(xid, MultipartType.OFPMPFLOW);
59         Assert.assertEquals(MultipartRequestInput.class, request.getImplementedInterface());
60         Assert.assertEquals(xidValue, request.getXid().longValue());
61         Assert.assertNotNull(request);
62     }
63 }