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.yangtools.sal.binding.generator.impl;
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
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;
27 public class AugmentRelativeXPathTest extends AbstractTypesTest {
29 public AugmentRelativeXPathTest() {
30 super(AugmentRelativeXPathTest.class.getResource("/augment-relative-xpath-models"));
34 public void AugmentationWithRelativeXPathTest() throws IOException {
35 final YangContextParser parser = new YangParserImpl();
36 final SchemaContext context = parser.parseFiles(testModels);
38 assertNotNull("context is null", context);
39 final BindingGenerator bindingGen = new BindingGeneratorImpl();
40 final List<Type> genTypes = bindingGen.generateTypes(context);
42 assertNotNull("genTypes is null", genTypes);
43 assertFalse("genTypes is empty", genTypes.isEmpty());
45 GeneratedTransferObject gtInterfaceKey = null;
46 GeneratedType gtInterface = null;
47 GeneratedType gtTunnel = null;
48 GeneratedTransferObject gtTunnelKey = null;
50 for (final Type type : genTypes) {
51 if (type.getName().equals("InterfaceKey") && type.getPackageName().contains("augment._abstract.topology")) {
52 gtInterfaceKey = (GeneratedTransferObject) type;
53 } else if (type.getName().equals("Interface")
54 && type.getPackageName().contains("augment._abstract.topology")) {
55 gtInterface = (GeneratedType) type;
56 } else if (type.getName().equals("Tunnel") && type.getPackageName().contains("augment._abstract.topology")) {
57 gtTunnel = (GeneratedType) type;
58 } else if (type.getName().equals("TunnelKey")
59 && type.getPackageName().contains("augment._abstract.topology")) {
60 gtTunnelKey = (GeneratedTransferObject) type;
65 assertNotNull("Interface is null", gtInterface);
66 final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
67 assertNotNull("Interface methods are null", gtInterfaceMethods);
68 MethodSignature getIfcKeyMethod = null;
69 for (final MethodSignature method : gtInterfaceMethods) {
70 if (method.getName().equals("getKey")) {
71 getIfcKeyMethod = method;
75 assertNotNull("getKey method is null", getIfcKeyMethod);
76 assertNotNull("getKey method return type is null", getIfcKeyMethod.getReturnType());
77 assertTrue("getKey method return type name must be InterfaceKey", getIfcKeyMethod.getReturnType().getName()
78 .equals("InterfaceKey"));
81 assertNotNull("InterfaceKey is null", gtInterfaceKey);
82 final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
83 assertNotNull("InterfaceKey properties are null", properties);
84 GeneratedProperty gtInterfaceId = null;
85 for (final GeneratedProperty property : properties) {
86 if (property.getName().equals("interfaceId")) {
87 gtInterfaceId = property;
91 assertNotNull("interfaceId is null", gtInterfaceId);
92 assertNotNull("interfaceId return type is null", gtInterfaceId.getReturnType());
93 assertTrue("interfaceId return type name must be String",
94 gtInterfaceId.getReturnType().getName().equals("String"));
97 assertNotNull("Tunnel is null", gtTunnel);
98 final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
99 assertNotNull("Tunnel methods are null", tunnelMethods);
100 MethodSignature getTunnelKeyMethod = null;
101 for (MethodSignature method : tunnelMethods) {
102 if (method.getName().equals("getKey")) {
103 getTunnelKeyMethod = method;
107 assertNotNull("getKey method is null", getTunnelKeyMethod);
108 assertNotNull("getKey method return type", getTunnelKeyMethod.getReturnType());
109 assertTrue("getKey method return type name must be TunnelKey", getTunnelKeyMethod.getReturnType().getName()
110 .equals("TunnelKey"));
113 assertNotNull("TunnelKey is null", gtTunnelKey);
114 final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
115 assertNotNull("TunnelKey properties are null", tunnelKeyProperties);
117 GeneratedProperty gtTunnelId = null;
118 for (final GeneratedProperty property : tunnelKeyProperties) {
119 if (property.getName().equals("tunnelId")) {
120 gtTunnelId = property;
123 assertNotNull("tunnelId is null", gtTunnelId);
124 assertNotNull("tunnelId return type is null", gtTunnelId.getReturnType());
125 assertTrue("tunnelId return type name must be Uri", gtTunnelId.getReturnType().getName().equals("Uri"));