2 * Copyright (c) 2017 Cisco 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.lisp.gpe.translate.read;
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertTrue;
21 import static org.mockito.ArgumentMatchers.any;
22 import static org.mockito.Mockito.when;
24 import io.fd.hc2vpp.common.test.read.InitializingListReaderCustomizerTest;
25 import io.fd.honeycomb.translate.read.ReadFailedException;
26 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
27 import io.fd.vpp.jvpp.core.dto.GpeNativeFwdRpathsGet;
28 import io.fd.vpp.jvpp.core.dto.Ip6FibDetails;
29 import io.fd.vpp.jvpp.core.dto.Ip6FibDetailsReplyDump;
30 import io.fd.vpp.jvpp.core.dto.IpFibDetails;
31 import io.fd.vpp.jvpp.core.dto.IpFibDetailsReplyDump;
32 import java.util.Arrays;
33 import java.util.List;
34 import org.junit.Test;
35 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.gpe.rev170801.NativeForwardPathsTablesState;
36 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.gpe.rev170801.NativeForwardPathsTablesStateBuilder;
37 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.gpe.rev170801._native.forward.paths.tables.state.NativeForwardPathsTable;
38 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.gpe.rev170801._native.forward.paths.tables.state.NativeForwardPathsTableBuilder;
39 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.gpe.rev170801._native.forward.paths.tables.state.NativeForwardPathsTableKey;
40 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
42 public class NativeForwardPathsTableCustomizerTest extends
43 InitializingListReaderCustomizerTest<NativeForwardPathsTable, NativeForwardPathsTableKey, NativeForwardPathsTableBuilder> {
45 static final int TABLE_0_IDX = 1;
46 static final int TABLE_1_IDX = 2;
47 static final int TABLE_2_IDX = 3;
49 InstanceIdentifier<NativeForwardPathsTable> validId;
51 public NativeForwardPathsTableCustomizerTest() {
52 super(NativeForwardPathsTable.class, NativeForwardPathsTablesStateBuilder.class);
56 protected void setUp() throws Exception {
57 final GpeNativeFwdRpathsGet requestV4 = new GpeNativeFwdRpathsGet();
59 final GpeNativeFwdRpathsGet requestV6 = new GpeNativeFwdRpathsGet();
61 when(api.ipFibDump(any())).thenReturn(future(getReplyV4()));
62 when(api.ip6FibDump(any())).thenReturn(future(getReplyV6()));
63 validId = InstanceIdentifier.create(NativeForwardPathsTablesState.class)
64 .child(NativeForwardPathsTable.class, new NativeForwardPathsTableKey((long) TABLE_0_IDX));
68 public void testGetAll() throws ReadFailedException {
69 final List<NativeForwardPathsTableKey> allIds = getCustomizer().getAllIds(validId, ctx);
70 assertEquals(3, allIds.size());
71 assertTrue(allIds.contains(new NativeForwardPathsTableKey((long) TABLE_0_IDX)));
72 assertTrue(allIds.contains(new NativeForwardPathsTableKey((long) TABLE_1_IDX)));
73 assertTrue(allIds.contains(new NativeForwardPathsTableKey((long) TABLE_2_IDX)));
77 public void testReadCurrent() throws ReadFailedException {
78 NativeForwardPathsTableBuilder builder = new NativeForwardPathsTableBuilder();
79 getCustomizer().readCurrentAttributes(validId, builder, ctx);
80 final long lTableId = TABLE_0_IDX;
81 assertEquals(lTableId, builder.getTableId().intValue());
82 assertEquals(lTableId, builder.key().getTableId().intValue());
85 private IpFibDetailsReplyDump getReplyV4() {
86 IpFibDetailsReplyDump reply = new IpFibDetailsReplyDump();
87 IpFibDetails table0 = new IpFibDetails();
88 table0.tableId = TABLE_0_IDX;
89 IpFibDetails table2 = new IpFibDetails();
90 table2.tableId = TABLE_2_IDX;
91 reply.ipFibDetails = Arrays.asList(table0, table2);
95 private Ip6FibDetailsReplyDump getReplyV6() {
96 Ip6FibDetailsReplyDump reply = new Ip6FibDetailsReplyDump();
97 Ip6FibDetails table1 = new Ip6FibDetails();
98 table1.tableId = TABLE_1_IDX;
99 reply.ip6FibDetails = Arrays.asList(table1);
104 protected ReaderCustomizer<NativeForwardPathsTable, NativeForwardPathsTableBuilder> initCustomizer() {
105 return new NativeForwardPathsTableCustomizer(api);