Update MRI projects for Aluminium
[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() {
38         service = new SingleLayerTableMultipartService(mockedRequestContextStack, mockedDeviceContext,
39                 MultipartWriterProviderFactory.createDefaultProvider(mockedDeviceContext));
40     }
41
42     @Test
43     public void buildRequest() {
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.implementedInterface());
54
55         final MultipartRequestTableFeatures result = (MultipartRequestTableFeatures) ((MultipartRequest) ofHeader)
56             .getMultipartRequestBody();
57
58         assertEquals(MAX_ENTRIES, result.nonnullTableFeatures().values().iterator().next().getMaxEntries().longValue());
59     }
60
61     @Test
62     public void handleAndReply() throws Exception {
63         mockSuccessfulFuture(Collections.singletonList(new MultipartReplyBuilder()
64                 .setXid(XID)
65                 .setMultipartReplyBody(new MultipartReplyTableFeaturesBuilder()
66                         .setTableFeatures(Collections.singletonList(new TableFeaturesBuilder()
67                                 .setMaxEntries(MAX_ENTRIES)
68                                 .build()))
69                         .build())
70                 .build()));
71
72         final UpdateTableInput input = new UpdateTableInputBuilder()
73                 .setUpdatedTable(new UpdatedTableBuilder()
74                         .setTableFeatures(Collections.singletonList(new TableFeaturesBuilder()
75                                 .setMaxEntries(MAX_ENTRIES)
76                                 .build()))
77                         .build())
78                 .build();
79
80         final Future<RpcResult<UpdateTableOutput>> rpcResultFuture = service
81                 .handleAndReply(input);
82
83         final RpcResult<UpdateTableOutput> result =
84                 rpcResultFuture.get();
85
86         assertTrue(result.isSuccessful());
87         assertEquals(XID, result.getResult().getTransactionId().getValue().longValue());
88     }
89 }