442b87cdd3e8bd50965793d15156c5a6c067f033
[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.request;
18
19 import static org.mockito.ArgumentMatchers.any;
20 import static org.mockito.Mockito.verify;
21 import static org.mockito.Mockito.verifyNoMoreInteractions;
22
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.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
35
36 public class EncapsulationSourceRequestTest extends JvppRequestTest {
37
38     private static final Ipv6Address BSID = new Ipv6Address("C1::");
39     private static final byte[] BSID_BYTES = {0, -63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
40
41     @Captor
42     private ArgumentCaptor<SrSetEncapSource> requestCaptor;
43
44     @Override
45     protected void init() {
46         Mockito.when(api.srSetEncapSource(any())).thenReturn(future(new SrSetEncapSourceReply()));
47     }
48
49     @Test
50     public void testWriteInvalid() throws WriteFailedException {
51         try {
52             new EncapsulationSourceWriteRequest(api).write(Srv6IIds.RT_SRV6_ENCAP);
53         } catch (NullPointerException e) {
54             verifyNoMoreInteractions(api);
55             return;
56         }
57         Assert.fail("NullPointerException was expected");
58     }
59
60     @Test
61     public void testWriteValid() throws WriteFailedException {
62         final EncapsulationSourceWriteRequest request = new EncapsulationSourceWriteRequest(api).setBsid(BSID);
63
64         request.write(Srv6IIds.RT_SRV6_ENCAP);
65         verify(api, Mockito.times(1)).srSetEncapSource(requestCaptor.capture());
66         Assert.assertEquals(BSID, request.getBsid());
67         Assert.assertTrue(Arrays.equals(BSID_BYTES, requestCaptor.getValue().encapsSource));
68     }
69
70     @Test
71     public void testDeleteValid() throws WriteFailedException {
72         final EncapsulationSourceDeleteRequest request = new EncapsulationSourceDeleteRequest(api);
73
74         request.delete(Srv6IIds.RT_SRV6_ENCAP);
75         verify(api, Mockito.times(1)).srSetEncapSource(requestCaptor.capture());
76         Assert.assertNull(requestCaptor.getValue().encapsSource);
77     }
78 }