Fix opendaylight-flow-types.yang cases
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / singlelayer / SingleLayerAggregateFlowMultipartServiceTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.services.singlelayer;
10
11 import static org.junit.Assert.assertEquals;
12
13 import java.math.BigInteger;
14 import java.util.Collections;
15 import java.util.concurrent.Future;
16 import org.junit.Test;
17 import org.opendaylight.openflowplugin.impl.services.ServiceMocking;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInputBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowAggregateStatsBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.multipart.request.multipart.request.body.MultipartRequestFlowAggregateStats;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReplyBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartRequest;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
27 import org.opendaylight.yangtools.yang.common.RpcResult;
28
29 public class SingleLayerAggregateFlowMultipartServiceTest extends ServiceMocking {
30     private static final short TABLE_ID = 42;
31     private static final BigInteger BYTE_COUNT = BigInteger.TEN;
32     private SingleLayerAggregateFlowMultipartService service;
33
34     @Override
35     protected void setup() throws Exception {
36         service = new SingleLayerAggregateFlowMultipartService(mockedRequestContextStack, mockedDeviceContext);
37     }
38
39     @Test
40     public void buildRequest() throws Exception {
41         final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input = new
42                 GetAggregateFlowStatisticsFromFlowTableForGivenMatchInputBuilder()
43                 .setTableId(TABLE_ID)
44                 .build();
45
46         final OfHeader ofHeader = service.buildRequest(DUMMY_XID, input);
47         assertEquals(MultipartRequest.class, ofHeader.getImplementedInterface());
48
49         final MultipartRequestFlowAggregateStats result = MultipartRequestFlowAggregateStats.class.cast(
50                 MultipartRequest.class.cast(ofHeader)
51                         .getMultipartRequestBody());
52
53         assertEquals(TABLE_ID, result.getFlowAggregateStats().getTableId().shortValue());
54     }
55
56     @Test
57     public void handleAndReply() throws Exception {
58         mockSuccessfulFuture(Collections.singletonList(new MultipartReplyBuilder()
59                 .setMultipartReplyBody(new MultipartReplyFlowAggregateStatsBuilder()
60                         .setByteCount(new Counter64(BYTE_COUNT))
61                         .build())
62                 .build()));
63
64         final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input = new
65                 GetAggregateFlowStatisticsFromFlowTableForGivenMatchInputBuilder()
66                 .setTableId(TABLE_ID)
67                 .build();
68
69         final Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> rpcResultFuture = service
70                 .handleAndReply(input);
71
72         final RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>
73                 sendAggregateFlowMpRequestOutputRpcResult = rpcResultFuture.get();
74
75         assertEquals(BYTE_COUNT, sendAggregateFlowMpRequestOutputRpcResult
76                 .getResult()
77                 .getAggregatedFlowStatistics()
78                 .get(0)
79                 .getByteCount().getValue());
80     }
81 }