2 * Copyright (c) 2013 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.controller.sal.binding.generator.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
16 import java.util.ArrayList;
17 import java.util.List;
20 import org.junit.BeforeClass;
21 import org.junit.Test;
22 import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
23 import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
24 import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
25 import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
26 import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
27 import org.opendaylight.controller.sal.binding.model.api.Type;
28 import org.opendaylight.controller.yang.model.api.Module;
29 import org.opendaylight.controller.yang.model.api.SchemaContext;
30 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
31 import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
33 public class AugmentedTypeTest {
35 private final static List<File> augmentModels = new ArrayList<>();
36 private final static String augmentFolderPath = AugmentedTypeTest.class
37 .getResource("/augment-test-models").getPath();
40 public static void loadTestResources() {
41 final File augFolder = new File(augmentFolderPath);
43 for (final File fileEntry : augFolder.listFiles()) {
44 if (fileEntry.isFile()) {
45 augmentModels.add(fileEntry);
51 public void augmentedAbstractTopologyTest() {
52 final YangModelParser parser = new YangParserImpl();
53 final Set<Module> modules = parser.parseYangModels(augmentModels);
54 final SchemaContext context = parser.resolveSchemaContext(modules);
56 assertNotNull(context);
57 final BindingGenerator bindingGen = new BindingGeneratorImpl();
58 final List<Type> genTypes = bindingGen.generateTypes(context);
60 assertNotNull(genTypes);
61 assertTrue(!genTypes.isEmpty());
63 int resolvedAugmentsCount = 0;
64 for (final Type type : genTypes) {
66 if (type.getName().equals("Topology")) {
67 final GeneratedType absTopologyType = (GeneratedType) type;
68 final List<MethodSignature> methods = absTopologyType
69 .getMethodDefinitions();
70 assertNotNull(methods);
71 assertEquals(4, methods.size());
72 } else if (type.getName().equals("InterfaceKey")
73 && type instanceof GeneratedTransferObject) {
74 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
75 final List<GeneratedProperty> properties = genTO
78 assertTrue(properties != null);
79 for (final GeneratedProperty property : properties) {
80 if (property.getName().equals("InterfaceId")) {
81 assertTrue(property.getReturnType() != null);
82 assertFalse(property.getReturnType().equals(
84 assertTrue(property.getReturnType().getName()
86 resolvedAugmentsCount++;
89 } else if (type.getName().equals("Interface")
90 && type instanceof GeneratedType) {
91 final GeneratedType genType = (GeneratedType) type;
92 final List<MethodSignature> methods = genType
93 .getMethodDefinitions();
95 assertTrue(methods != null);
96 for (final MethodSignature method : methods) {
97 if (method.getName().equals("getInterfaceKey")) {
98 assertTrue(method.getReturnType() != null);
99 assertFalse(method.getReturnType().equals(
101 assertTrue(method.getReturnType().getName()
102 .equals("InterfaceKey"));
103 resolvedAugmentsCount++;
104 } else if (method.getName().equals("getHigherLayerIf")) {
105 assertTrue(method.getReturnType() != null);
106 assertFalse(method.getReturnType().equals(
108 assertTrue(method.getReturnType().getName()
110 resolvedAugmentsCount++;
113 } else if (type.getName().equals("Tunnel")
114 && type instanceof GeneratedType) {
115 final GeneratedType genType = (GeneratedType) type;
116 final List<MethodSignature> methods = genType
117 .getMethodDefinitions();
118 assertTrue(methods != null);
119 for (MethodSignature method : methods) {
120 if (method.getName().equals("getTunnelKey")) {
121 assertTrue(method.getReturnType() != null);
122 assertFalse(method.getReturnType().equals(
124 assertTrue(method.getReturnType().getName()
125 .equals("TunnelKey"));
126 resolvedAugmentsCount++;
129 } else if (type.getName().equals("TunnelKey")
130 && type instanceof GeneratedTransferObject) {
131 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
132 final List<GeneratedProperty> properties = genTO
135 assertTrue(properties != null);
136 for (final GeneratedProperty property : properties) {
137 if (property.getName().equals("TunnelId")) {
138 assertTrue(property.getReturnType() != null);
139 assertFalse(property.getReturnType().equals(
141 assertTrue(property.getReturnType().getName()
143 resolvedAugmentsCount++;
146 } else if (type.getName().equals("NetworkLink2")
147 && type instanceof GeneratedType) {
148 final GeneratedType genType = (GeneratedType) type;
149 final List<MethodSignature> methods = genType
150 .getMethodDefinitions();
151 assertTrue(methods != null);
152 for (MethodSignature method : methods) {
153 if (method.getName().equals("getInterface")) {
154 assertTrue(method.getReturnType() != null);
155 assertFalse(method.getReturnType().equals(
157 assertTrue(method.getReturnType().getName()
159 resolvedAugmentsCount++;
164 assertEquals(6, resolvedAugmentsCount);
168 public void augmentedNetworkLinkTest() {
173 public void augmentedTopologyTunnelsTest() {