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.*;
13 import java.util.ArrayList;
14 import java.util.List;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
20 import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
21 import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
22 import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
23 import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
24 import org.opendaylight.controller.sal.binding.model.api.Type;
25 import org.opendaylight.yangtools.yang.model.api.Module;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27 import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
28 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
30 public class AugmentRleativeXPathTest {
32 private final static List<File> augmentModels = new ArrayList<>();
33 private final static String augmentFolderPath = AugmentedTypeTest.class
34 .getResource("/augment-relative-xpath-models").getPath();
37 public static void loadTestResources() {
38 final File augFolder = new File(augmentFolderPath);
40 for (final File fileEntry : augFolder.listFiles()) {
41 if (fileEntry.isFile()) {
42 augmentModels.add(fileEntry);
48 public void AugmentationWithRelativeXPathTest() {
49 final YangModelParser parser = new YangParserImpl();
50 final Set<Module> modules = parser.parseYangModels(augmentModels);
51 final SchemaContext context = parser.resolveSchemaContext(modules);
53 assertNotNull("context is null", context);
54 final BindingGenerator bindingGen = new BindingGeneratorImpl();
55 final List<Type> genTypes = bindingGen.generateTypes(context);
57 assertNotNull("genTypes is null", genTypes);
58 assertFalse("genTypes is empty", genTypes.isEmpty());
60 GeneratedTransferObject gtInterfaceKey = null;
61 GeneratedType gtInterface = null;
62 GeneratedType gtTunnel = null;
63 GeneratedTransferObject gtTunnelKey = null;
65 for (final Type type : genTypes) {
66 if (type.getName().equals("InterfaceKey") && type.getPackageName().contains("augment._abstract.topology")) {
67 gtInterfaceKey = (GeneratedTransferObject) type;
68 } else if (type.getName().equals("Interface") && type.getPackageName().contains("augment._abstract.topology")) {
69 gtInterface = (GeneratedType) type;
70 } else if (type.getName().equals("Tunnel") && type.getPackageName().contains("augment._abstract.topology")) {
71 gtTunnel = (GeneratedType) type;
72 } else if (type.getName().equals("TunnelKey") && type.getPackageName().contains("augment._abstract.topology")) {
73 gtTunnelKey = (GeneratedTransferObject) type;
78 assertNotNull("gtInterface is null", gtInterface);
79 final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
80 assertNotNull("gtInterfaceMethods is null", gtInterfaceMethods);
81 MethodSignature getIfcKeyMethod = null;
82 for (final MethodSignature method : gtInterfaceMethods) {
83 if (method.getName().equals("getInterfaceKey")) {
84 getIfcKeyMethod = method;
88 assertNotNull("getIfcKeyMethod is null", getIfcKeyMethod);
89 assertNotNull("getIfcKeyMethod.getReturnType() is null", getIfcKeyMethod.getReturnType());
90 assertFalse("getIfcKeyMethod.getReturnType() should not be Void",
91 getIfcKeyMethod.getReturnType().equals("java.lang.Void"));
92 assertTrue("getIfcKeyMethod.getReturnType().getName() must be InterfaceKey",
93 getIfcKeyMethod.getReturnType().getName().equals("InterfaceKey"));
96 assertNotNull("gtInterfaceKey is null", gtInterfaceKey);
97 final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
98 assertNotNull("properties is null", properties);
99 GeneratedProperty gtInterfaceId = null;
100 for (final GeneratedProperty property : properties) {
101 if (property.getName().equals("InterfaceId")) {
102 gtInterfaceId = property;
106 assertNotNull("gtInterfaceId is null", gtInterfaceId);
107 assertNotNull("gtInterfaceId.getReturnType() is null", gtInterfaceId.getReturnType());
108 assertFalse("gtInterfaceId.getReturnType() should not be Void",
109 gtInterfaceId.getReturnType().equals("java.lang.Void"));
110 assertTrue("gtInterfaceId.getReturnType().getName() must be String",
111 gtInterfaceId.getReturnType().getName().equals("String"));
114 assertNotNull("gtTunnel is null", gtTunnel);
115 final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
116 assertNotNull("tunnelMethods is null", tunnelMethods);
117 MethodSignature getTunnelKeyMethod = null;
118 for (MethodSignature method : tunnelMethods) {
119 if (method.getName().equals("getTunnelKey")) {
120 getTunnelKeyMethod = method;
124 assertNotNull("getTunnelKeyMethod is null", getTunnelKeyMethod);
125 assertNotNull("getTunnelKeyMethod.getReturnType()",
126 getTunnelKeyMethod.getReturnType());
127 assertFalse("getTunnelKeyMethod.getReturnType() should not be Void",
128 getTunnelKeyMethod.getReturnType().equals("java.lang.Void"));
129 assertTrue("getTunnelKeyMethod.getReturnType().getName() must be TunnelKey",
130 getTunnelKeyMethod.getReturnType().getName().equals("TunnelKey"));
133 assertNotNull("gtTunnelKey is null", gtTunnelKey);
134 final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
135 assertNotNull("tunnelKeyProperties is null", tunnelKeyProperties);
137 GeneratedProperty gtTunnelId = null;
138 for (final GeneratedProperty property : tunnelKeyProperties) {
139 if (property.getName().equals("TunnelId")) {
140 gtTunnelId = property;
143 assertNotNull("gtTunnelId is null", gtTunnelId);
144 assertNotNull("gtTunnelId.getReturnType() is null",
145 gtTunnelId.getReturnType());
146 assertFalse("gtTunnelId.getReturnType() should not be Void",
147 gtTunnelId.getReturnType().equals("java.lang.Void"));
148 assertTrue("gtTunnelId.getReturnType().getName() must be Uri",
149 gtTunnelId.getReturnType().getName().equals("Uri"));