Merge "BUG-4068: RpcContextImpl doesn't close rpcRegistrations correctly"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / SalEchoServiceImplTest.java
1 package org.opendaylight.openflowplugin.impl.services;
2
3 import org.junit.Test;
4 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
5 import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoInput;
6 import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoInputBuilder;
7 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput;
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
10
11 import static org.junit.Assert.*;
12 import static org.mockito.Mockito.verify;
13
14 public class SalEchoServiceImplTest extends ServiceMocking {
15
16     private static final Long DUMMY_XID_VALUE = 100L;
17     private static final byte[] DUMMY_DATA = "DUMMY DATA".getBytes();
18     SalEchoServiceImpl salEchoService;
19
20     @Test
21     public void testSendEcho() throws Exception {
22         salEchoService = new SalEchoServiceImpl(mockedRequestContextStack, mockedDeviceContext);
23         SendEchoInput sendEchoInput = new SendEchoInputBuilder().build();
24         salEchoService.sendEcho(sendEchoInput);
25         verify(mockedRequestContextStack).createRequestContext();;
26     }
27
28     @Test
29     public void testBuildRequest() throws Exception {
30         salEchoService = new SalEchoServiceImpl(mockedRequestContextStack, mockedDeviceContext);
31         SendEchoInput sendEchoInput = new SendEchoInputBuilder().setData(DUMMY_DATA).build();
32         final OfHeader request = this.salEchoService.buildRequest(new Xid(DUMMY_XID_VALUE), sendEchoInput);
33         assertEquals(DUMMY_XID_VALUE, request.getXid());
34         assertTrue(request instanceof EchoInput);
35         final byte[] data = ((EchoInput) request).getData();
36         assertArrayEquals(DUMMY_DATA, data);
37     }
38 }