2 * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.hc2vpp.srv6.write.encap.source;
19 import static org.mockito.Mockito.verify;
20 import static org.mockito.Mockito.when;
22 import io.fd.hc2vpp.common.test.util.FutureProducer;
23 import io.fd.hc2vpp.srv6.Srv6IIds;
24 import io.fd.hc2vpp.srv6.util.JvppRequestTest;
25 import io.fd.honeycomb.translate.write.WriteFailedException;
26 import io.fd.vpp.jvpp.core.dto.SrSetEncapSource;
27 import io.fd.vpp.jvpp.core.dto.SrSetEncapSourceReply;
28 import java.util.Arrays;
29 import org.junit.Assert;
30 import org.junit.Test;
31 import org.mockito.ArgumentCaptor;
32 import org.mockito.Captor;
33 import org.mockito.Mockito;
34 import org.mockito.MockitoAnnotations;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.encap.Encapsulation;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.encap.EncapsulationBuilder;
39 public class EncapsulationSourceCustomizerTest extends JvppRequestTest implements FutureProducer {
41 private static final byte[] BSID_BYTES = {0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
42 private static Ipv6Address A1 = new Ipv6Address("a::1");
43 private static EncapsulationSourceCustomizer sourceCustomizer;
44 private static Encapsulation encapsulation = new EncapsulationBuilder()
45 .setIpTtlPropagation(false)
50 private ArgumentCaptor<SrSetEncapSource> requestCaptor;
53 protected void init() {
54 MockitoAnnotations.initMocks(this);
55 sourceCustomizer = new EncapsulationSourceCustomizer(api);
56 when(api.srSetEncapSource(requestCaptor.capture())).thenReturn(future(new SrSetEncapSourceReply()));
60 public void writeCurrentAttributesTest() throws WriteFailedException {
61 sourceCustomizer.writeCurrentAttributes(Srv6IIds.RT_SRV6_ENCAP, encapsulation, ctx);
62 verify(api, Mockito.times(1)).srSetEncapSource(requestCaptor.capture());
63 Assert.assertTrue(Arrays.equals(BSID_BYTES, requestCaptor.getValue().encapsSource));
67 public void deleteCurrentAttributesTest() throws WriteFailedException {
68 sourceCustomizer.deleteCurrentAttributes(Srv6IIds.RT_SRV6_ENCAP, encapsulation, ctx);
69 verify(api, Mockito.times(1)).srSetEncapSource(requestCaptor.capture());
70 Assert.assertNull(requestCaptor.getValue().encapsSource);