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.RootReaderCustomizer;
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.TagRewriteOperation;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VlanType;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.L2;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.L2Builder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.l2.VlanTagRewrite;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.l2.VlanTagRewriteBuilder;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
43 import org.openvpp.jvpp.dto.SwInterfaceDetails;
45 public class VlanTagRewriteCustomizerTest extends ChildReaderCustomizerTest<VlanTagRewrite, VlanTagRewriteBuilder> {
47 private NamingContext interfacesContext;
49 public VlanTagRewriteCustomizerTest() {
50 super(VlanTagRewrite.class);
54 public void setUpBefore() {
55 interfacesContext = new NamingContext("generatedIfaceName");
60 protected RootReaderCustomizer<VlanTagRewrite, VlanTagRewriteBuilder> initCustomizer() {
61 return new VlanTagRewriteCustomizer(api, interfacesContext);
65 public void testMerge() {
66 final L2Builder builder = mock(L2Builder.class);
67 final VlanTagRewrite value = mock(VlanTagRewrite.class);
68 getCustomizer().merge(builder, value);
69 verify(builder).setVlanTagRewrite(value);
72 private InstanceIdentifier<VlanTagRewrite> getVlanTagRewriteId(final String name) {
73 return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)).augmentation(
74 VppInterfaceStateAugmentation.class).child(L2.class).child(VlanTagRewrite.class);
78 public void testRead() throws ReadFailedException {
79 final Context ctx = new Context();
80 final Map<Integer, SwInterfaceDetails> cachedInterfaceDump = new HashMap<>();
82 final String ifName = "eth0.sub0";
83 interfacesContext.addName(ifId, ifName);
84 final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails();
85 ifaceDetails.subId = ifId;
86 cachedInterfaceDump.put(ifId, ifaceDetails);
87 ctx.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump);
89 final VlanTagRewriteBuilder builder = mock(VlanTagRewriteBuilder.class);
90 getCustomizer().readCurrentAttributes(getVlanTagRewriteId(ifName), builder, ctx);
92 verify(builder).setFirstPushed(VlanType._802dot1ad);
93 verify(builder).setRewriteOperation(TagRewriteOperation.Disabled);
94 verify(builder, never()).setTag1(any());
95 verify(builder, never()).setTag2(any());