0daef976a0a2a49ecbbf72d4f95034a9daede2b8
[hc2vpp.git] /
1 /*
2  * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.hc2vpp.srv6.write.encap.source;
18
19 import static org.mockito.Mockito.verify;
20 import static org.mockito.Mockito.when;
21
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;
38
39 public class EncapsulationSourceCustomizerTest extends JvppRequestTest implements FutureProducer {
40
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)
46             .setSourceAddress(A1)
47             .build();
48
49     @Captor
50     private ArgumentCaptor<SrSetEncapSource> requestCaptor;
51
52     @Override
53     protected void init() {
54         MockitoAnnotations.initMocks(this);
55         sourceCustomizer = new EncapsulationSourceCustomizer(api);
56         when(api.srSetEncapSource(requestCaptor.capture())).thenReturn(future(new SrSetEncapSourceReply()));
57     }
58
59     @Test
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));
64     }
65
66     @Test
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);
71     }
72 }