adcbdb6433a116e1ad01a7801ae8845cabefc4b5
[honeycomb.git] / lisp / lisp2vpp / src / test / java / io / fd / honeycomb / lisp / translate / read / MapResolverCustomizerTest.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.vpp.test.read.ListReaderCustomizerTest;
27 import io.fd.vpp.jvpp.core.dto.LispMapResolverDetails;
28 import io.fd.vpp.jvpp.core.dto.LispMapResolverDetailsReplyDump;
29 import java.util.List;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.map.resolvers.grouping.MapResolvers;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.map.resolvers.grouping.MapResolversBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.map.resolvers.grouping.map.resolvers.MapResolver;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.map.resolvers.grouping.map.resolvers.MapResolverBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.map.resolvers.grouping.map.resolvers.MapResolverKey;
39 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
40
41
42 public class MapResolverCustomizerTest
43         extends ListReaderCustomizerTest<MapResolver, MapResolverKey, MapResolverBuilder> {
44
45     private static final IpAddress IP_ADDRESS_REVERTED =
46             new IpAddress(new Ipv4AddressNoZone("1.2.168.192"));
47
48     private InstanceIdentifier<MapResolver> emptyId;
49     private InstanceIdentifier<MapResolver> validId;
50
51     public MapResolverCustomizerTest() {
52         super(MapResolver.class, MapResolversBuilder.class);
53     }
54
55     @Before
56     public void init() {
57
58         emptyId = InstanceIdentifier.create(MapResolver.class);
59         validId = InstanceIdentifier.create(MapResolvers.class)
60                 .child(MapResolver.class, new MapResolverKey(IP_ADDRESS_REVERTED));
61         defineDumpData();
62     }
63
64     @Test
65     public void readCurrentAttributes() throws Exception {
66         MapResolverBuilder builder = new MapResolverBuilder();
67         getCustomizer().readCurrentAttributes(validId, builder, ctx);
68
69         MapResolver resolver = builder.build();
70         assertNotNull(resolver);
71         assertEquals("1.2.168.192", resolver.getIpAddress().getIpv4Address().getValue());
72     }
73
74     @Test
75     public void getAllIds() throws Exception {
76         final List<MapResolverKey> keys = getCustomizer().getAllIds(emptyId, ctx);
77
78         assertEquals(1, keys.size());
79
80         final MapResolverKey key = keys.get(0);
81         assertNotNull(key);
82         assertEquals("1.2.168.192", new String(key.getIpAddress().getValue()));
83
84     }
85
86     private void defineDumpData() {
87         final LispMapResolverDetailsReplyDump replyDump = new LispMapResolverDetailsReplyDump();
88         final LispMapResolverDetails detail = new LispMapResolverDetails();
89         detail.context = 5;
90         detail.ipAddress = new byte[]{1, 2, -88, -64};
91         detail.isIpv6 = 0;
92
93         replyDump.lispMapResolverDetails = ImmutableList.of(detail);
94
95         when(api.lispMapResolverDump(any())).thenReturn(future(replyDump));
96     }
97
98     @Override
99     protected ReaderCustomizer<MapResolver, MapResolverBuilder> initCustomizer() {
100         return new MapResolverCustomizer(api);
101     }
102 }