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 org.junit.BeforeClass;
11 import org.junit.Test;
12 import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
13 import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
14 import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
15 import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
16 import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
17 import org.opendaylight.controller.sal.binding.model.api.Type;
18 import org.opendaylight.controller.yang.model.api.Module;
19 import org.opendaylight.controller.yang.model.api.SchemaContext;
20 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
21 import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
24 import java.util.ArrayList;
25 import java.util.List;
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertNotNull;
30 import static org.junit.Assert.assertTrue;
32 public class AugmentRleativeXPathTest {
34 private final static List<File> augmentModels = new ArrayList<>();
35 private final static String augmentFolderPath = AugmentedTypeTest.class
36 .getResource("/augment-relative-xpath-models").getPath();
39 public static void loadTestResources() {
40 final File augFolder = new File(augmentFolderPath);
42 for (final File fileEntry : augFolder.listFiles()) {
43 if (fileEntry.isFile()) {
44 augmentModels.add(fileEntry);
50 public void AugmentationWithRelativeXPathTest() {
51 final YangModelParser parser = new YangParserImpl();
52 final Set<Module> modules = parser.parseYangModels(augmentModels);
53 final SchemaContext context = parser.resolveSchemaContext(modules);
55 assertNotNull("context is null", context);
56 final BindingGenerator bindingGen = new BindingGeneratorImpl();
57 final List<Type> genTypes = bindingGen.generateTypes(context);
59 assertNotNull("genTypes is null", genTypes);
60 assertFalse("genTypes is empty", genTypes.isEmpty());
62 GeneratedTransferObject gtInterfaceKey = null;
63 GeneratedType gtInterface = null;
64 GeneratedType gtTunnel = null;
65 GeneratedTransferObject gtTunnelKey = null;
67 for (final Type type : genTypes) {
68 if (type.getName().equals("InterfaceKey") && type.getPackageName().contains("augment._abstract.topology")) {
69 gtInterfaceKey = (GeneratedTransferObject) type;
70 } else if (type.getName().equals("Interface") && type.getPackageName().contains("augment._abstract.topology")) {
71 gtInterface = (GeneratedType) type;
72 } else if (type.getName().equals("Tunnel") && type.getPackageName().contains("augment._abstract.topology")) {
73 gtTunnel = (GeneratedType) type;
74 } else if (type.getName().equals("TunnelKey") && type.getPackageName().contains("augment._abstract.topology")) {
75 gtTunnelKey = (GeneratedTransferObject) type;
80 assertNotNull("gtInterface is null", gtInterface);
81 final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
82 assertNotNull("gtInterfaceMethods is null", gtInterfaceMethods);
83 MethodSignature getIfcKeyMethod = null;
84 for (final MethodSignature method : gtInterfaceMethods) {
85 if (method.getName().equals("getInterfaceKey")) {
86 getIfcKeyMethod = method;
90 assertNotNull("getIfcKeyMethod is null", getIfcKeyMethod);
91 assertNotNull("getIfcKeyMethod.getReturnType() is null", getIfcKeyMethod.getReturnType());
92 assertFalse("getIfcKeyMethod.getReturnType() should not be Void",
93 getIfcKeyMethod.getReturnType().equals("java.lang.Void"));
94 assertTrue("getIfcKeyMethod.getReturnType().getName() must be InterfaceKey",
95 getIfcKeyMethod.getReturnType().getName().equals("InterfaceKey"));
98 assertNotNull("gtInterfaceKey is null", gtInterfaceKey);
99 final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
100 assertNotNull("properties is null", properties);
101 GeneratedProperty gtInterfaceId = null;
102 for (final GeneratedProperty property : properties) {
103 if (property.getName().equals("InterfaceId")) {
104 gtInterfaceId = property;
108 assertNotNull("gtInterfaceId is null", gtInterfaceId);
109 assertNotNull("gtInterfaceId.getReturnType() is null", gtInterfaceId.getReturnType());
110 assertFalse("gtInterfaceId.getReturnType() should not be Void",
111 gtInterfaceId.getReturnType().equals("java.lang.Void"));
112 assertTrue("gtInterfaceId.getReturnType().getName() must be String",
113 gtInterfaceId.getReturnType().getName().equals("String"));
116 assertNotNull("gtTunnel is null", gtTunnel);
117 final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
118 assertNotNull("tunnelMethods is null", tunnelMethods);
119 MethodSignature getTunnelKeyMethod = null;
120 for (MethodSignature method : tunnelMethods) {
121 if (method.getName().equals("getTunnelKey")) {
122 getTunnelKeyMethod = method;
126 assertNotNull("getTunnelKeyMethod is null", getTunnelKeyMethod);
127 assertNotNull("getTunnelKeyMethod.getReturnType()",
128 getTunnelKeyMethod.getReturnType());
129 assertFalse("getTunnelKeyMethod.getReturnType() should not be Void",
130 getTunnelKeyMethod.getReturnType().equals("java.lang.Void"));
131 assertTrue("getTunnelKeyMethod.getReturnType().getName() must be TunnelKey",
132 getTunnelKeyMethod.getReturnType().getName().equals("TunnelKey"));
135 assertNotNull("gtTunnelKey is null", gtTunnelKey);
136 final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
137 assertNotNull("tunnelKeyProperties is null", tunnelKeyProperties);
139 GeneratedProperty gtTunnelId = null;
140 for (final GeneratedProperty property : tunnelKeyProperties) {
141 if (property.getName().equals("TunnelId")) {
142 gtTunnelId = property;
145 assertNotNull("gtTunnelId is null", gtTunnelId);
146 assertNotNull("gtTunnelId.getReturnType() is null",
147 gtTunnelId.getReturnType());
148 assertFalse("gtTunnelId.getReturnType() should not be Void",
149 gtTunnelId.getReturnType().equals("java.lang.Void"));
150 assertTrue("gtTunnelId.getReturnType().getName() must be Uri",
151 gtTunnelId.getReturnType().getName().equals("Uri"));