7cfecf88bfb9f55872f2a160a4f539886db07572
[mdsal.git] / binding / mdsal-binding-generator-impl / src / test / java / org / opendaylight / mdsal / binding / generator / impl / AugmentedTypeTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.mdsal.binding.generator.impl;
9
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13
14 import java.util.List;
15 import org.junit.Test;
16 import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
17 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
18 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
19 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
20 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
21 import org.opendaylight.mdsal.binding.model.api.Type;
22 import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25
26 public class AugmentedTypeTest {
27
28     @Test
29     public void augmentedAbstractTopologyTest() {
30         final SchemaContext context = YangParserTestUtils.parseYangResources(AugmentedTypeTest.class,
31             "/augment-test-models/abstract-topology@2013-02-08.yang",
32             "/augment-test-models/augment-abstract-topology@2013-05-03.yang",
33             "/augment-test-models/augment-network-link-attributes@2013-05-03.yang",
34             "/augment-test-models/augment-topology-tunnels@2013-05-03.yang",
35             "/augment-test-models/ietf-interfaces@2012-11-15.yang");
36         assertNotNull("Schema Context is null", context);
37
38         final BindingGenerator bindingGen = new BindingGeneratorImpl();
39         final List<Type> genTypes = bindingGen.generateTypes(context);
40
41         assertNotNull("genTypes is null", genTypes);
42         assertFalse("genTypes is empty", genTypes.isEmpty());
43
44         GeneratedTransferObject gtInterfaceKey = null;
45         GeneratedType gtInterface = null;
46         GeneratedType gtTunnel = null;
47         GeneratedTransferObject gtTunnelKey = null;
48         GeneratedType gtNetworkLink2 = null;
49
50         for (final Type type : genTypes) {
51             if (type.getName().equals("InterfaceKey") && type.getPackageName().contains("augment._abstract.topology")) {
52                 gtInterfaceKey = (GeneratedTransferObject) type;
53             } else if (type.getName().equals("Interface")
54                     && type.getPackageName().contains("augment._abstract.topology")) {
55                 gtInterface = (GeneratedType) type;
56             } else if (type.getName().equals("Tunnel") && type.getPackageName().contains("augment._abstract.topology")) {
57                 gtTunnel = (GeneratedType) type;
58             } else if (type.getName().equals("TunnelKey")
59                     && type.getPackageName().contains("augment._abstract.topology")) {
60                 gtTunnelKey = (GeneratedTransferObject) type;
61             } else if (type.getName().equals("NetworkLink2")
62                     && type.getPackageName().contains("augment._abstract.topology")) {
63                 gtNetworkLink2 = (GeneratedType) type;
64             }
65         }
66
67         // 'Interface
68         assertNotNull("gtInterface is null", gtInterface);
69         final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
70         assertNotNull("gtInterfaceMethods is null", gtInterfaceMethods);
71         MethodSignature getIfcKeyMethod = null;
72         for (final MethodSignature method : gtInterfaceMethods) {
73             if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
74                 getIfcKeyMethod = method;
75                 break;
76             }
77         }
78         assertNotNull("getIfcKeyMethod is null", getIfcKeyMethod);
79         assertNotNull("getIfcKeyMethod.getReturnType() is null", getIfcKeyMethod.getReturnType());
80         assertFalse("getIfcKeyMethod.getReturnType() should not be Void",
81                 getIfcKeyMethod.getReturnType().equals("java.lang.Void"));
82         assertTrue("getIfcKeyMethod.getReturnType().getName() must be InterfaceKey", getIfcKeyMethod.getReturnType()
83                 .getName().equals("InterfaceKey"));
84
85         MethodSignature getHigherLayerIfMethod = null;
86         for (final MethodSignature method : gtInterfaceMethods) {
87             if (method.getName().equals("getHigherLayerIf")) {
88                 getHigherLayerIfMethod = method;
89                 break;
90             }
91         }
92         assertNotNull("getHigherLayerIf method is null", getHigherLayerIfMethod);
93         assertNotNull("getHigherLayerIf method return type is null", getHigherLayerIfMethod.getReturnType());
94         assertTrue("getHigherLayerIf method return type name must be List", getHigherLayerIfMethod.getReturnType()
95                 .getName().equals("List"));
96
97         // 'InterfaceKey'
98         assertNotNull("InterfaceKey is null", gtInterfaceKey);
99         final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
100         assertNotNull("properties is null", properties);
101         GeneratedProperty gtInterfaceId = null;
102         for (final GeneratedProperty property : properties) {
103             if (property.getName().equals("interfaceId")) {
104                 gtInterfaceId = property;
105                 break;
106             }
107         }
108         assertNotNull("interfaceId is null", gtInterfaceId);
109         assertNotNull("interfaceId return type is null", gtInterfaceId.getReturnType());
110         assertTrue("interfaceId return type name must be String",
111                 gtInterfaceId.getReturnType().getName().equals("String"));
112
113         // 'Tunnel'
114         assertNotNull("Tunnel is null", gtTunnel);
115         final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
116         assertNotNull("Tunnel methods are null", tunnelMethods);
117         MethodSignature getTunnelKeyMethod = null;
118         for (MethodSignature method : tunnelMethods) {
119             if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
120                 getTunnelKeyMethod = method;
121                 break;
122             }
123         }
124         assertNotNull("getKey method of Tunnel is null", getTunnelKeyMethod);
125         assertNotNull("getKey method return type is null", getTunnelKeyMethod.getReturnType());
126         assertTrue("getKey method return type name must be TunnelKey", getTunnelKeyMethod.getReturnType().getName()
127                 .equals("TunnelKey"));
128
129         // 'TunnelKey'
130         assertNotNull("TunnelKey is null", gtTunnelKey);
131         final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
132         assertNotNull("TunnelKey properties are null", tunnelKeyProperties);
133
134         GeneratedProperty gtTunnelId = null;
135         for (final GeneratedProperty property : tunnelKeyProperties) {
136             if (property.getName().equals("tunnelId")) {
137                 gtTunnelId = property;
138             }
139         }
140         assertNotNull("tunnelId is null", gtTunnelId);
141         assertNotNull("tunnelId return type is null", gtTunnelId.getReturnType());
142         assertTrue("tunnelId returnType name must be Integer", gtTunnelId.getReturnType().getName().equals("Integer"));
143
144         // 'NetworkLink2'
145         assertNotNull("NetworkLink2 is null", gtNetworkLink2);
146
147         final List<MethodSignature> networkLink2Methods = gtNetworkLink2.getMethodDefinitions();
148         assertNotNull("NetworkLink2 methods are null", networkLink2Methods);
149
150         MethodSignature getIfcMethod = null;
151         for (MethodSignature method : networkLink2Methods) {
152             if (method.getName().equals("getInterface")) {
153                 getIfcMethod = method;
154                 break;
155             }
156         }
157
158         assertNotNull("getInterface method is null", getIfcMethod);
159         assertNotNull("getInterface method return type is null", getIfcMethod.getReturnType());
160         assertTrue("getInterface method return type name must be String", getIfcMethod.getReturnType().getName()
161                 .equals("String"));
162     }
163
164     @Test
165     public void augmentedNetworkLinkTest() {
166
167     }
168
169     @Test
170     public void augmentedTopologyTunnelsTest() {
171
172     }
173
174 }