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
9 package org.opendaylight.openflowplugin.impl.services.singlelayer;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
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;
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;
37 protected void setup() {
38 service = new SingleLayerTableMultipartService(mockedRequestContextStack, mockedDeviceContext,
39 MultipartWriterProviderFactory.createDefaultProvider(mockedDeviceContext));
43 public void buildRequest() {
44 final UpdateTableInput input = new UpdateTableInputBuilder()
45 .setUpdatedTable(new UpdatedTableBuilder()
46 .setTableFeatures(Collections.singletonList(new TableFeaturesBuilder()
47 .setMaxEntries(MAX_ENTRIES)
52 final OfHeader ofHeader = service.buildRequest(DUMMY_XID, input);
53 assertEquals(MultipartRequest.class, ofHeader.implementedInterface());
55 final MultipartRequestTableFeatures result = (MultipartRequestTableFeatures) ((MultipartRequest) ofHeader)
56 .getMultipartRequestBody();
58 assertEquals(MAX_ENTRIES, result.getTableFeatures().get(0).getMaxEntries().longValue());
62 public void handleAndReply() throws Exception {
63 mockSuccessfulFuture(Collections.singletonList(new MultipartReplyBuilder()
65 .setMultipartReplyBody(new MultipartReplyTableFeaturesBuilder()
66 .setTableFeatures(Collections.singletonList(new TableFeaturesBuilder()
67 .setMaxEntries(MAX_ENTRIES)
72 final UpdateTableInput input = new UpdateTableInputBuilder()
73 .setUpdatedTable(new UpdatedTableBuilder()
74 .setTableFeatures(Collections.singletonList(new TableFeaturesBuilder()
75 .setMaxEntries(MAX_ENTRIES)
80 final Future<RpcResult<UpdateTableOutput>> rpcResultFuture = service
81 .handleAndReply(input);
83 final RpcResult<UpdateTableOutput> result =
84 rpcResultFuture.get();
86 assertTrue(result.isSuccessful());
87 assertEquals(XID, result.getResult().getTransactionId().getValue().longValue());