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 io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping;
20 import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid;
21 import static org.mockito.Matchers.any;
22 import static org.mockito.Matchers.anyString;
23 import static org.mockito.Mockito.doReturn;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.never;
26 import static org.mockito.Mockito.verify;
28 import com.google.common.base.Optional;
29 import com.google.common.collect.Lists;
30 import io.fd.honeycomb.v3po.translate.read.ReadFailedException;
31 import io.fd.honeycomb.v3po.translate.spi.read.ChildReaderCustomizer;
32 import io.fd.honeycomb.v3po.translate.v3po.test.ChildReaderCustomizerTest;
33 import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
34 import java.util.HashMap;
35 import java.util.List;
37 import org.junit.Test;
38 import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings;
39 import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.MappingsBuilder;
40 import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
41 import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingKey;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VlanType;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentationBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.SubInterface;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.SubInterfaceBuilder;
50 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
51 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
52 import org.openvpp.jvpp.dto.SwInterfaceDetails;
54 public class SubInterfaceCustomizerTest extends ChildReaderCustomizerTest<SubInterface, SubInterfaceBuilder> {
56 private NamingContext interfacesContext;
58 public SubInterfaceCustomizerTest() {
59 super(SubInterface.class);
63 protected ChildReaderCustomizer<SubInterface, SubInterfaceBuilder> initCustomizer() {
64 return new SubInterfaceCustomizer(api, interfacesContext);
68 public void setUpBefore() {
69 interfacesContext = new NamingContext("generatedIfaceName", "test-instance");
72 private InstanceIdentifier<SubInterface> getSubInterfaceId(final String name) {
73 return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)).augmentation(
74 VppInterfaceStateAugmentation.class).child(
79 public void testMerge() {
80 final VppInterfaceStateAugmentationBuilder builder = mock(VppInterfaceStateAugmentationBuilder.class);
81 final SubInterface value = mock(SubInterface.class);
82 getCustomizer().merge(builder, value);
83 verify(builder).setSubInterface(value);
87 public void testRead() throws ReadFailedException {
88 final Map<Integer, SwInterfaceDetails> cachedInterfaceDump = new HashMap<>();
90 final String ifName = "eth0.sub0";
92 final KeyedInstanceIdentifier<Mapping, MappingKey> ifcIid = getMappingIid(ifName, "test-instance");
93 doReturn(getMapping(ifName, ifId)).when(mappingContext).read(ifcIid);
94 final KeyedInstanceIdentifier<Mapping, MappingKey> superIfcIid = getMappingIid("super", "test-instance");
95 doReturn(getMapping("super", 0)).when(mappingContext).read(superIfcIid);
97 final List<Mapping> allMappings = Lists.newArrayList(getMapping(ifName, ifId).get(), getMapping("super", 0).get());
98 final Mappings allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build();
99 doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(ifcIid.firstIdentifierOf(Mappings.class));
101 final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails();
102 ifaceDetails.subId = ifId;
103 ifaceDetails.interfaceName = ifName.getBytes();
104 cachedInterfaceDump.put(ifId, ifaceDetails);
105 cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump);
107 final SubInterfaceBuilder builder = mock(SubInterfaceBuilder.class);
108 getCustomizer().readCurrentAttributes(getSubInterfaceId(ifName), builder, ctx);
110 verify(builder).setIdentifier((long)ifId);
111 verify(builder).setSuperInterface(anyString());
112 verify(builder).setNumberOfTags((short)0);
113 verify(builder).setVlanType(VlanType._802dot1ad);
114 verify(builder, never()).setExactMatch(any());
115 verify(builder, never()).setDefaultSubif(any());
116 verify(builder, never()).setMatchAnyOuterId(any());
117 verify(builder, never()).setMatchAnyInnerId(any());
118 verify(builder, never()).setInnerId(any());
119 verify(builder, never()).setOuterId(any());