HONEYCOMB-154: update revison of models that changed since 16.09
[honeycomb.git] / lisp / lisp2vpp / src / test / java / io / fd / honeycomb / lisp / translate / write / MapResolverCustomizerTest.java
1 /*
2  * Copyright (c) 2015 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.lisp.translate.write;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.mockito.Matchers.any;
21 import static org.mockito.Mockito.times;
22 import static org.mockito.Mockito.verify;
23 import static org.mockito.Mockito.when;
24
25 import io.fd.honeycomb.translate.vpp.util.Ipv4Translator;
26 import io.fd.honeycomb.translate.write.WriteFailedException;
27 import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
28 import java.util.concurrent.ExecutionException;
29 import org.junit.Test;
30 import org.mockito.ArgumentCaptor;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.map.resolvers.grouping.map.resolvers.MapResolver;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.map.resolvers.grouping.map.resolvers.MapResolverBuilder;
35 import io.fd.vpp.jvpp.core.dto.LispAddDelMapResolver;
36 import io.fd.vpp.jvpp.core.dto.LispAddDelMapResolverReply;
37
38
39 public class MapResolverCustomizerTest extends WriterCustomizerTest implements Ipv4Translator {
40
41     private MapResolverCustomizer customizer;
42
43     @Override
44     public void setUp() {
45         customizer = new MapResolverCustomizer(api);
46     }
47
48     private void whenLispAddDelMapResolverThenSuccess() {
49         when(api.lispAddDelMapResolver(any(LispAddDelMapResolver.class)))
50             .thenReturn(future(new LispAddDelMapResolverReply()));
51     }
52
53     @Test(expected = NullPointerException.class)
54     public void testWriteCurrentAttributesNullData() throws WriteFailedException {
55         customizer.writeCurrentAttributes(null, null, null);
56     }
57
58     @Test(expected = NullPointerException.class)
59     public void testWriteCurrentAttributesBadData() throws WriteFailedException {
60         customizer.writeCurrentAttributes(null, new MapResolverBuilder().build(), null);
61     }
62
63     @Test
64     public void testWriteCurrentAttributes() throws WriteFailedException {
65         Ipv4Address address = new Ipv4Address("192.168.2.1");
66         MapResolver resolver = new MapResolverBuilder().setIpAddress(new IpAddress(address)).build();
67
68         whenLispAddDelMapResolverThenSuccess();
69
70         customizer.writeCurrentAttributes(null, resolver, null);
71
72         ArgumentCaptor<LispAddDelMapResolver> resolverCaptor = ArgumentCaptor.forClass(LispAddDelMapResolver.class);
73         verify(api, times(1)).lispAddDelMapResolver(resolverCaptor.capture());
74
75         LispAddDelMapResolver request = resolverCaptor.getValue();
76         assertEquals(1, request.isAdd);
77         assertEquals("1.2.168.192", arrayToIpv4AddressNoZone(request.ipAddress).getValue());
78     }
79
80
81     @Test(expected = UnsupportedOperationException.class)
82     public void testUpdateCurrentAttributes() throws WriteFailedException {
83         customizer.updateCurrentAttributes(null, null, null, null);
84     }
85
86     @Test
87     public void testDeleteCurrentAttributes() throws InterruptedException, ExecutionException, WriteFailedException {
88         Ipv4Address address = new Ipv4Address("192.168.2.1");
89         MapResolver resolver = new MapResolverBuilder().setIpAddress(new IpAddress(address)).build();
90
91         whenLispAddDelMapResolverThenSuccess();
92
93         customizer.deleteCurrentAttributes(null, resolver, null);
94
95         ArgumentCaptor<LispAddDelMapResolver> resolverCaptor = ArgumentCaptor.forClass(LispAddDelMapResolver.class);
96         verify(api, times(1)).lispAddDelMapResolver(resolverCaptor.capture());
97
98         LispAddDelMapResolver request = resolverCaptor.getValue();
99         assertEquals(0, request.isAdd);
100         assertEquals("1.2.168.192", arrayToIpv4AddressNoZone(request.ipAddress).getValue());
101     }
102
103 }