HONEYCOMB-154: update revison of models that changed since 16.09
[honeycomb.git] / lisp / lisp2vpp / src / test / java / io / fd / honeycomb / lisp / context / util / EidMappingContextTest.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.context.util;
18
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertTrue;
22
23 import io.fd.honeycomb.lisp.util.EidMappingContextHelper;
24 import io.fd.honeycomb.translate.MappingContext;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.Mock;
28 import org.mockito.MockitoAnnotations;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.MappingId;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.local.mappings.local.mapping.Eid;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder;
35
36 public class EidMappingContextTest implements EidMappingContextHelper {
37
38     private static final String EID_MAPPING_CONTEXT_NAME = "eidMappingContext";
39
40     @Mock
41     private MappingContext mappingContext;
42
43     private EidMappingContext eidMappingContext;
44     private Eid localEid;
45     private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.remote.mapping.Eid
46             remoteEid;
47     private org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid
48             mappingEid;
49     private MappingId mappingId;
50
51     @Before
52     public void init() {
53         MockitoAnnotations.initMocks(this);
54         eidMappingContext = new EidMappingContext(EID_MAPPING_CONTEXT_NAME);
55
56         localEid =
57                 new EidBuilder().setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build()).build();
58         remoteEid = fromLocalToRemoteEid(localEid);
59         mappingEid = fromLocalToMappingEid(localEid);
60         mappingId = new MappingId("mapping");
61
62         defineMapping(mappingContext, mappingEid, mappingId, EID_MAPPING_CONTEXT_NAME);
63     }
64
65     @Test
66     public void testContainsEid() {
67         assertTrue(eidMappingContext.containsEid(mappingId, mappingContext));
68         org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid
69                 loadedEid = eidMappingContext.getEid(mappingId, mappingContext);
70
71         assertEquals("192.168.2.1", ((Ipv4) (loadedEid.getAddress())).getIpv4().getValue());
72     }
73
74     @Test
75     public void testContainsId() {
76         assertTrue(eidMappingContext.containsId(localEid, mappingContext));
77         assertTrue(eidMappingContext.containsId(remoteEid, mappingContext));
78     }
79
80     @Test
81     public void testGetEid() {
82         assertEquals(mappingEid, eidMappingContext.getEid(mappingId, mappingContext));
83     }
84
85     @Test
86     public void testGetId() {
87         assertEquals(mappingId, eidMappingContext.getId(localEid, mappingContext));
88         assertEquals(mappingId, eidMappingContext.getId(remoteEid, mappingContext));
89     }
90
91     private org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid fromLocalToMappingEid(
92             Eid eid) {
93         return new org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.EidBuilder()
94                 .setAddress(eid.getAddress())
95                 .setAddressType(eid.getAddressType())
96                 .setVirtualNetworkId(eid.getVirtualNetworkId())
97                 .build();
98     }
99
100     private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.remote.mapping.Eid fromLocalToRemoteEid(
101             Eid eid) {
102         return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder()
103                 .setAddress(eid.getAddress())
104                 .setAddressType(eid.getAddressType())
105                 .setVirtualNetworkId(eid.getVirtualNetworkId())
106                 .build();
107     }
108 }