52abdf8186efca87b3677ed00661021e15e988a5
[honeycomb.git] / lisp / lisp2vpp / src / test / java / io / fd / honeycomb / lisp / translate / read / PitrCfgCustomizerTest.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 io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
25 import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest;
26 import java.nio.charset.StandardCharsets;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.LispStateBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.lisp.feature.data.grouping.LispFeatureDataBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.pitr.cfg.grouping.PitrCfg;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.pitr.cfg.grouping.PitrCfgBuilder;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 import io.fd.vpp.jvpp.core.dto.ShowLispPitrReply;
35
36
37 public class PitrCfgCustomizerTest extends ReaderCustomizerTest<PitrCfg, PitrCfgBuilder> {
38
39     private static final byte[] LOC_SET_NAME_BYTES = "loc-set".getBytes(StandardCharsets.UTF_8);
40
41     private InstanceIdentifier<PitrCfg> emptyId;
42
43     public PitrCfgCustomizerTest() {
44         super(PitrCfg.class, LispFeatureDataBuilder.class);
45     }
46
47     @Before
48     public void init() {
49         emptyId = InstanceIdentifier.create(PitrCfg.class);
50
51         mockDumpData();
52     }
53
54     @Test
55     public void readCurrentAttributes() throws Exception {
56         PitrCfgBuilder builder = new PitrCfgBuilder();
57         getCustomizer().readCurrentAttributes(emptyId, builder, ctx);
58
59         final PitrCfg cfg = builder.build();
60
61         assertNotNull(cfg);
62         assertEquals("loc-set", cfg.getLocatorSet());
63     }
64
65     private void mockDumpData() {
66         ShowLispPitrReply replyDump = new ShowLispPitrReply();
67         replyDump.locatorSetName = LOC_SET_NAME_BYTES;
68         replyDump.status = 1;
69
70         when(api.showLispPitr(any())).thenReturn(future(replyDump));
71     }
72
73     @Override
74     protected ReaderCustomizer<PitrCfg, PitrCfgBuilder> initCustomizer() {
75         return new PitrCfgCustomizer(api);
76     }
77 }