3e453b7bad52c3b33f567265107e36f5842b2158
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / EchoServiceTest.java
1 package org.opendaylight.openflowplugin.impl.services;
2
3 import static org.junit.Assert.assertArrayEquals;
4 import static org.junit.Assert.assertEquals;
5 import static org.junit.Assert.assertTrue;
6 import static org.mockito.Mockito.verify;
7
8 import org.junit.Test;
9 import org.opendaylight.openflowplugin.api.OFConstants;
10 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
14
15 public class EchoServiceTest extends ServiceMocking {
16
17     private static final Long DUMMY_XID_VALUE = 100L;
18     private static final byte[] DUMMY_DATA = "DUMMY DATA".getBytes();
19     EchoService echoService;
20
21     @Override
22     public void setup() {
23         echoService = new EchoService(mockedRequestContextStack, mockedDeviceContext);
24     }
25
26     @Test
27     public void testSendEcho() throws Exception {
28         EchoInputBuilder sendEchoInput = new EchoInputBuilder();
29         echoService.handleServiceCall(sendEchoInput);
30         verify(mockedRequestContextStack).createRequestContext();
31     }
32
33     @Test
34     public void testBuildRequest() throws Exception {
35         EchoInputBuilder sendEchoInput = new EchoInputBuilder().setData(DUMMY_DATA);
36         final OfHeader request = this.echoService.buildRequest(new Xid(DUMMY_XID_VALUE), sendEchoInput);
37         assertEquals(DUMMY_XID_VALUE, request.getXid());
38         assertTrue(request instanceof EchoInput);
39         final byte[] data = ((EchoInput) request).getData();
40         assertArrayEquals(DUMMY_DATA, data);
41         assertEquals(OFConstants.OFP_VERSION_1_3, request.getVersion().shortValue());
42     }
43 }