Merge "Remove redundant exception declarations"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / singlelayer / SingleLayerExperimenterMultipartServiceTest.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.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;
26
27 public class SingleLayerExperimenterMultipartServiceTest extends ServiceMocking {
28     private SingleLayerExperimenterMultipartService service;
29
30     @Override
31     protected void setup() {
32         service = new SingleLayerExperimenterMultipartService(
33                 mockedRequestContextStack, mockedDeviceContext,
34                 mockedExtensionConverterProvider);
35     }
36
37     @Test
38     public void buildRequest() {
39         final SendExperimenterMpRequestInput input = new SendExperimenterMpRequestInputBuilder()
40                 .setExperimenterMessageOfChoice(mockExperimenter())
41                 .build();
42
43         final OfHeader ofHeader = service.buildRequest(DUMMY_XID, input);
44         assertEquals(MultipartRequest.class, ofHeader.getImplementedInterface());
45
46         final MultipartRequestExperimenter result = (MultipartRequestExperimenter) ((MultipartRequest) ofHeader)
47             .getMultipartRequestBody();
48
49         assertEquals(DummyExperimenter.class, result.getExperimenterMessageOfChoice().getImplementedInterface());
50     }
51
52     @Test
53     public void handleAndReply() throws Exception {
54         mockSuccessfulFuture(Collections.singletonList(new MultipartReplyBuilder()
55                 .setMultipartReplyBody(new MultipartReplyExperimenterBuilder()
56                         .setExperimenterMessageOfChoice(mockExperimenter())
57                         .build())
58                 .build()));
59
60         final SendExperimenterMpRequestInput input = new SendExperimenterMpRequestInputBuilder()
61                 .setExperimenterMessageOfChoice(mockExperimenter())
62                 .build();
63
64         final Future<RpcResult<SendExperimenterMpRequestOutput>> rpcResultFuture = service
65                 .handleAndReply(input);
66
67         final RpcResult<SendExperimenterMpRequestOutput> sendExperimenterMpRequestOutputRpcResult =
68                 rpcResultFuture.get();
69
70         assertEquals(DummyExperimenter.class, sendExperimenterMpRequestOutputRpcResult
71                 .getResult()
72                 .getExperimenterCoreMessageItem()
73                 .get(0)
74                 .getExperimenterMessageOfChoice().getImplementedInterface());
75     }
76 }