HONEYCOMB-154: update revison of models that changed since 16.09
[honeycomb.git] / v3po / v3po2vpp / src / test / java / io / fd / honeycomb / translate / v3po / interfacesstate / EthernetCustomizerTest.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.translate.v3po.interfacesstate;
18
19 import static org.mockito.Mockito.mock;
20 import static org.mockito.Mockito.verify;
21
22 import io.fd.honeycomb.translate.read.ReadFailedException;
23 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
24 import io.fd.honeycomb.translate.vpp.util.NamingContext;
25 import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest;
26 import io.fd.honeycomb.vpp.test.util.InterfaceDumpHelper;
27 import org.junit.Test;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.EthernetStateAttributes;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceStateAugmentation;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceStateAugmentationBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.Ethernet;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.EthernetBuilder;
36 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
37 import io.fd.vpp.jvpp.core.dto.SwInterfaceDetails;
38
39 public class EthernetCustomizerTest extends ReaderCustomizerTest<Ethernet, EthernetBuilder> implements
40     InterfaceDumpHelper {
41     private static final String IFC_CTX_NAME = "ifc-test-instance";
42     private static final String IF_NAME = "local0";
43     private static final int IF_INDEX = 1;
44     private static final InstanceIdentifier<Ethernet> IID =
45         InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME))
46             .augmentation(VppInterfaceStateAugmentation.class).child(Ethernet.class);
47     private NamingContext interfaceContext;
48
49     public EthernetCustomizerTest() {
50         super(Ethernet.class, VppInterfaceStateAugmentationBuilder.class);
51     }
52
53     @Override
54     protected void setUp() throws Exception {
55         interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
56         defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
57     }
58
59     @Override
60     protected ReaderCustomizer<Ethernet, EthernetBuilder> initCustomizer() {
61         return new EthernetCustomizer(api, interfaceContext);
62     }
63
64     private void testRead(final int linkDuplex, final EthernetStateAttributes.Duplex duplex) throws ReadFailedException {
65         final EthernetBuilder builder = mock(EthernetBuilder.class);
66         final short mtu = 123;
67         whenSwInterfaceDumpThenReturn(api, ifaceDetails(mtu, linkDuplex));
68         getCustomizer().readCurrentAttributes(IID, builder, ctx);
69         verify(builder).setMtu((int)mtu);
70         verify(builder).setDuplex(duplex);
71     }
72
73     private SwInterfaceDetails ifaceDetails(final short mtu, final int duplex) {
74         final SwInterfaceDetails details = new SwInterfaceDetails();
75         details.swIfIndex = IF_INDEX;
76         details.linkMtu = mtu;
77         details.linkDuplex = (byte)duplex;
78         return details;
79     }
80
81     @Test
82     public void testReadHalfDuplex() throws ReadFailedException {
83         testRead(1, EthernetStateAttributes.Duplex.Half);
84     }
85
86     @Test
87     public void testReadFullDuplex() throws ReadFailedException {
88         testRead(2, EthernetStateAttributes.Duplex.Full);
89     }
90 }