HONEYCOMB-58 - Routing Api
[honeycomb.git] / v3po / v3po2vpp / src / test / java / io / fd / honeycomb / translate / v3po / interfacesstate / acl / ingress / AclCustomizerTest.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.acl.ingress;
18
19 import static org.mockito.Matchers.any;
20 import static org.mockito.Mockito.mock;
21 import static org.mockito.Mockito.verify;
22 import static org.mockito.Mockito.when;
23
24 import io.fd.honeycomb.translate.read.ReadFailedException;
25 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
26 import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager;
27 import io.fd.honeycomb.translate.vpp.util.NamingContext;
28 import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest;
29 import io.fd.vpp.jvpp.core.dto.ClassifyTableByInterfaceReply;
30 import org.junit.Test;
31 import org.mockito.Mock;
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.rev161214.VppInterfaceStateAugmentation;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev161214.acl.base.attributes.L2AclBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.Acl;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.AclBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.acl.Ingress;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.acl.IngressBuilder;
41 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
42
43 public class AclCustomizerTest extends ReaderCustomizerTest<Ingress, IngressBuilder> {
44
45     private static final String IF_NAME = "local0";
46     private static final int IF_INDEX = 1;
47     private static final int TABLE_INDEX = 123;
48     private static final String TABLE_NAME = "table123";
49     private static final InstanceIdentifier<Ingress> IID =
50         InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME))
51             .augmentation(VppInterfaceStateAugmentation.class).child(Acl.class).child(Ingress.class);
52
53     private static final String IFC_CTX_NAME = "ifc-test-instance";
54
55     private NamingContext interfaceContext;
56
57     @Mock
58     private VppClassifierContextManager classifyTableContext;
59
60     public AclCustomizerTest() {
61         super(Ingress.class, AclBuilder.class);
62     }
63
64     @Override
65     public void setUp() {
66         interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
67         defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
68     }
69
70     @Override
71     protected ReaderCustomizer<Ingress, IngressBuilder> initCustomizer() {
72         return new AclCustomizer(api, interfaceContext, classifyTableContext);
73     }
74
75     @Test
76     public void testRead() throws ReadFailedException {
77         final IngressBuilder builder = mock(IngressBuilder.class);
78
79         final ClassifyTableByInterfaceReply reply = new ClassifyTableByInterfaceReply();
80         reply.l2TableId = TABLE_INDEX;
81         reply.ip4TableId = ~0;
82         reply.ip6TableId = ~0;
83         when(api.classifyTableByInterface(any())).thenReturn(future(reply));
84
85         when(classifyTableContext.getTableName(TABLE_INDEX, mappingContext)).thenReturn(TABLE_NAME);
86
87         getCustomizer().readCurrentAttributes(IID, builder, ctx);
88
89         verify(builder).setL2Acl(new L2AclBuilder().setClassifyTable(TABLE_NAME).build());
90         verify(builder).setIp4Acl(null);
91         verify(builder).setIp6Acl(null);
92     }
93
94     @Test(expected = ReadFailedException.class)
95     public void testReadFailed() throws ReadFailedException {
96         when(api.classifyTableByInterface(any())).thenReturn(failedFuture());
97         getCustomizer().readCurrentAttributes(IID, mock(IngressBuilder.class), ctx);
98     }
99 }