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