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.sid.request;
19 import static io.fd.vpp.jvpp.Assertions.assertEquals;
20 import static org.mockito.Mockito.times;
21 import static org.mockito.Mockito.verify;
23 import io.fd.hc2vpp.srv6.Srv6IIds;
24 import io.fd.honeycomb.translate.write.WriteFailedException;
25 import io.fd.vpp.jvpp.core.dto.SrLocalsidAddDel;
26 import org.junit.Test;
28 public class TableLookupLocalSidRequestTest extends LocalSidRequestTest {
30 private static final int END_T_VALUE = 3;
32 @Test(expected = NullPointerException.class)
33 public void testNoAddress() throws WriteFailedException {
34 final TableLookupLocalSidRequest request = new TableLookupLocalSidRequest(api);
35 request.write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID);
38 @Test(expected = IllegalStateException.class)
39 public void testNoBehavior() throws WriteFailedException {
40 final TableLookupLocalSidRequest request = new TableLookupLocalSidRequest(api);
41 request.setLocalSidAddress(SID);
42 request.write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID);
46 public void testWriteValid() throws WriteFailedException {
47 createValidRequest().write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID);
48 verify(api, times(1)).srLocalsidAddDel(requestcaptor.capture());
49 final SrLocalsidAddDel jvppRequest = requestcaptor.getValue();
51 assertIsCreate(jvppRequest);
52 assertBaseFields(jvppRequest, SID_BYTES, 0, END_T_VALUE, 1);
53 assertEquals(7, jvppRequest.swIfIndex);
57 public void testDeleteValid() throws WriteFailedException {
58 createValidRequest().delete(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID);
59 verify(api, times(1)).srLocalsidAddDel(requestcaptor.capture());
60 final SrLocalsidAddDel jvppRequest = requestcaptor.getValue();
62 assertIsDelete(jvppRequest);
63 assertBaseFields(jvppRequest, SID_BYTES, 0, END_T_VALUE, 1);
64 assertEquals(7, jvppRequest.swIfIndex);
67 private TableLookupLocalSidRequest createValidRequest() {
68 final TableLookupLocalSidRequest request = new TableLookupLocalSidRequest(api);
69 request.setLookupFibTable(7);
70 request.setInstallFibTable(0);
71 request.setLocalSidAddress(SID);
72 request.setFunction(END_T_VALUE);