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;
13 import java.util.Collections;
14 import java.util.concurrent.Future;
15 import org.junit.Test;
16 import org.opendaylight.openflowplugin.impl.services.ServiceMocking;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SendExperimenterMpRequestInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SendExperimenterMpRequestInputBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SendExperimenterMpRequestOutput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReplyBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartRequest;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.multipart.reply.multipart.reply.body.MultipartReplyExperimenterBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.multipart.request.multipart.request.body.MultipartRequestExperimenter;
25 import org.opendaylight.yangtools.yang.common.RpcResult;
27 public class SingleLayerExperimenterMultipartServiceTest extends ServiceMocking {
28 private SingleLayerExperimenterMultipartService service;
31 protected void setup() {
32 service = new SingleLayerExperimenterMultipartService(
33 mockedRequestContextStack, mockedDeviceContext,
34 mockedExtensionConverterProvider);
38 public void buildRequest() {
39 final SendExperimenterMpRequestInput input = new SendExperimenterMpRequestInputBuilder()
40 .setExperimenterMessageOfChoice(mockExperimenter())
43 final OfHeader ofHeader = service.buildRequest(DUMMY_XID, input);
44 assertEquals(MultipartRequest.class, ofHeader.getImplementedInterface());
46 final MultipartRequestExperimenter result = (MultipartRequestExperimenter) ((MultipartRequest) ofHeader)
47 .getMultipartRequestBody();
49 assertEquals(DummyExperimenter.class, result.getExperimenterMessageOfChoice().getImplementedInterface());
53 public void handleAndReply() throws Exception {
54 mockSuccessfulFuture(Collections.singletonList(new MultipartReplyBuilder()
55 .setMultipartReplyBody(new MultipartReplyExperimenterBuilder()
56 .setExperimenterMessageOfChoice(mockExperimenter())
60 final SendExperimenterMpRequestInput input = new SendExperimenterMpRequestInputBuilder()
61 .setExperimenterMessageOfChoice(mockExperimenter())
64 final Future<RpcResult<SendExperimenterMpRequestOutput>> rpcResultFuture = service
65 .handleAndReply(input);
67 final RpcResult<SendExperimenterMpRequestOutput> sendExperimenterMpRequestOutputRpcResult =
68 rpcResultFuture.get();
70 assertEquals(DummyExperimenter.class, sendExperimenterMpRequestOutputRpcResult
72 .getExperimenterCoreMessageItem()
74 .getExperimenterMessageOfChoice().getImplementedInterface());