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.mdsal.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.mdsal.binding.generator.api.BindingGenerator;
18 import org.opendaylight.mdsal.binding.generator.impl.BindingGeneratorImpl;
19 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
20 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
21 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
22 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
23 import org.opendaylight.mdsal.binding.model.api.Type;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
26 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
27 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
29 public class AugmentRelativeXPathTest extends AbstractTypesTest {
31 public AugmentRelativeXPathTest() {
32 super(AugmentRelativeXPathTest.class.getResource("/augment-relative-xpath-models"));
36 public void AugmentationWithRelativeXPathTest() throws IOException, SourceException, ReactorException {
38 final SchemaContext context = YangParserTestUtils.parseYangSources(testModels);
40 assertNotNull("context is null", context);
41 final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
42 final List<Type> genTypes = bindingGen.generateTypes(context);
44 assertNotNull("genTypes is null", genTypes);
45 assertFalse("genTypes is empty", genTypes.isEmpty());
47 GeneratedTransferObject gtInterfaceKey = null;
48 GeneratedType gtInterface = null;
49 GeneratedType gtTunnel = null;
50 GeneratedTransferObject gtTunnelKey = null;
52 for (final Type type : genTypes) {
53 if (type.getName().equals("InterfaceKey") && type.getPackageName().contains("augment._abstract.topology")) {
54 gtInterfaceKey = (GeneratedTransferObject) type;
55 } else if (type.getName().equals("Interface")
56 && type.getPackageName().contains("augment._abstract.topology")) {
57 gtInterface = (GeneratedType) type;
58 } else if (type.getName().equals("Tunnel") && type.getPackageName().contains("augment._abstract.topology")) {
59 gtTunnel = (GeneratedType) type;
60 } else if (type.getName().equals("TunnelKey")
61 && type.getPackageName().contains("augment._abstract.topology")) {
62 gtTunnelKey = (GeneratedTransferObject) type;
67 assertNotNull("Interface is null", gtInterface);
68 final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
69 assertNotNull("Interface methods are null", gtInterfaceMethods);
70 MethodSignature getIfcKeyMethod = null;
71 for (final MethodSignature method : gtInterfaceMethods) {
72 if (method.getName().equals("getKey")) {
73 getIfcKeyMethod = method;
77 assertNotNull("getKey method is null", getIfcKeyMethod);
78 assertNotNull("getKey method return type is null", getIfcKeyMethod.getReturnType());
79 assertTrue("getKey method return type name must be InterfaceKey", getIfcKeyMethod.getReturnType().getName()
80 .equals("InterfaceKey"));
83 assertNotNull("InterfaceKey is null", gtInterfaceKey);
84 final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
85 assertNotNull("InterfaceKey properties are null", properties);
86 GeneratedProperty gtInterfaceId = null;
87 for (final GeneratedProperty property : properties) {
88 if (property.getName().equals("interfaceId")) {
89 gtInterfaceId = property;
93 assertNotNull("interfaceId is null", gtInterfaceId);
94 assertNotNull("interfaceId return type is null", gtInterfaceId.getReturnType());
95 assertTrue("interfaceId return type name must be String",
96 gtInterfaceId.getReturnType().getName().equals("String"));
99 assertNotNull("Tunnel is null", gtTunnel);
100 final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
101 assertNotNull("Tunnel methods are null", tunnelMethods);
102 MethodSignature getTunnelKeyMethod = null;
103 for (MethodSignature method : tunnelMethods) {
104 if (method.getName().equals("getKey")) {
105 getTunnelKeyMethod = method;
109 assertNotNull("getKey method is null", getTunnelKeyMethod);
110 assertNotNull("getKey method return type", getTunnelKeyMethod.getReturnType());
111 assertTrue("getKey method return type name must be TunnelKey", getTunnelKeyMethod.getReturnType().getName()
112 .equals("TunnelKey"));
115 assertNotNull("TunnelKey is null", gtTunnelKey);
116 final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
117 assertNotNull("TunnelKey properties are null", tunnelKeyProperties);
119 GeneratedProperty gtTunnelId = null;
120 for (final GeneratedProperty property : tunnelKeyProperties) {
121 if (property.getName().equals("tunnelId")) {
122 gtTunnelId = property;
125 assertNotNull("tunnelId is null", gtTunnelId);
126 assertNotNull("tunnelId return type is null", gtTunnelId.getReturnType());
127 assertTrue("tunnelId return type name must be Uri", gtTunnelId.getReturnType().getName().equals("Uri"));