Decompose RPC implementation classes
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / sal / UpdatePortImplTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowplugin.impl.services.sal;
9
10 import static org.junit.Assert.assertNotNull;
11 import static org.mockito.Mockito.verify;
12
13 import org.junit.Test;
14 import org.junit.runner.RunWith;
15 import org.mockito.junit.MockitoJUnitRunner;
16 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
17 import org.opendaylight.openflowplugin.impl.services.ServiceMocking;
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.PortBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInputBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.port.update.UpdatedPortBuilder;
27 import org.opendaylight.yangtools.yang.binding.util.BindingMap;
28 import org.opendaylight.yangtools.yang.common.Uint32;
29
30 @RunWith(MockitoJUnitRunner.class)
31 public class UpdatePortImplTest extends ServiceMocking {
32     private static final Uint32 DUMMY_XID = Uint32.valueOf(55L);
33     private static final Uint32 DUMMY_PORT_NUMBER = Uint32.valueOf(66L);
34     private static final String DUMMY_MAC_ADDRESS = "AA:BB:CC:DD:EE:FF";
35
36     private UpdatePortImpl updatePort;
37
38     @Override
39     protected void setup() {
40         final var convertorManager = ConvertorManagerFactory.createDefaultManager();
41         updatePort = new UpdatePortImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager);
42     }
43
44     @Test
45     public void testUpdatePort() {
46         updatePort.invoke(dummyUpdatePortInput());
47         verify(mockedRequestContextStack).createRequestContext();
48     }
49
50     @Test
51     public void testBuildRequest() {
52         assertNotNull(updatePort.buildRequest(new Xid(DUMMY_XID), dummyUpdatePortInput()));
53     }
54
55     private static UpdatePortInput dummyUpdatePortInput() {
56         return new UpdatePortInputBuilder()
57             .setUpdatedPort(new UpdatedPortBuilder()
58                 .setPort(new PortBuilder()
59                     .setPort(BindingMap.of(new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925
60                         .port.mod.port.PortBuilder()
61                         .setConfiguration(new PortConfig(true, true, true, true))
62                         .setAdvertisedFeatures(new PortFeatures(true, true, true, true, true, true, true, true, true,
63                             true, true, true, true, true, true, true))
64                         .setPortNumber(new PortNumberUni(DUMMY_PORT_NUMBER))
65                         .setHardwareAddress(new MacAddress(DUMMY_MAC_ADDRESS))
66                         .setPortModOrder(Uint32.ZERO)
67                         .build()))
68                     .build())
69                 .build())
70             .build();
71     }
72 }