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