d540dfa3b919684507cd373ae37f446738a23244
[hc2vpp.git] /
1 /*
2  * Copyright (c) 2017 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 package io.fd.hc2vpp.v3po.interfacesstate.ip.v4;
17
18 import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest;
19 import io.fd.hc2vpp.v3po.interfacesstate.ip.InterfaceChildNodeTest;
20 import io.fd.honeycomb.translate.read.ReadFailedException;
21 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
22 import org.junit.Test;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4Builder;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Neighbor;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.NeighborBuilder;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.NeighborKey;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33
34 import java.util.Arrays;
35
36 import static org.junit.Assert.assertEquals;
37
38 public class Ipv4NeighbourCustomizerTest extends ListReaderCustomizerTest<Neighbor, NeighborKey, NeighborBuilder>
39         implements InterfaceChildNodeTest {
40
41     private InstanceIdentifier<Neighbor> instanceIdentifier;
42
43     public Ipv4NeighbourCustomizerTest() {
44         super(Neighbor.class, Ipv4Builder.class);
45     }
46
47     @Override
48     protected void setUp() throws Exception {
49         instanceIdentifier = InstanceIdentifier.create(InterfacesState.class)
50                 .child(Interface.class, new InterfaceKey(IFACE_NAME))
51                 .augmentation(Interface2.class)
52                 .child(Ipv4.class)
53                 .child(Neighbor.class, new NeighborKey(IPV4_ONE_ADDRESS));
54         defineMapping(mappingContext, IFACE_NAME, IFACE_ID, INTERFACE_CONTEXT_NAME);
55         mockNeighborDump(api, dumpV4NeighborIfaceOne(), v4Neighbors());
56     }
57
58     @Test
59     public void testGetAll() throws ReadFailedException {
60         verifyList(Arrays.asList(new NeighborKey(IPV4_ONE_ADDRESS), new NeighborKey(IPV4_TWO_ADDRESS)),
61                 getCustomizer().getAllIds(instanceIdentifier, ctx));
62     }
63
64     @Test
65     public void readCurrent() throws ReadFailedException {
66         final NeighborBuilder builder = new NeighborBuilder();
67         getCustomizer().readCurrentAttributes(instanceIdentifier, builder, ctx);
68
69         assertEquals(IPV4_ONE_ADDRESS, builder.getIp());
70         assertEquals(MAC_ONE_ADDRESS, builder.getLinkLayerAddress());
71     }
72
73     @Override
74     protected ReaderCustomizer<Neighbor, NeighborBuilder> initCustomizer() {
75         return new Ipv4NeighbourCustomizer(api, INTERFACE_CONTEXT);
76     }
77 }