Update BindingRuntime{Context,Generator,Types}
[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.model.api.GeneratedProperty;
17 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
18 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
19 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
20 import org.opendaylight.mdsal.binding.model.api.Type;
21 import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
22 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
23 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
24
25 public class AugmentedTypeTest {
26
27     @Test
28     public void augmentedAbstractTopologyTest() {
29         final EffectiveModelContext context = YangParserTestUtils.parseYangResources(AugmentedTypeTest.class,
30             "/augment-test-models/abstract-topology@2013-02-08.yang",
31             "/augment-test-models/augment-abstract-topology@2013-05-03.yang",
32             "/augment-test-models/augment-network-link-attributes@2013-05-03.yang",
33             "/augment-test-models/augment-topology-tunnels@2013-05-03.yang",
34             "/augment-test-models/ietf-interfaces@2012-11-15.yang");
35         assertNotNull("Schema Context is null", context);
36
37         final List<Type> genTypes = DefaultBindingGenerator.generateFor(context);
38
39         assertNotNull("genTypes is null", genTypes);
40         assertFalse("genTypes is empty", genTypes.isEmpty());
41
42         GeneratedTransferObject gtInterfaceKey = null;
43         GeneratedType gtInterface = null;
44         GeneratedType gtTunnel = null;
45         GeneratedTransferObject gtTunnelKey = null;
46         GeneratedType gtNetworkLink2 = null;
47
48         for (final Type type : genTypes) {
49             if (!type.getPackageName().contains("augment._abstract.topology")) {
50                 continue;
51             }
52
53             if (type.getName().equals("InterfaceKey")) {
54                 gtInterfaceKey = (GeneratedTransferObject) type;
55             } else if (type.getName().equals("Interface")) {
56                 gtInterface = (GeneratedType) type;
57             } else if (type.getName().equals("Tunnel")) {
58                 gtTunnel = (GeneratedType) type;
59             } else if (type.getName().equals("TunnelKey")) {
60                 gtTunnelKey = (GeneratedTransferObject) type;
61             } else if (type.getName().equals("NetworkLink2")) {
62                 gtNetworkLink2 = (GeneratedType) type;
63             }
64         }
65
66         // 'Interface
67         assertNotNull("gtInterface is null", gtInterface);
68         final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
69         assertNotNull("gtInterfaceMethods is null", gtInterfaceMethods);
70         MethodSignature getIfcKeyMethod = null;
71         for (final MethodSignature method : gtInterfaceMethods) {
72             if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
73                 getIfcKeyMethod = method;
74                 break;
75             }
76         }
77         assertNotNull("getIfcKeyMethod is null", getIfcKeyMethod);
78         assertNotNull("getIfcKeyMethod.getReturnType() is null", getIfcKeyMethod.getReturnType());
79         assertFalse("getIfcKeyMethod.getReturnType() should not be Void",
80                 getIfcKeyMethod.getReturnType().equals("java.lang.Void"));
81         assertTrue("getIfcKeyMethod.getReturnType().getName() must be InterfaceKey", getIfcKeyMethod.getReturnType()
82                 .getName().equals("InterfaceKey"));
83
84         MethodSignature getHigherLayerIfMethod = null;
85         for (final MethodSignature method : gtInterfaceMethods) {
86             if (method.getName().equals("getHigherLayerIf")) {
87                 getHigherLayerIfMethod = method;
88                 break;
89             }
90         }
91         assertNotNull("getHigherLayerIf method is null", getHigherLayerIfMethod);
92         assertNotNull("getHigherLayerIf method return type is null", getHigherLayerIfMethod.getReturnType());
93         assertTrue("getHigherLayerIf method return type name must be List", getHigherLayerIfMethod.getReturnType()
94                 .getName().equals("List"));
95
96         // 'InterfaceKey'
97         assertNotNull("InterfaceKey is null", gtInterfaceKey);
98         final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
99         assertNotNull("properties is null", properties);
100         GeneratedProperty gtInterfaceId = null;
101         for (final GeneratedProperty property : properties) {
102             if (property.getName().equals("interfaceId")) {
103                 gtInterfaceId = property;
104                 break;
105             }
106         }
107         assertNotNull("interfaceId is null", gtInterfaceId);
108         assertNotNull("interfaceId return type is null", gtInterfaceId.getReturnType());
109         assertTrue("interfaceId return type name must be String",
110                 gtInterfaceId.getReturnType().getName().equals("String"));
111
112         // 'Tunnel'
113         assertNotNull("Tunnel is null", gtTunnel);
114         final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
115         assertNotNull("Tunnel methods are null", tunnelMethods);
116         MethodSignature getTunnelKeyMethod = null;
117         for (MethodSignature method : tunnelMethods) {
118             if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
119                 getTunnelKeyMethod = method;
120                 break;
121             }
122         }
123         assertNotNull("getKey method of Tunnel is null", getTunnelKeyMethod);
124         assertNotNull("getKey method return type is null", getTunnelKeyMethod.getReturnType());
125         assertTrue("getKey method return type name must be TunnelKey", getTunnelKeyMethod.getReturnType().getName()
126                 .equals("TunnelKey"));
127
128         // 'TunnelKey'
129         assertNotNull("TunnelKey is null", gtTunnelKey);
130         final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
131         assertNotNull("TunnelKey properties are null", tunnelKeyProperties);
132
133         GeneratedProperty gtTunnelId = null;
134         for (final GeneratedProperty property : tunnelKeyProperties) {
135             if (property.getName().equals("tunnelId")) {
136                 gtTunnelId = property;
137             }
138         }
139         assertNotNull("tunnelId is null", gtTunnelId);
140         assertNotNull("tunnelId return type is null", gtTunnelId.getReturnType());
141         assertTrue("tunnelId returnType name must be Integer", gtTunnelId.getReturnType().getName().equals("Integer"));
142
143         // 'NetworkLink2'
144         assertNotNull("NetworkLink2 is null", gtNetworkLink2);
145
146         final List<MethodSignature> networkLink2Methods = gtNetworkLink2.getMethodDefinitions();
147         assertNotNull("NetworkLink2 methods are null", networkLink2Methods);
148
149         MethodSignature getIfcMethod = null;
150         for (MethodSignature method : networkLink2Methods) {
151             if (method.getName().equals("getInterface")) {
152                 getIfcMethod = method;
153                 break;
154             }
155         }
156
157         assertNotNull("getInterface method is null", getIfcMethod);
158         assertNotNull("getInterface method return type is null", getIfcMethod.getReturnType());
159         assertTrue("getInterface method return type name must be String", getIfcMethod.getReturnType().getName()
160                 .equals("String"));
161     }
162
163     @Test
164     public void augmentedNetworkLinkTest() {
165
166     }
167
168     @Test
169     public void augmentedTopologyTunnelsTest() {
170
171     }
172
173 }