Merge "Failed to cancel service reconciliation, When controller become slave."
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / statistics / services / PortStatsServiceTest.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;
10
11 import java.util.concurrent.atomic.AtomicLong;
12 import org.junit.Assert;
13 import org.junit.Test;
14 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsInputBuilder;
20 import org.opendaylight.yangtools.yang.common.Uint32;
21
22 /**
23  * Test of {@link PortStatsService}.
24  */
25 public class PortStatsServiceTest extends AbstractStatsServiceTest {
26
27     private PortStatsService portStatsService;
28
29     @Override
30     public void setUp() {
31         portStatsService = new PortStatsService(rqContextStack, deviceContext,
32                 new AtomicLong());
33     }
34
35     @Test
36     public void testBuildRequest() {
37         Xid xid = new Xid(Uint32.valueOf(42L));
38         GetNodeConnectorStatisticsInputBuilder input = new GetNodeConnectorStatisticsInputBuilder()
39                 .setNodeConnectorId(new NodeConnectorId("junitProto:11:12"))
40                 .setNode(createNodeRef("junitProto:11"));
41
42         final OfHeader request = portStatsService.buildRequest(xid, input.build());
43
44         Assert.assertTrue(request instanceof MultipartRequestInput);
45         final MultipartRequestInput mpRequest = (MultipartRequestInput) request;
46         Assert.assertTrue(mpRequest.getMultipartRequestBody() instanceof MultipartRequestPortStatsCase);
47         final MultipartRequestPortStatsCase mpRequestBody =
48                 (MultipartRequestPortStatsCase) mpRequest.getMultipartRequestBody();
49         Assert.assertEquals(12L, mpRequestBody.getMultipartRequestPortStats().getPortNo().longValue());
50
51     }
52 }