HONEYCOMB-58 - Routing Api
[honeycomb.git] / lisp / lisp2vpp / src / test / java / io / fd / honeycomb / lisp / translate / read / trait / SubtableReaderTestCase.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.read.trait;
18
19
20 import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.SubtableDumpParams.MapLevel;
21 import static org.junit.Assert.assertEquals;
22 import static org.mockito.Matchers.any;
23 import static org.mockito.Mockito.times;
24 import static org.mockito.Mockito.verify;
25 import static org.mockito.Mockito.when;
26 import static org.mockito.MockitoAnnotations.initMocks;
27
28 import com.google.common.collect.ImmutableList;
29 import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest;
30 import io.fd.vpp.jvpp.VppCallbackException;
31 import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetails;
32 import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump;
33 import io.fd.vpp.jvpp.core.dto.LispEidTableMapDump;
34 import java.util.Collections;
35 import java.util.concurrent.CompletableFuture;
36 import java.util.concurrent.ExecutionException;
37 import java.util.concurrent.TimeUnit;
38 import java.util.concurrent.TimeoutException;
39 import javax.annotation.Nonnull;
40 import org.junit.Before;
41 import org.mockito.ArgumentCaptor;
42 import org.mockito.Captor;
43 import org.opendaylight.yangtools.concepts.Builder;
44 import org.opendaylight.yangtools.yang.binding.DataObject;
45
46 public abstract class SubtableReaderTestCase<D extends DataObject, B extends Builder<D>>
47         extends ReaderCustomizerTest<D, B>
48         implements SubtableReader {
49
50     protected final long expectedVni = 12;
51     protected final int expectedTableId = 14;
52
53     @Captor
54     protected ArgumentCaptor<LispEidTableMapDump> requestCaptor;
55
56     public SubtableReaderTestCase(final Class<D> dataObjectClass,
57                                   final Class<? extends Builder<? extends DataObject>> parentBuilderClass) {
58         super(dataObjectClass, parentBuilderClass);
59     }
60
61     protected void doReturnValidNonEmptyDataOnDump() {
62         LispEidTableMapDetailsReplyDump reply = new LispEidTableMapDetailsReplyDump();
63         LispEidTableMapDetails detailFirst = new LispEidTableMapDetails();
64         detailFirst.vni = Long.valueOf(expectedVni).intValue();
65         detailFirst.dpTable = expectedTableId;
66
67         LispEidTableMapDetails detailSecond = new LispEidTableMapDetails();
68         detailSecond.vni = 13;
69         detailSecond.dpTable = 15;
70
71         reply.lispEidTableMapDetails = ImmutableList.of(detailFirst, detailSecond);
72
73         when(api.lispEidTableMapDump(any(LispEidTableMapDump.class)))
74                 .thenReturn(future(reply));
75     }
76
77     protected void doReturnEmptyDataOnDump() {
78         LispEidTableMapDetailsReplyDump reply = new LispEidTableMapDetailsReplyDump();
79         reply.lispEidTableMapDetails = Collections.emptyList();
80         when(api.lispEidTableMapDump(any(LispEidTableMapDump.class)))
81                 .thenReturn(future(reply));
82     }
83
84     protected void doThrowOnDump() {
85         when(api.lispEidTableMapDump(any(LispEidTableMapDump.class)))
86                 .thenReturn(failedFuture());
87     }
88
89     protected void verifyLispEidTableMapDumpCalled(@Nonnull final MapLevel expectedLevel) {
90         verify(api, times(1)).lispEidTableMapDump(requestCaptor.capture());
91         assertEquals(expectedLevel.getValue(), requestCaptor.getValue().isL2);
92     }
93
94     protected void verifyLispEidTableMapDumpNotCalled() {
95         verify(api, times(1)).lispEidTableMapDump(any());
96     }
97 }