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.translate.v3po.interfacesstate;
19 import static org.mockito.Matchers.any;
20 import static org.mockito.Mockito.mock;
21 import static org.mockito.Mockito.when;
23 import io.fd.honeycomb.translate.read.ReadFailedException;
24 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
25 import io.fd.honeycomb.translate.vpp.util.NamingContext;
26 import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest;
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.vpp.vlan.rev161214.SubinterfaceStateAugmentation;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.SubInterfaces;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterface;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterfaceBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterfaceKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.L2;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.L2Builder;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
40 public class SubInterfaceL2CustomizerTest extends ReaderCustomizerTest<L2, L2Builder> {
42 private static final String IFC_CTX_NAME = "ifc-test-instance";
43 private static final String BD_CTX_NAME = "bd-test-instance";
44 private NamingContext interfaceContext;
45 private NamingContext bridgeDomainContext;
47 private static final String IF_NAME = "local0";
48 private static final int IF_INDEX = 1;
49 private static final String SUB_IF_NAME = "local0.1";
50 private static final long SUB_IF_ID = 1;
51 private static final int SUB_IF_INDEX = 11;
52 private InstanceIdentifier<L2> IID =
53 InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME))
54 .augmentation(SubinterfaceStateAugmentation.class)
55 .child(SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)).child(L2.class);
57 public SubInterfaceL2CustomizerTest() {
58 super(L2.class, SubInterfaceBuilder.class);
62 protected void setUp() {
63 interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
64 bridgeDomainContext = new NamingContext("generatedBDName", BD_CTX_NAME);
65 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
66 defineMapping(mappingContext, SUB_IF_NAME, SUB_IF_INDEX, IFC_CTX_NAME);
70 protected ReaderCustomizer<L2, L2Builder> initCustomizer() {
71 return new SubInterfaceL2Customizer(api, interfaceContext, bridgeDomainContext);
74 @Test(expected = ReadFailedException.class)
75 public void testReadFailed() throws ReadFailedException {
76 final L2Builder builder = mock(L2Builder.class);
77 when(api.swInterfaceDump(any())).thenReturn(failedFuture());
78 getCustomizer().readCurrentAttributes(IID, builder, ctx);