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.request;
19 import static org.mockito.ArgumentMatchers.any;
20 import static org.mockito.Mockito.verify;
21 import static org.mockito.Mockito.verifyNoMoreInteractions;
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;
36 public class EncapsulationSourceRequestTest extends JvppRequestTest {
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};
42 private ArgumentCaptor<SrSetEncapSource> requestCaptor;
45 protected void init() {
46 Mockito.when(api.srSetEncapSource(any())).thenReturn(future(new SrSetEncapSourceReply()));
50 public void testWriteInvalid() throws WriteFailedException {
52 new EncapsulationSourceWriteRequest(api).write(Srv6IIds.RT_SRV6_ENCAP);
53 } catch (NullPointerException e) {
54 verifyNoMoreInteractions(api);
57 Assert.fail("NullPointerException was expected");
61 public void testWriteValid() throws WriteFailedException {
62 final EncapsulationSourceWriteRequest request = new EncapsulationSourceWriteRequest(api).setBsid(BSID);
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));
71 public void testDeleteValid() throws WriteFailedException {
72 final EncapsulationSourceDeleteRequest request = new EncapsulationSourceDeleteRequest(api);
74 request.delete(Srv6IIds.RT_SRV6_ENCAP);
75 verify(api, Mockito.times(1)).srSetEncapSource(requestCaptor.capture());
76 Assert.assertNull(requestCaptor.getValue().encapsSource);