Rework bit-copying functions and re-enable tests
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / singlelayer / SingleLayerTableMultipartServiceTest.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 import static org.junit.Assert.assertTrue;
13
14 import java.util.Collections;
15 import java.util.concurrent.Future;
16 import org.junit.Test;
17 import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProviderFactory;
18 import org.opendaylight.openflowplugin.impl.services.ServiceMocking;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReplyBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartRequest;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInputBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.multipart.reply.multipart.reply.body.MultipartReplyTableFeaturesBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.multipart.request.multipart.request.body.MultipartRequestTableFeatures;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder;
29 import org.opendaylight.yangtools.yang.common.RpcResult;
30
31 public class SingleLayerTableMultipartServiceTest extends ServiceMocking {
32     private static final long MAX_ENTRIES = 42;
33     private static final long XID = 43;
34     private SingleLayerTableMultipartService service;
35
36     @Override
37     protected void setup() throws Exception {
38         service = new SingleLayerTableMultipartService(mockedRequestContextStack, mockedDeviceContext,
39                 MultipartWriterProviderFactory.createDefaultProvider(mockedDeviceContext));
40     }
41
42     @Test
43     public void buildRequest() throws Exception {
44         final UpdateTableInput input = new UpdateTableInputBuilder()
45                 .setUpdatedTable(new UpdatedTableBuilder()
46                         .setTableFeatures(Collections.singletonList(new TableFeaturesBuilder()
47                                 .setMaxEntries(MAX_ENTRIES)
48                                 .build()))
49                         .build())
50                 .build();
51
52         final OfHeader ofHeader = service.buildRequest(DUMMY_XID, input);
53         assertEquals(MultipartRequest.class, ofHeader.getImplementedInterface());
54
55         final MultipartRequestTableFeatures result = MultipartRequestTableFeatures.class.cast(
56                 MultipartRequest.class.cast(ofHeader)
57                         .getMultipartRequestBody());
58
59         assertEquals(MAX_ENTRIES, result.getTableFeatures().get(0).getMaxEntries().longValue());
60     }
61
62     @Test
63     public void handleAndReply() throws Exception {
64         mockSuccessfulFuture(Collections.singletonList(new MultipartReplyBuilder()
65                 .setXid(XID)
66                 .setMultipartReplyBody(new MultipartReplyTableFeaturesBuilder()
67                         .setTableFeatures(Collections.singletonList(new TableFeaturesBuilder()
68                                 .setMaxEntries(MAX_ENTRIES)
69                                 .build()))
70                         .build())
71                 .build()));
72
73         final UpdateTableInput input = new UpdateTableInputBuilder()
74                 .setUpdatedTable(new UpdatedTableBuilder()
75                         .setTableFeatures(Collections.singletonList(new TableFeaturesBuilder()
76                                 .setMaxEntries(MAX_ENTRIES)
77                                 .build()))
78                         .build())
79                 .build();
80
81         final Future<RpcResult<UpdateTableOutput>> rpcResultFuture = service
82                 .handleAndReply(input);
83
84         final RpcResult<UpdateTableOutput> result =
85                 rpcResultFuture.get();
86
87         assertTrue(result.isSuccessful());
88         assertEquals(XID, result.getResult().getTransactionId().getValue().longValue());
89     }
90 }