HONEYCOMB-58 - Routing Api
[honeycomb.git] / nat / nat2vpp / src / test / java / io / fd / honeycomb / nat / read / ifc / InterfaceOutboundNatCustomizerTest.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.nat.read.ifc;
18
19 import static io.fd.honeycomb.nat.read.ifc.InterfaceInboundNatCustomizerTest.getId;
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertTrue;
22
23 import com.google.common.collect.Lists;
24 import io.fd.honeycomb.translate.impl.read.GenericReader;
25 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
26 import io.fd.honeycomb.translate.util.RWUtils;
27 import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager;
28 import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor;
29 import io.fd.honeycomb.translate.vpp.util.NamingContext;
30 import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest;
31 import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetails;
32 import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetailsReplyDump;
33 import org.junit.Test;
34 import org.mockito.Mock;
35 import org.mockito.Mockito;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214._interface.nat.attributes.NatBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214._interface.nat.attributes.nat.Outbound;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev161214._interface.nat.attributes.nat.OutboundBuilder;
39 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
40
41 public class InterfaceOutboundNatCustomizerTest
42         extends ReaderCustomizerTest<Outbound, OutboundBuilder> {
43
44     private static final String IFC_NAME = "a";
45     private static final int IFC_IDX = 0;
46     private static final String CTX_NAME = "ifc";
47
48     @Mock
49     private EntityDumpExecutor<SnatInterfaceDetailsReplyDump, Void> abc;
50     private DumpCacheManager<SnatInterfaceDetailsReplyDump, Void> dumpMgr;
51     private NamingContext ifcContext = new NamingContext(CTX_NAME, CTX_NAME);
52     private InstanceIdentifier<Outbound> id;
53
54     public InterfaceOutboundNatCustomizerTest() {
55         super(Outbound.class, NatBuilder.class);
56     }
57
58     @Override
59     protected void setUp() throws Exception {
60         id = getId(Outbound.class);
61         defineMapping(mappingContext, IFC_NAME, IFC_IDX, CTX_NAME);
62         // empty dump
63         Mockito.doReturn(new SnatInterfaceDetailsReplyDump()).when(abc).executeDump(id, null);
64         dumpMgr = new DumpCacheManager.DumpCacheManagerBuilder<SnatInterfaceDetailsReplyDump, Void>()
65                 .withExecutor(abc)
66                 .build();
67     }
68
69     @Test
70     public void testNoPresence() throws Exception {
71         assertFalse(getReader().read(id, ctx).isPresent());
72     }
73
74     private GenericReader<Outbound, OutboundBuilder> getReader() {
75         return new GenericReader<>(RWUtils.makeIidWildcarded(id), customizer);
76     }
77
78     @Test
79     public void testPresence() throws Exception {
80         final SnatInterfaceDetailsReplyDump details = new SnatInterfaceDetailsReplyDump();
81         final SnatInterfaceDetails detail = new SnatInterfaceDetails();
82         detail.isInside = 0;
83         detail.swIfIndex = IFC_IDX;
84         details.snatInterfaceDetails = Lists.newArrayList(detail);
85         Mockito.doReturn(details).when(abc).executeDump(id, null);
86
87         assertTrue(getReader().read(id, ctx).isPresent());
88     }
89
90     @Override
91     protected ReaderCustomizer<Outbound, OutboundBuilder> initCustomizer() {
92         return new InterfaceOutboundNatCustomizer(dumpMgr, ifcContext);
93     }
94 }