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