2 * Copyright (c) 2015 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.lisp.translate.write;
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;
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;
39 public class MapResolverCustomizerTest extends WriterCustomizerTest implements Ipv4Translator {
41 private MapResolverCustomizer customizer;
45 customizer = new MapResolverCustomizer(api);
48 private void whenLispAddDelMapResolverThenSuccess() {
49 when(api.lispAddDelMapResolver(any(LispAddDelMapResolver.class)))
50 .thenReturn(future(new LispAddDelMapResolverReply()));
53 @Test(expected = NullPointerException.class)
54 public void testWriteCurrentAttributesNullData() throws WriteFailedException {
55 customizer.writeCurrentAttributes(null, null, null);
58 @Test(expected = NullPointerException.class)
59 public void testWriteCurrentAttributesBadData() throws WriteFailedException {
60 customizer.writeCurrentAttributes(null, new MapResolverBuilder().build(), null);
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();
68 whenLispAddDelMapResolverThenSuccess();
70 customizer.writeCurrentAttributes(null, resolver, null);
72 ArgumentCaptor<LispAddDelMapResolver> resolverCaptor = ArgumentCaptor.forClass(LispAddDelMapResolver.class);
73 verify(api, times(1)).lispAddDelMapResolver(resolverCaptor.capture());
75 LispAddDelMapResolver request = resolverCaptor.getValue();
76 assertEquals(1, request.isAdd);
77 assertEquals("1.2.168.192", arrayToIpv4AddressNoZone(request.ipAddress).getValue());
81 @Test(expected = UnsupportedOperationException.class)
82 public void testUpdateCurrentAttributes() throws WriteFailedException {
83 customizer.updateCurrentAttributes(null, null, null, null);
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();
91 whenLispAddDelMapResolverThenSuccess();
93 customizer.deleteCurrentAttributes(null, resolver, null);
95 ArgumentCaptor<LispAddDelMapResolver> resolverCaptor = ArgumentCaptor.forClass(LispAddDelMapResolver.class);
96 verify(api, times(1)).lispAddDelMapResolver(resolverCaptor.capture());
98 LispAddDelMapResolver request = resolverCaptor.getValue();
99 assertEquals(0, request.isAdd);
100 assertEquals("1.2.168.192", arrayToIpv4AddressNoZone(request.ipAddress).getValue());