2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.statistics.services.direct.singlelayer;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.ArgumentMatchers.eq;
14 import static org.mockito.Mockito.lenient;
15 import static org.mockito.Mockito.mock;
16 import static org.mockito.Mockito.verify;
17 import static org.mockito.Mockito.when;
19 import java.util.Collections;
20 import java.util.List;
21 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
22 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
23 import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractDirectStatisticsServiceTest;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatisticsInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatisticsOutput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReplyBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartRequest;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.multipart.reply.multipart.reply.body.MultipartReplyPortStatsBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.multipart.request.multipart.request.body.MultipartRequestPortStats;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMapBuilder;
35 public class NodeConnectorDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest {
36 private PortDirectStatisticsService service;
39 public void setUp() throws Exception {
40 service = new PortDirectStatisticsService(requestContextStack,
43 multipartWriterProvider);
47 public void testBuildRequestBody() throws Exception {
48 final GetNodeConnectorStatisticsInput input = mock(GetNodeConnectorStatisticsInput.class);
50 lenient().when(input.getNode()).thenReturn(createNodeRef(NODE_ID));
51 when(input.getNodeConnectorId()).thenReturn(nodeConnectorId);
53 final MultipartRequestPortStats body = (MultipartRequestPortStats) ((MultipartRequest)service
54 .buildRequest(new Xid(42L), input))
55 .getMultipartRequestBody();
57 assertEquals(nodeConnectorId, body.getNodeConnectorId());
61 public void testBuildReply() throws Exception {
62 final NodeConnectorStatisticsAndPortNumberMap portStat = new NodeConnectorStatisticsAndPortNumberMapBuilder()
63 .setNodeConnectorId(nodeConnectorId)
66 final MultipartReply reply = new MultipartReplyBuilder()
67 .setMultipartReplyBody(new MultipartReplyPortStatsBuilder()
68 .setNodeConnectorStatisticsAndPortNumberMap(Collections.singletonList(portStat))
72 final List<MultipartReply> input = Collections.singletonList(reply);
73 final GetNodeConnectorStatisticsOutput output = service.buildReply(input, true);
74 assertTrue(output.getNodeConnectorStatisticsAndPortNumberMap().size() > 0);
76 final NodeConnectorStatisticsAndPortNumberMap stats =
77 output.getNodeConnectorStatisticsAndPortNumberMap().get(0);
79 assertEquals(stats.getNodeConnectorId(), nodeConnectorId);
83 public void testStoreStatistics() throws Exception {
84 final NodeConnectorStatisticsAndPortNumberMap stat = mock(NodeConnectorStatisticsAndPortNumberMap.class);
85 when(stat.getNodeConnectorId()).thenReturn(nodeConnectorId);
87 final List<NodeConnectorStatisticsAndPortNumberMap> stats = Collections.singletonList(stat);
88 final GetNodeConnectorStatisticsOutput output = mock(GetNodeConnectorStatisticsOutput.class);
89 when(output.getNodeConnectorStatisticsAndPortNumberMap()).thenReturn(stats);
91 multipartWriterProvider.lookup(MultipartType.OFPMPPORTSTATS).get().write(output, true);
92 verify(deviceContext).writeToTransactionWithParentsSlow(eq(LogicalDatastoreType.OPERATIONAL), any(), any());