8ed35e01b3e5a0d838db959405ee484f7ac70205
[hc2vpp.git] /
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.v3po.translate.v3po.interfacesstate;
18
19 import static org.mockito.Matchers.any;
20 import static org.mockito.Mockito.mock;
21 import static org.mockito.Mockito.never;
22 import static org.mockito.Mockito.verify;
23
24 import io.fd.honeycomb.v3po.translate.Context;
25 import io.fd.honeycomb.v3po.translate.read.ReadFailedException;
26 import io.fd.honeycomb.v3po.translate.spi.read.ChildReaderCustomizer;
27 import io.fd.honeycomb.v3po.translate.v3po.test.ChildReaderCustomizerTest;
28 import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
29 import java.util.HashMap;
30 import java.util.Map;
31 import org.junit.Test;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VlanType;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentationBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.SubInterface;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.SubInterfaceBuilder;
40 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
41 import org.openvpp.jvpp.dto.SwInterfaceDetails;
42
43 public class SubInterfaceCustomizerTest extends ChildReaderCustomizerTest<SubInterface, SubInterfaceBuilder> {
44
45     private NamingContext interfacesContext;
46
47     public SubInterfaceCustomizerTest() {
48         super(SubInterface.class);
49     }
50
51     @Override
52     protected ChildReaderCustomizer<SubInterface, SubInterfaceBuilder> initCustomizer() {
53         return new SubInterfaceCustomizer(api, interfacesContext);
54     }
55
56     @Override
57     public void setUpBefore() {
58         interfacesContext = new NamingContext("generatedIfaceName");
59     }
60
61     private InstanceIdentifier<SubInterface> getSubInterfaceId(final String name) {
62         return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)).augmentation(
63                 VppInterfaceStateAugmentation.class).child(
64                 SubInterface.class);
65     }
66
67     @Test
68     public void testMerge() {
69         final VppInterfaceStateAugmentationBuilder builder = mock(VppInterfaceStateAugmentationBuilder.class);
70         final SubInterface value = mock(SubInterface.class);
71         getCustomizer().merge(builder, value);
72         verify(builder).setSubInterface(value);
73     }
74
75     @Test
76     public void testRead() throws ReadFailedException {
77         final Context ctx = new Context();
78         final Map<Integer, SwInterfaceDetails> cachedInterfaceDump = new HashMap<>();
79         final int ifId = 1;
80         final String ifName = "eth0.sub0";
81         interfacesContext.addName(ifId, ifName);
82         final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails();
83         ifaceDetails.subId = ifId;
84         ifaceDetails.interfaceName = ifName.getBytes();
85         cachedInterfaceDump.put(ifId, ifaceDetails);
86         ctx.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump);
87
88         final SubInterfaceBuilder builder = mock(SubInterfaceBuilder.class);
89         getCustomizer().readCurrentAttributes(getSubInterfaceId(ifName), builder, ctx);
90
91         verify(builder).setIdentifier((long)ifId);
92         verify(builder).setNumberOfTags((short)0);
93         verify(builder).setVlanType(VlanType._802dot1ad);
94         verify(builder, never()).setExactMatch(any());
95         verify(builder, never()).setDefaultSubif(any());
96         verify(builder, never()).setMatchAnyOuterId(any());
97         verify(builder, never()).setMatchAnyInnerId(any());
98         verify(builder, never()).setInnerId(any());
99         verify(builder, never()).setOuterId(any());
100     }
101 }