e863ba2bbab05bc7f7942d98790e79a86c5899b7
[honeycomb.git] / lisp / lisp2vpp / src / test / java / io / fd / honeycomb / lisp / translate / read / LocatorSetCustomizerTest.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;
18
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;
23
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;
40
41
42 public class LocatorSetCustomizerTest
43         extends ListReaderCustomizerTest<LocatorSet, LocatorSetKey, LocatorSetBuilder> {
44
45     private InstanceIdentifier<LocatorSet> emptyId;
46     private InstanceIdentifier<LocatorSet> validId;
47
48     public LocatorSetCustomizerTest() {
49         super(LocatorSet.class, LocatorSetsBuilder.class);
50     }
51
52     @Before
53     public void init() {
54         emptyId = InstanceIdentifier.create(LocatorSet.class);
55         validId = InstanceIdentifier.create(LocatorSets.class).child(LocatorSet.class, new LocatorSetKey("loc-set"));
56
57         defineDumpData();
58         defineMapping(mappingContext, "loc-set", 1, "locator-set-context");
59     }
60
61     private void defineDumpData() {
62         LispLocatorSetDetailsReplyDump dump = new LispLocatorSetDetailsReplyDump();
63         LispLocatorSetDetails detail = new LispLocatorSetDetails();
64         detail.context = 4;
65         detail.lsName = "loc-set".getBytes(StandardCharsets.UTF_8);
66         detail.lsIndex = 1;
67
68         dump.lispLocatorSetDetails = ImmutableList.of(detail);
69
70         when(api.lispLocatorSetDump(any())).thenReturn(future(dump));
71     }
72
73
74     @Test
75     public void readCurrentAttributes() throws Exception {
76         LocatorSetBuilder builder = new LocatorSetBuilder();
77         getCustomizer().readCurrentAttributes(validId, builder, ctx);
78
79         assertNotNull(builder);
80         assertEquals("loc-set", builder.getName());
81         assertEquals("loc-set", builder.getKey().getName());
82     }
83
84     @Test
85     public void getAllIds() throws Exception {
86         final List<LocatorSetKey> keys = getCustomizer().getAllIds(emptyId, ctx);
87
88         assertEquals(1, keys.size());
89         assertEquals("loc-set", keys.get(0).getName());
90     }
91
92     @Override
93     protected ReaderCustomizer<LocatorSet, LocatorSetBuilder> initCustomizer() {
94         return new LocatorSetCustomizer(api, new NamingContext("loc", "locator-set-context"));
95     }
96 }