2 * Copyright (c) 2016 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package io.fd.honeycomb.v3po.translate.v3po.interfacesstate;
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;
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;
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;
43 public class SubInterfaceCustomizerTest extends ChildReaderCustomizerTest<SubInterface, SubInterfaceBuilder> {
45 private NamingContext interfacesContext;
47 public SubInterfaceCustomizerTest() {
48 super(SubInterface.class);
52 protected ChildReaderCustomizer<SubInterface, SubInterfaceBuilder> initCustomizer() {
53 return new SubInterfaceCustomizer(api, interfacesContext);
57 public void setUpBefore() {
58 interfacesContext = new NamingContext("generatedIfaceName");
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(
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);
76 public void testRead() throws ReadFailedException {
77 final Context ctx = new Context();
78 final Map<Integer, SwInterfaceDetails> cachedInterfaceDump = new HashMap<>();
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);
88 final SubInterfaceBuilder builder = mock(SubInterfaceBuilder.class);
89 getCustomizer().readCurrentAttributes(getSubInterfaceId(ifName), builder, ctx);
91 verify(builder).setIdentifier((long)ifId);
92 verify(builder).setSuperInterface(interfacesContext.getArtificialName(0));
93 verify(builder).setNumberOfTags((short)0);
94 verify(builder).setVlanType(VlanType._802dot1ad);
95 verify(builder, never()).setExactMatch(any());
96 verify(builder, never()).setDefaultSubif(any());
97 verify(builder, never()).setMatchAnyOuterId(any());
98 verify(builder, never()).setMatchAnyInnerId(any());
99 verify(builder, never()).setInnerId(any());
100 verify(builder, never()).setOuterId(any());