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.acl.ingress;
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;
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;
43 public class AclCustomizerTest extends ReaderCustomizerTest<Ingress, IngressBuilder> {
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);
53 private static final String IFC_CTX_NAME = "ifc-test-instance";
55 private NamingContext interfaceContext;
58 private VppClassifierContextManager classifyTableContext;
60 public AclCustomizerTest() {
61 super(Ingress.class, AclBuilder.class);
66 interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
67 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
71 protected ReaderCustomizer<Ingress, IngressBuilder> initCustomizer() {
72 return new AclCustomizer(api, interfaceContext, classifyTableContext);
76 public void testRead() throws ReadFailedException {
77 final IngressBuilder builder = mock(IngressBuilder.class);
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));
85 when(classifyTableContext.getTableName(TABLE_INDEX, mappingContext)).thenReturn(TABLE_NAME);
87 getCustomizer().readCurrentAttributes(IID, builder, ctx);
89 verify(builder).setL2Acl(new L2AclBuilder().setClassifyTable(TABLE_NAME).build());
90 verify(builder).setIp4Acl(null);
91 verify(builder).setIp6Acl(null);
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);