Merge "OPNFLWPLUG-1076 Migrate lldp-speaker, forwardingrules-sync and arbitratorrecon...
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / EchoServiceTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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 package org.opendaylight.openflowplugin.impl.services;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13 import static org.mockito.Mockito.verify;
14
15 import org.junit.Test;
16 import org.opendaylight.openflowplugin.api.OFConstants;
17 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
21 import org.opendaylight.yangtools.yang.common.Uint32;
22
23 public class EchoServiceTest extends ServiceMocking {
24
25     private static final Uint32 DUMMY_XID_VALUE = Uint32.valueOf(100);
26     private static final byte[] DUMMY_DATA = "DUMMY DATA".getBytes();
27     EchoService echoService;
28
29     @Override
30     public void setup() {
31         echoService = new EchoService(mockedRequestContextStack, mockedDeviceContext);
32     }
33
34     @Test
35     public void testSendEcho() {
36         EchoInputBuilder sendEchoInput = new EchoInputBuilder();
37         echoService.handleServiceCall(sendEchoInput);
38         verify(mockedRequestContextStack).createRequestContext();
39     }
40
41     @Test
42     public void testBuildRequest() {
43         EchoInputBuilder sendEchoInput = new EchoInputBuilder().setData(DUMMY_DATA);
44         final OfHeader request = this.echoService.buildRequest(new Xid(DUMMY_XID_VALUE), sendEchoInput);
45         assertEquals(DUMMY_XID_VALUE, request.getXid());
46         assertTrue(request instanceof EchoInput);
47         final byte[] data = ((EchoInput) request).getData();
48         assertArrayEquals(DUMMY_DATA, data);
49         assertEquals(OFConstants.OFP_VERSION_1_3, request.getVersion().shortValue());
50     }
51 }