2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.impl.services;
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;
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;
22 public class EchoServiceTest extends ServiceMocking {
24 private static final Long DUMMY_XID_VALUE = 100L;
25 private static final byte[] DUMMY_DATA = "DUMMY DATA".getBytes();
26 EchoService echoService;
30 echoService = new EchoService(mockedRequestContextStack, mockedDeviceContext);
34 public void testSendEcho() throws Exception {
35 EchoInputBuilder sendEchoInput = new EchoInputBuilder();
36 echoService.handleServiceCall(sendEchoInput);
37 verify(mockedRequestContextStack).createRequestContext();
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());