Bug 5596 Cleaning part 3
[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
22 public class EchoServiceTest extends ServiceMocking {
23
24     private static final Long DUMMY_XID_VALUE = 100L;
25     private static final byte[] DUMMY_DATA = "DUMMY DATA".getBytes();
26     EchoService echoService;
27
28     @Override
29     public void setup() {
30         echoService = new EchoService(mockedRequestContextStack, mockedDeviceContext);
31     }
32
33     @Test
34     public void testSendEcho() throws Exception {
35         EchoInputBuilder sendEchoInput = new EchoInputBuilder();
36         echoService.handleServiceCall(sendEchoInput);
37         verify(mockedRequestContextStack).createRequestContext();
38     }
39
40     @Test
41     public void testBuildRequest() throws Exception {
42         EchoInputBuilder sendEchoInput = new EchoInputBuilder().setData(DUMMY_DATA);
43         final OfHeader request = this.echoService.buildRequest(new Xid(DUMMY_XID_VALUE), sendEchoInput);
44         assertEquals(DUMMY_XID_VALUE, request.getXid());
45         assertTrue(request instanceof EchoInput);
46         final byte[] data = ((EchoInput) request).getData();
47         assertArrayEquals(DUMMY_DATA, data);
48         assertEquals(OFConstants.OFP_VERSION_1_3, request.getVersion().shortValue());
49     }
50 }