HONEYCOMB-154: update revison of models that changed since 16.09
[honeycomb.git] / v3po / v3po2vpp / src / test / java / io / fd / honeycomb / translate / v3po / interfaces / ProxyArpCustomizerTest.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.interfaces;
18
19 import static org.mockito.Matchers.any;
20 import static org.mockito.Mockito.verify;
21 import static org.mockito.Mockito.when;
22
23 import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator;
24 import io.fd.honeycomb.translate.write.WriteFailedException;
25 import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
26 import org.junit.Test;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceAugmentation;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.ProxyArp;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.ProxyArpBuilder;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35 import io.fd.vpp.jvpp.core.dto.ProxyArpAddDel;
36 import io.fd.vpp.jvpp.core.dto.ProxyArpAddDelReply;
37
38 public class ProxyArpCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator {
39     private static final String IF_NAME = "eth1";
40
41     private ProxyArpCustomizer customizer;
42
43     @Override
44     public void setUp() throws Exception {
45         customizer = new ProxyArpCustomizer(api);
46     }
47
48     @Test
49     public void testWrite() throws WriteFailedException {
50         when(api.proxyArpAddDel(any())).thenReturn(future(new ProxyArpAddDelReply()));
51         customizer.writeCurrentAttributes(getProxyArpId(IF_NAME), proxyArp(), writeContext);
52         verify(api).proxyArpAddDel(expectedRequest(true));
53     }
54
55     @Test(expected = WriteFailedException.class)
56     public void testWriteFailed() throws WriteFailedException {
57         when(api.proxyArpAddDel(any())).thenReturn(failedFuture());
58         customizer.writeCurrentAttributes(getProxyArpId(IF_NAME), proxyArp(), writeContext);
59     }
60
61     @Test(expected = WriteFailedException.UpdateFailedException.class)
62     public void testUpdate() throws WriteFailedException.UpdateFailedException {
63         customizer.updateCurrentAttributes(getProxyArpId(IF_NAME), proxyArp(), proxyArp(), writeContext);
64     }
65
66     @Test
67     public void testDelete() throws WriteFailedException {
68         when(api.proxyArpAddDel(any())).thenReturn(future(new ProxyArpAddDelReply()));
69         customizer.deleteCurrentAttributes(getProxyArpId(IF_NAME), proxyArp(), writeContext);
70         verify(api).proxyArpAddDel(expectedRequest(false));
71     }
72
73     @Test(expected = WriteFailedException.DeleteFailedException.class)
74     public void testDeleteFailed() throws WriteFailedException {
75         when(api.proxyArpAddDel(any())).thenReturn(failedFuture());
76         customizer.deleteCurrentAttributes(getProxyArpId(IF_NAME), proxyArp(), writeContext);
77     }
78
79     private ProxyArp proxyArp() {
80         return new ProxyArpBuilder().setVrfId(123L).setHighAddr(new Ipv4AddressNoZone("10.1.1.2"))
81             .setLowAddr(new Ipv4AddressNoZone("10.1.1.1")).build();
82     }
83
84     private ProxyArpAddDel expectedRequest(final boolean isAdd) {
85         final ProxyArpAddDel request = new ProxyArpAddDel();
86         request.isAdd = booleanToByte(isAdd);
87         request.vrfId = 123;
88         request.lowAddress = new byte[]{10,1,1,1};
89         request.hiAddress = new byte[]{10,1,1,2};
90         return request;
91     }
92
93     private InstanceIdentifier<ProxyArp> getProxyArpId(final String eth0) {
94         return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(eth0)).augmentation(
95             VppInterfaceAugmentation.class).child(ProxyArp.class);
96     }
97 }