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.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 org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
15 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
17 import java.io.IOException;
18 import java.util.List;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator;
21 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty;
22 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
23 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
24 import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature;
25 import org.opendaylight.yangtools.sal.binding.model.api.Type;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
28 public class AugmentRelativeXPathTest extends AbstractTypesTest {
30 public AugmentRelativeXPathTest() {
31 super(AugmentRelativeXPathTest.class.getResource("/augment-relative-xpath-models"));
35 public void AugmentationWithRelativeXPathTest() throws IOException, SourceException, ReactorException {
37 final SchemaContext context = RetestUtils.parseYangSources(testModels);
39 assertNotNull("context is null", context);
40 final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
41 final List<Type> genTypes = bindingGen.generateTypes(context);
43 assertNotNull("genTypes is null", genTypes);
44 assertFalse("genTypes is empty", genTypes.isEmpty());
46 GeneratedTransferObject gtInterfaceKey = null;
47 GeneratedType gtInterface = null;
48 GeneratedType gtTunnel = null;
49 GeneratedTransferObject gtTunnelKey = null;
51 for (final Type type : genTypes) {
52 if (type.getName().equals("InterfaceKey") && type.getPackageName().contains("augment._abstract.topology")) {
53 gtInterfaceKey = (GeneratedTransferObject) type;
54 } else if (type.getName().equals("Interface")
55 && type.getPackageName().contains("augment._abstract.topology")) {
56 gtInterface = (GeneratedType) type;
57 } else if (type.getName().equals("Tunnel") && type.getPackageName().contains("augment._abstract.topology")) {
58 gtTunnel = (GeneratedType) type;
59 } else if (type.getName().equals("TunnelKey")
60 && type.getPackageName().contains("augment._abstract.topology")) {
61 gtTunnelKey = (GeneratedTransferObject) type;
66 assertNotNull("Interface is null", gtInterface);
67 final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
68 assertNotNull("Interface methods are null", gtInterfaceMethods);
69 MethodSignature getIfcKeyMethod = null;
70 for (final MethodSignature method : gtInterfaceMethods) {
71 if (method.getName().equals("getKey")) {
72 getIfcKeyMethod = method;
76 assertNotNull("getKey method is null", getIfcKeyMethod);
77 assertNotNull("getKey method return type is null", getIfcKeyMethod.getReturnType());
78 assertTrue("getKey method return type name must be InterfaceKey", getIfcKeyMethod.getReturnType().getName()
79 .equals("InterfaceKey"));
82 assertNotNull("InterfaceKey is null", gtInterfaceKey);
83 final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
84 assertNotNull("InterfaceKey properties are null", properties);
85 GeneratedProperty gtInterfaceId = null;
86 for (final GeneratedProperty property : properties) {
87 if (property.getName().equals("interfaceId")) {
88 gtInterfaceId = property;
92 assertNotNull("interfaceId is null", gtInterfaceId);
93 assertNotNull("interfaceId return type is null", gtInterfaceId.getReturnType());
94 assertTrue("interfaceId return type name must be String",
95 gtInterfaceId.getReturnType().getName().equals("String"));
98 assertNotNull("Tunnel is null", gtTunnel);
99 final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
100 assertNotNull("Tunnel methods are null", tunnelMethods);
101 MethodSignature getTunnelKeyMethod = null;
102 for (MethodSignature method : tunnelMethods) {
103 if (method.getName().equals("getKey")) {
104 getTunnelKeyMethod = method;
108 assertNotNull("getKey method is null", getTunnelKeyMethod);
109 assertNotNull("getKey method return type", getTunnelKeyMethod.getReturnType());
110 assertTrue("getKey method return type name must be TunnelKey", getTunnelKeyMethod.getReturnType().getName()
111 .equals("TunnelKey"));
114 assertNotNull("TunnelKey is null", gtTunnelKey);
115 final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
116 assertNotNull("TunnelKey properties are null", tunnelKeyProperties);
118 GeneratedProperty gtTunnelId = null;
119 for (final GeneratedProperty property : tunnelKeyProperties) {
120 if (property.getName().equals("tunnelId")) {
121 gtTunnelId = property;
124 assertNotNull("tunnelId is null", gtTunnelId);
125 assertNotNull("tunnelId return type is null", gtTunnelId.getReturnType());
126 assertTrue("tunnelId return type name must be Uri", gtTunnelId.getReturnType().getName().equals("Uri"));