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;
19 import static org.junit.Assert.assertEquals;
20 import static org.mockito.Mockito.when;
22 import com.google.common.collect.ImmutableList;
23 import io.fd.honeycomb.translate.read.ReadFailedException;
24 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
25 import io.fd.honeycomb.translate.vpp.util.NamingContext;
26 import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest;
27 import java.util.List;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.mockito.Mockito;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.LocatorSets;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.LocatorSet;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.LocatorSetBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.LocatorSetKey;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.locator.set.Interface;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.locator.set.InterfaceBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.locator.set.InterfaceKey;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
39 import io.fd.vpp.jvpp.core.dto.LispLocatorDetails;
40 import io.fd.vpp.jvpp.core.dto.LispLocatorDetailsReplyDump;
42 public class InterfaceCustomizerTest
43 extends ListReaderCustomizerTest<Interface, InterfaceKey, InterfaceBuilder> {
45 public InterfaceCustomizerTest() {
46 super(Interface.class, LocatorSetBuilder.class);
49 private InstanceIdentifier<Interface> validId;
53 validId = InstanceIdentifier.create(LocatorSets.class).child(LocatorSet.class, new LocatorSetKey("loc-set-1"))
54 .child(Interface.class, new InterfaceKey("interface-1"));
62 private void defineDumpData() {
63 final LispLocatorDetailsReplyDump dump = new LispLocatorDetailsReplyDump();
65 final LispLocatorDetails detail1 = new LispLocatorDetails();
66 detail1.swIfIndex = 1;
67 detail1.ipAddress = new byte[]{-64, -88, 2, 1};
73 final LispLocatorDetails detail2 = new LispLocatorDetails();
74 detail2.swIfIndex = 2;
75 detail2.ipAddress = new byte[]{-64, -88, 2, 2};
81 dump.lispLocatorDetails = ImmutableList.of(detail1, detail2);
83 when(api.lispLocatorDump(Mockito.any())).thenReturn(future(dump));
86 private void defineMappings() {
87 defineMapping(mappingContext, "interface-1", 1, "interface-context");
88 defineMapping(mappingContext, "interface-2", 2, "interface-context");
89 defineMapping(mappingContext, "loc-set-1", 3, "locator-set-context");
93 public void testGetAllIds() throws ReadFailedException {
95 final List<InterfaceKey> keys = getCustomizer().getAllIds(validId, ctx);
97 assertEquals(2, keys.size());
98 assertEquals("interface-1", keys.get(0).getInterfaceRef());
99 assertEquals("interface-2", keys.get(1).getInterfaceRef());
103 public void testReadCurrentAttributes() throws ReadFailedException {
104 InterfaceBuilder builder = new InterfaceBuilder();
105 getCustomizer().readCurrentAttributes(validId, builder, ctx);
107 final Interface iface = builder.build();
108 assertEquals("interface-1", iface.getInterfaceRef());
109 assertEquals("interface-1", iface.getKey().getInterfaceRef());
114 protected ReaderCustomizer<Interface, InterfaceBuilder> initCustomizer() {
115 return new InterfaceCustomizer(api, new NamingContext("interface", "interface-context"),
116 new NamingContext("loc-set", "locator-set-context"));