3f80ae561422affe5c98317d33d2ed0424733eec
[honeycomb.git] / lisp / lisp2vpp / src / test / java / io / fd / honeycomb / lisp / translate / write / trait / SubtableWriterTestCase.java
1 /*
2  * Copyright (c) 2016 Cisco 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.honeycomb.lisp.translate.write.trait;
18
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertNotNull;
22 import static org.mockito.Mockito.times;
23 import static org.mockito.Mockito.verify;
24 import static org.mockito.Mockito.when;
25
26 import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
27 import io.fd.vpp.jvpp.core.dto.LispEidTableAddDelMap;
28 import io.fd.vpp.jvpp.core.dto.LispEidTableAddDelMapReply;
29 import org.mockito.ArgumentCaptor;
30 import org.mockito.Captor;
31 import org.mockito.Mockito;
32
33 public class SubtableWriterTestCase extends WriterCustomizerTest implements SubtableWriter {
34     @Captor
35     protected ArgumentCaptor<LispEidTableAddDelMap> requestCaptor;
36
37
38     protected void verifyAddDelEidTableAddDelMapInvokedCorrectly(final int addDel, final int vni, final int tableId,
39                                                                  final int isL2) {
40         verify(api, times(1)).lispEidTableAddDelMap(requestCaptor.capture());
41
42         final LispEidTableAddDelMap request = requestCaptor.getValue();
43         assertNotNull(request);
44         assertEquals(addDel, request.isAdd);
45         assertEquals(vni, request.vni);
46         assertEquals(tableId, request.dpTable);
47         assertEquals(isL2, request.isL2);
48     }
49
50     protected void whenAddDelEidTableAddDelMapSuccess() {
51         when(api.lispEidTableAddDelMap(Mockito.any(LispEidTableAddDelMap.class)))
52                 .thenReturn(future(new LispEidTableAddDelMapReply()));
53     }
54
55     protected void whenAddDelEidTableAddDelMapFail() {
56         when(api.lispEidTableAddDelMap(Mockito.any(LispEidTableAddDelMap.class)))
57                 .thenReturn(failedFuture());
58     }
59 }