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.junit.Assert.assertNotNull;
21 import static org.mockito.Matchers.any;
22 import static org.mockito.Mockito.when;
24 import com.google.common.collect.ImmutableList;
25 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
26 import io.fd.honeycomb.translate.vpp.util.NamingContext;
27 import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest;
28 import java.nio.charset.StandardCharsets;
29 import java.util.List;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.LocatorSets;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.LocatorSetsBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.LocatorSet;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.LocatorSetBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.LocatorSetKey;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
38 import io.fd.vpp.jvpp.core.dto.LispLocatorSetDetails;
39 import io.fd.vpp.jvpp.core.dto.LispLocatorSetDetailsReplyDump;
42 public class LocatorSetCustomizerTest
43 extends ListReaderCustomizerTest<LocatorSet, LocatorSetKey, LocatorSetBuilder> {
45 private InstanceIdentifier<LocatorSet> emptyId;
46 private InstanceIdentifier<LocatorSet> validId;
48 public LocatorSetCustomizerTest() {
49 super(LocatorSet.class, LocatorSetsBuilder.class);
54 emptyId = InstanceIdentifier.create(LocatorSet.class);
55 validId = InstanceIdentifier.create(LocatorSets.class).child(LocatorSet.class, new LocatorSetKey("loc-set"));
58 defineMapping(mappingContext, "loc-set", 1, "locator-set-context");
61 private void defineDumpData() {
62 LispLocatorSetDetailsReplyDump dump = new LispLocatorSetDetailsReplyDump();
63 LispLocatorSetDetails detail = new LispLocatorSetDetails();
65 detail.lsName = "loc-set".getBytes(StandardCharsets.UTF_8);
68 dump.lispLocatorSetDetails = ImmutableList.of(detail);
70 when(api.lispLocatorSetDump(any())).thenReturn(future(dump));
75 public void readCurrentAttributes() throws Exception {
76 LocatorSetBuilder builder = new LocatorSetBuilder();
77 getCustomizer().readCurrentAttributes(validId, builder, ctx);
79 assertNotNull(builder);
80 assertEquals("loc-set", builder.getName());
81 assertEquals("loc-set", builder.getKey().getName());
85 public void getAllIds() throws Exception {
86 final List<LocatorSetKey> keys = getCustomizer().getAllIds(emptyId, ctx);
88 assertEquals(1, keys.size());
89 assertEquals("loc-set", keys.get(0).getName());
93 protected ReaderCustomizer<LocatorSet, LocatorSetBuilder> initCustomizer() {
94 return new LocatorSetCustomizer(api, new NamingContext("loc", "locator-set-context"));