83e84102becee96ec9a13ba5a373fa95779f2608
[honeycomb.git] / v3po / v3po2vpp / src / test / java / io / fd / honeycomb / translate / v3po / interfacesstate / SubInterfaceL2CustomizerTest.java
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.translate.v3po.interfacesstate;
18
19 import static org.mockito.Matchers.any;
20 import static org.mockito.Mockito.mock;
21 import static org.mockito.Mockito.when;
22
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;
39
40 public class SubInterfaceL2CustomizerTest extends ReaderCustomizerTest<L2, L2Builder> {
41
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;
46
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);
56
57     public SubInterfaceL2CustomizerTest() {
58         super(L2.class, SubInterfaceBuilder.class);
59     }
60
61     @Override
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);
67     }
68
69     @Override
70     protected ReaderCustomizer<L2, L2Builder> initCustomizer() {
71         return new SubInterfaceL2Customizer(api, interfaceContext, bridgeDomainContext);
72     }
73
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);
79     }
80 }