2 * Copyright (c) 2016 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.honeycomb.lisp.translate.read;
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertNotNull;
22 import static org.junit.Assert.assertTrue;
23 import static org.junit.Assert.fail;
24 import static org.mockito.Mockito.when;
26 import com.google.common.collect.ImmutableList;
27 import io.fd.honeycomb.translate.read.ReadFailedException;
28 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
29 import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest;
30 import io.fd.vpp.jvpp.VppCallbackException;
31 import io.fd.vpp.jvpp.core.dto.LispEidTableVniDetails;
32 import io.fd.vpp.jvpp.core.dto.LispEidTableVniDetailsReplyDump;
33 import java.util.List;
34 import java.util.concurrent.CompletableFuture;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.mockito.Mockito;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.EidTable;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.EidTableBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTable;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTableBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTableKey;
43 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
45 public class VniTableCustomizerTest extends ListReaderCustomizerTest<VniTable, VniTableKey, VniTableBuilder> {
47 private InstanceIdentifier<VniTable> validId;
49 public VniTableCustomizerTest() {
50 super(VniTable.class, EidTableBuilder.class);
55 validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(12L));
59 public void testReadAllSuccessfull() throws ReadFailedException {
60 whenLispEidTableVniDumpReturnValid();
61 final List<VniTableKey> keys = getCustomizer().getAllIds(validId, ctx);
64 assertEquals(3, keys.size());
65 assertTrue(keys.contains(new VniTableKey(12L)));
66 assertTrue(keys.contains(new VniTableKey(14L)));
67 assertTrue(keys.contains(new VniTableKey(16L)));
71 public void testReadAllFailed() {
72 whenLispEidTableVniDumpThrowException();
74 getCustomizer().getAllIds(validId, ctx);
75 } catch (ReadFailedException e) {
76 assertTrue(e.getCause() instanceof VppCallbackException);
80 fail("Test should have thrown ReadFailedException");
84 public void testReadAttributes() throws ReadFailedException {
85 whenLispEidTableVniDumpReturnValid();
86 VniTableBuilder builder = new VniTableBuilder();
88 customizer.readCurrentAttributes(validId, builder, ctx);
90 final VniTable table = builder.build();
92 assertEquals(12L, table.getVirtualNetworkIdentifier().longValue());
95 private void whenLispEidTableVniDumpReturnValid() {
97 LispEidTableVniDetailsReplyDump dump = new LispEidTableVniDetailsReplyDump();
98 LispEidTableVniDetails details1 = new LispEidTableVniDetails();
101 LispEidTableVniDetails details2 = new LispEidTableVniDetails();
104 LispEidTableVniDetails details3 = new LispEidTableVniDetails();
107 dump.lispEidTableVniDetails = ImmutableList.of(details1, details2, details3);
109 when(api.lispEidTableVniDump(Mockito.any())).thenReturn(CompletableFuture.completedFuture(dump));
112 private void whenLispEidTableVniDumpThrowException() {
113 when(api.lispEidTableVniDump(Mockito.any()))
114 .thenReturn(failedFuture());
118 protected ReaderCustomizer<VniTable, VniTableBuilder> initCustomizer() {
119 return new VniTableCustomizer(api);