2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding.generator.impl;
10 import static org.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertNotNull;
15 import java.util.List;
16 import org.junit.Test;
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.JavaTypeName;
21 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
22 import org.opendaylight.mdsal.binding.model.ri.Types;
23 import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
24 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
25 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
27 public class AugmentedTypeTest {
29 public void augmentedAbstractTopologyTest() {
30 final EffectiveModelContext 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);
38 final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(context);
39 assertEquals(28, genTypes.size());
41 GeneratedTransferObject gtInterfaceKey = null;
42 GeneratedType gtInterface = null;
43 GeneratedType gtTunnel = null;
44 GeneratedTransferObject gtTunnelKey = null;
45 GeneratedType gtNetworkLink2 = null;
47 for (final GeneratedType type : genTypes) {
48 if (!type.getPackageName().contains("augment._abstract.topology")) {
52 if (type.getName().equals("InterfaceKey")) {
53 gtInterfaceKey = (GeneratedTransferObject) type;
54 } else if (type.getName().equals("Interface")) {
56 } else if (type.getName().equals("Tunnel")) {
58 } else if (type.getName().equals("TunnelKey")) {
59 gtTunnelKey = (GeneratedTransferObject) type;
60 } else if (type.getName().equals("NetworkLink2")) {
61 gtNetworkLink2 = type;
66 assertNotNull("gtInterface is null", gtInterface);
67 final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
68 assertNotNull("gtInterfaceMethods is null", gtInterfaceMethods);
69 MethodSignature getIfcKeyMethod = null;
70 for (final MethodSignature method : gtInterfaceMethods) {
71 if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
72 getIfcKeyMethod = method;
76 assertNotNull("getIfcKeyMethod is null", getIfcKeyMethod);
77 assertThat(getIfcKeyMethod.getReturnType(), instanceOf(GeneratedTransferObject.class));
78 assertEquals(JavaTypeName.create(
79 "org.opendaylight.yang.gen.v1.urn.model.augment._abstract.topology.rev130503.topology.interfaces",
80 "InterfaceKey"), getIfcKeyMethod.getReturnType().getIdentifier());
82 MethodSignature getHigherLayerIfMethod = null;
83 for (final MethodSignature method : gtInterfaceMethods) {
84 if (method.getName().equals("getHigherLayerIf")) {
85 getHigherLayerIfMethod = method;
89 assertNotNull("getHigherLayerIf method is null", getHigherLayerIfMethod);
90 assertEquals(Types.listTypeFor(Types.STRING), getHigherLayerIfMethod.getReturnType());
93 assertNotNull("InterfaceKey is null", gtInterfaceKey);
94 final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
95 assertNotNull("properties is null", properties);
96 GeneratedProperty gtInterfaceId = null;
97 for (final GeneratedProperty property : properties) {
98 if (property.getName().equals("interfaceId")) {
99 gtInterfaceId = property;
103 assertNotNull("interfaceId is null", gtInterfaceId);
104 assertEquals(Types.STRING, gtInterfaceId.getReturnType());
107 assertNotNull("Tunnel is null", gtTunnel);
108 final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
109 assertNotNull("Tunnel methods are null", tunnelMethods);
110 MethodSignature getTunnelKeyMethod = null;
111 for (MethodSignature method : tunnelMethods) {
112 if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
113 getTunnelKeyMethod = method;
117 assertNotNull("getKey method of Tunnel is null", getTunnelKeyMethod);
119 var retType = getTunnelKeyMethod.getReturnType();
120 assertThat(retType, instanceOf(GeneratedTransferObject.class));
121 assertEquals(JavaTypeName.create("org.opendaylight.yang.gen.v1.urn.model.augment._abstract.topology.rev130503"
122 + ".topology.network.links.network.link.tunnels", "TunnelKey"), retType.getIdentifier());
125 assertNotNull("TunnelKey is null", gtTunnelKey);
126 final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
127 assertNotNull("TunnelKey properties are null", tunnelKeyProperties);
129 GeneratedProperty gtTunnelId = null;
130 for (final GeneratedProperty property : tunnelKeyProperties) {
131 if (property.getName().equals("tunnelId")) {
132 gtTunnelId = property;
135 assertNotNull("tunnelId is null", gtTunnelId);
136 assertEquals(Types.typeForClass(Integer.class), gtTunnelId.getReturnType());
139 assertNotNull("NetworkLink2 is null", gtNetworkLink2);
141 final List<MethodSignature> networkLink2Methods = gtNetworkLink2.getMethodDefinitions();
142 assertNotNull("NetworkLink2 methods are null", networkLink2Methods);
144 MethodSignature getIfcMethod = null;
145 for (MethodSignature method : networkLink2Methods) {
146 if (method.getName().equals("getInterface")) {
147 getIfcMethod = method;
152 assertNotNull("getInterface method is null", getIfcMethod);
153 assertEquals(Types.STRING, getIfcMethod.getReturnType());