2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.sal;
10 import static org.mockito.Mockito.verify;
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
14 import org.mockito.junit.MockitoJUnitRunner;
15 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
16 import org.opendaylight.openflowplugin.impl.services.ServiceMocking;
17 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
18 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.Port;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.PortBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInputBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.port.update.UpdatedPort;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.port.update.UpdatedPortBuilder;
30 import org.opendaylight.yangtools.yang.binding.util.BindingMap;
31 import org.opendaylight.yangtools.yang.common.Uint32;
33 @RunWith(MockitoJUnitRunner.class)
34 public class SalPortServiceImplTest extends ServiceMocking {
36 private static final Uint32 DUMMY_XID = Uint32.valueOf(55L);
37 private static final Uint32 DUMMY_PORT_NUMBER = Uint32.valueOf(66L);
38 private static final String DUMMY_MAC_ADDRESS = "AA:BB:CC:DD:EE:FF";
39 SalPortServiceImpl salPortService;
42 protected void setup() {
43 final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
44 salPortService = new SalPortServiceImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager);
48 public void testUpdatePort() {
49 salPortService.updatePort(dummyUpdatePortInput());
50 verify(mockedRequestContextStack).createRequestContext();
54 public void testBuildRequest() {
55 final OfHeader ofHeader = salPortService.buildRequest(new Xid(DUMMY_XID), dummyUpdatePortInput());
58 private static UpdatePortInput dummyUpdatePortInput() {
59 org.opendaylight.yang.gen.v1.urn
60 .opendaylight.flow.types.port.rev130925.port.mod.port.PortBuilder concretePortBuilder
61 = new org.opendaylight.yang.gen.v1.urn
62 .opendaylight.flow.types.port.rev130925.port.mod.port.PortBuilder();
63 concretePortBuilder.setConfiguration(new PortConfig(true, true, true, true));
64 concretePortBuilder.setAdvertisedFeatures(new PortFeatures(true, true, true, true, true, true, true, true,
65 true, true, true, true, true, true, true, true));
66 concretePortBuilder.setPortNumber(new PortNumberUni(DUMMY_PORT_NUMBER));
67 concretePortBuilder.setHardwareAddress(new MacAddress(DUMMY_MAC_ADDRESS));
68 concretePortBuilder.setPortModOrder(Uint32.ZERO);
70 Port port = new PortBuilder().setPort(BindingMap.of(concretePortBuilder.build())).build();
71 UpdatedPort updatePort = new UpdatedPortBuilder().setPort(port).build();
72 return new UpdatePortInputBuilder().setUpdatedPort(updatePort).build();