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.mockito.Mockito.verify;
12 import com.google.common.collect.Lists;
13 import java.util.List;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.mockito.runners.MockitoJUnitRunner;
17 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
18 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
19 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.Port;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.PortBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInputBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.port.update.UpdatedPort;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.port.update.UpdatedPortBuilder;
32 @RunWith(MockitoJUnitRunner.class)
33 public class SalPortServiceImplTest extends ServiceMocking {
35 private static final Long DUMMY_XID = 55L;
36 private static final Long DUMMY_PORT_NUMBER = 66L;
37 private static final String DUMMY_MAC_ADDRESS = "AA:BB:CC:DD:EE:FF";
38 SalPortServiceImpl salPortService;
41 public void initialization() {
42 super.initialization();
43 final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
44 salPortService = new SalPortServiceImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager);
48 public void testUpdatePort() throws Exception {
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 UpdatePortInput dummyUpdatePortInput(){
59 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.PortBuilder concretePortBuilder
60 = new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.PortBuilder();
61 concretePortBuilder.setConfiguration(new PortConfig(true, true, true, true));
62 concretePortBuilder.setAdvertisedFeatures(new PortFeatures(true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true));
63 concretePortBuilder.setPortNumber(new PortNumberUni(DUMMY_PORT_NUMBER));
64 concretePortBuilder.setHardwareAddress(new MacAddress(DUMMY_MAC_ADDRESS));
66 List<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port> ports
67 = Lists.newArrayList(concretePortBuilder.build());
68 Port port = new PortBuilder().setPort(ports).build();
69 UpdatedPort updatePort = new UpdatedPortBuilder().setPort(port).build();
70 return new UpdatePortInputBuilder().setUpdatedPort(updatePort).build();