1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/*
* Copyright (c) 2017 Cisco and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fd.hc2vpp.lisp.translate.read;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.vpp.jvpp.core.dto.OneMapServerDetails;
import io.fd.vpp.jvpp.core.dto.OneMapServerDetailsReplyDump;
import io.fd.vpp.jvpp.core.dto.OneMapServerDump;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170808.map.servers.grouping.MapServers;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170808.map.servers.grouping.MapServersBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170808.map.servers.grouping.map.servers.MapServer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170808.map.servers.grouping.map.servers.MapServerBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170808.map.servers.grouping.map.servers.MapServerKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public class MapServerCustomizerTest
extends LispInitializingListReaderCustomizerTest<MapServer, MapServerKey, MapServerBuilder>
implements LispInitTest {
private static final MapServerKey
SERVER_KEY = new MapServerKey(new IpAddress(new Ipv4Address("192.168.2.1")));
private static final InstanceIdentifier<MapServer> STATE_IID = LISP_STATE_FTR_IID.child(MapServers.class)
.child(MapServer.class, SERVER_KEY);
private static final InstanceIdentifier<MapServer> CONFIG_IID = LISP_FTR_IID.child(MapServers.class)
.child(MapServer.class, SERVER_KEY);
public MapServerCustomizerTest() {
super(MapServer.class, MapServersBuilder.class);
}
@Override
@Before
public void setUp() throws Exception {
final OneMapServerDetailsReplyDump reply = new OneMapServerDetailsReplyDump();
OneMapServerDetails server1 = new OneMapServerDetails();
//192.168.2.2
server1.ipAddress = new byte[]{-64, -88, 2, 1};
server1.isIpv6 = 0;
OneMapServerDetails server2 = new OneMapServerDetails();
//192.168.2.2
server2.ipAddress = new byte[]{-64, -88, 2, 2};
server2.isIpv6 = 0;
OneMapServerDetails server3 = new OneMapServerDetails();
//2001:0db8:0a0b:12f0:0000:0000:0000:0001
server3.ipAddress = new byte[]{32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1};
server3.isIpv6 = 1;
reply.oneMapServerDetails = Arrays.asList(server1, server2, server3);
when(api.oneMapServerDump(any(OneMapServerDump.class))).thenReturn(future(reply));
mockLispEnabled();
}
@Test
public void testGetAllIds() throws Exception {
final List<MapServerKey> allIds = getCustomizer().getAllIds(STATE_IID, ctx);
assertThat(allIds, hasSize(3));
assertThat(allIds, containsInAnyOrder(
new MapServerKey(new IpAddress(new Ipv4AddressNoZone("192.168.2.1"))),
new MapServerKey(new IpAddress(new Ipv4AddressNoZone("192.168.2.2"))),
new MapServerKey(new IpAddress(new Ipv6AddressNoZone("2001:db8:a0b:12f0::1")))));
}
@Test
public void testReadCurrentAttributes() throws Exception {
final MapServerBuilder builder = new MapServerBuilder();
getCustomizer().readCurrentAttributes(STATE_IID, builder, ctx);
assertEquals("192.168.2.1", builder.getIpAddress().getIpv4Address().getValue());
}
@Test
public void testInit() {
final MapServer data = new MapServerBuilder().setIpAddress(
new IpAddress(new Ipv4Address("192.168.2.1"))).build();
invokeInitTest(STATE_IID, data, CONFIG_IID, data);
}
@Override
protected ReaderCustomizer<MapServer, MapServerBuilder> initCustomizer() {
return new MapServerCustomizer(api, lispStateCheckService);
}
}
|