3dc74a3e550c8842b93ccf54cc849a3ab74e0d20
[hc2vpp.git] /
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.translate.v3po.initializers;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.mockito.MockitoAnnotations.initMocks;
21
22 import java.util.Arrays;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.mockito.Mock;
26 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.EthernetCsmacd;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfaceType;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesBuilder;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesStateBuilder;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
34
35 public class InterfacesInitializerTest {
36
37     @Mock
38     private DataBroker bindingDataBroker;
39
40     private InterfacesInitializer interfacesInitializer;
41
42     @Before
43     public void setUp() {
44         initMocks(this);
45         interfacesInitializer = new InterfacesInitializer(bindingDataBroker);
46     }
47
48     @Test
49     public void testConvert() throws Exception {
50         final InterfacesState operationalData = operationalData();
51         final Interfaces expectedConfigData = expectedConfigData();
52
53         final Interfaces configData = interfacesInitializer.convert(operationalData);
54         assertEquals(expectedConfigData, configData);
55     }
56
57     private org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface operInterface(
58             String name, Class<? extends InterfaceType> inerfaceType, Interface.AdminStatus adminStatus) {
59         final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder
60                 iface =
61                 new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder();
62         iface.setKey(
63                 new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey(
64                         name));
65         iface.setName(name);
66         iface.setType(inerfaceType);
67         iface.setAdminStatus(adminStatus);
68         return iface.build();
69     }
70
71     private InterfacesState operationalData() {
72         final InterfacesStateBuilder builder = new InterfacesStateBuilder();
73         builder.setInterface(
74                 Arrays.asList(
75                         operInterface("eth1", EthernetCsmacd.class, Interface.AdminStatus.Up),
76                         operInterface("eth2", EthernetCsmacd.class, Interface.AdminStatus.Down)
77                 ));
78         return builder.build();
79     }
80
81     private org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface configInterface(
82             String name, Class<? extends InterfaceType> inerfaceType, boolean isEnabled) {
83         final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder
84                 iface =
85                 new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder();
86         iface.setKey(
87                 new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey(
88                         name));
89         iface.setName(name);
90         iface.setType(inerfaceType);
91         iface.setEnabled(isEnabled);
92         return iface.build();
93     }
94
95     private Interfaces expectedConfigData() {
96         final InterfacesBuilder builder = new InterfacesBuilder();
97
98         builder.setInterface(
99                 Arrays.asList(
100                         configInterface("eth1", EthernetCsmacd.class, true),
101                         configInterface("eth2", EthernetCsmacd.class, false)
102                 ));
103         return builder.build();
104     }
105
106 }