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.mock;
22 import static org.mockito.Mockito.times;
23 import static org.mockito.Mockito.verify;
24 import static org.mockito.Mockito.when;
26 import io.fd.honeycomb.translate.v3po.util.TranslateUtils;
27 import io.fd.honeycomb.translate.write.WriteFailedException;
28 import java.util.concurrent.CompletableFuture;
29 import java.util.concurrent.ExecutionException;
30 import org.junit.Test;
31 import org.mockito.ArgumentCaptor;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.map.resolvers.grouping.map.resolvers.MapResolver;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.map.resolvers.grouping.map.resolvers.MapResolverBuilder;
36 import org.openvpp.jvpp.core.dto.LispAddDelMapResolver;
37 import org.openvpp.jvpp.core.dto.LispAddDelMapResolverReply;
38 import org.openvpp.jvpp.core.future.FutureJVppCore;
41 public class MapResolverCustomizerTest {
43 @Test(expected = NullPointerException.class)
44 public void testWriteCurrentAttributesNullData() throws WriteFailedException {
45 new MapResolverCustomizer(mock(FutureJVppCore.class)).writeCurrentAttributes(null, null, null);
48 @Test(expected = NullPointerException.class)
49 public void testWriteCurrentAttributesBadData() throws WriteFailedException {
50 new MapResolverCustomizer(mock(FutureJVppCore.class))
51 .writeCurrentAttributes(null, new MapResolverBuilder().build(), null);
55 public void testWriteCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException {
56 FutureJVppCore fakeJvpp = mock(FutureJVppCore.class);
58 MapResolverCustomizer customizer = new MapResolverCustomizer(fakeJvpp);
59 Ipv4Address address = new Ipv4Address("192.168.2.1");
60 MapResolver resolver = new MapResolverBuilder().setIpAddress(new IpAddress(address)).build();
62 ArgumentCaptor<LispAddDelMapResolver> resolverCaptor = ArgumentCaptor.forClass(LispAddDelMapResolver.class);
64 LispAddDelMapResolverReply fakeReply = new LispAddDelMapResolverReply();
66 CompletableFuture<LispAddDelMapResolverReply> finalStage = new CompletableFuture<>();
67 finalStage.complete(fakeReply);
69 when(fakeJvpp.lispAddDelMapResolver(any(LispAddDelMapResolver.class))).thenReturn(finalStage);
71 customizer.writeCurrentAttributes(null, resolver, null);
72 verify(fakeJvpp, times(1)).lispAddDelMapResolver(resolverCaptor.capture());
74 LispAddDelMapResolver request = resolverCaptor.getValue();
75 assertEquals(1, request.isAdd);
76 assertEquals("1.2.168.192", TranslateUtils.arrayToIpv4AddressNoZone(request.ipAddress).getValue());
80 @Test(expected = UnsupportedOperationException.class)
81 public void testUpdateCurrentAttributes() throws WriteFailedException {
82 new MapResolverCustomizer(mock(FutureJVppCore.class)).updateCurrentAttributes(null, null, null, null);
86 public void testDeleteCurrentAttributes() throws InterruptedException, ExecutionException, WriteFailedException {
88 FutureJVppCore fakeJvpp = mock(FutureJVppCore.class);
90 MapResolverCustomizer customizer = new MapResolverCustomizer(fakeJvpp);
91 Ipv4Address address = new Ipv4Address("192.168.2.1");
92 MapResolver resolver = new MapResolverBuilder().setIpAddress(new IpAddress(address)).build();
94 ArgumentCaptor<LispAddDelMapResolver> resolverCaptor = ArgumentCaptor.forClass(LispAddDelMapResolver.class);
96 LispAddDelMapResolverReply fakeReply = new LispAddDelMapResolverReply();
98 CompletableFuture<LispAddDelMapResolverReply> finalStage = new CompletableFuture<>();
99 finalStage.complete(fakeReply);
101 when(fakeJvpp.lispAddDelMapResolver(any(LispAddDelMapResolver.class))).thenReturn(finalStage);
103 customizer.deleteCurrentAttributes(null, resolver, null);
104 verify(fakeJvpp, times(1)).lispAddDelMapResolver(resolverCaptor.capture());
106 LispAddDelMapResolver request = resolverCaptor.getValue();
107 assertEquals(0, request.isAdd);
108 assertEquals("1.2.168.192", TranslateUtils.arrayToIpv4AddressNoZone(request.ipAddress).getValue());