Test for YANG choices was programmed.
Fixed bug:
- in BindingGeneratorImpl was in method addInterfaceDefinition changed
type of object which contains information about implemented interfaces
from ReferencedType to GeneratedType
Change-Id: Ie580f74aeebfa53c77e01995ff0f361fb1ec6224
Signed-off-by: Jozef Gloncak <jgloncak@cisco.com>
final List<GeneratedType> generatedTypes = new ArrayList<>();
for (final ChoiceCaseNode caseNode : caseNodes) {
- if (caseNode != null && !caseNode.isAddedByUses()) {
+ if (caseNode != null && !caseNode.isAddedByUses() && !caseNode.isAugmenting()) {
final String packageName = packageNameForGeneratedType(basePackageName, caseNode.getPath());
final GeneratedTypeBuilder caseTypeBuilder = addDefaultInterfaceDefinition(packageName, caseNode);
caseTypeBuilder.addImplementsType(refChoiceType);
for (UsesNode usesNode : dataNodeContainer.getUses()) {
if (usesNode.getGroupingPath() != null) {
GeneratedType genType = allGroupings.get(usesNode.getGroupingPath());
- builder.addImplementsType(new ReferencedTypeImpl(genType.getPackageName(), genType.getName()));
+ builder.addImplementsType(genType);
}
}
return builder;
*/
package org.opendaylight.controller.sal.binding.generator.impl;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.opendaylight.controller.sal.binding.generator.impl.SupportTestUtil.containsInterface;
+import static org.opendaylight.controller.sal.binding.generator.impl.SupportTestUtil.containsSignatures;
import java.io.File;
import java.util.ArrayList;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
import org.opendaylight.controller.sal.binding.model.api.Type;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
}
}
+ private static GeneratedType checkGeneratedType(List<Type> genTypes, String genTypeName, String packageName,
+ int occurences) {
+ GeneratedType searchedGenType = null;
+ int searchedGenTypeCounter = 0;
+ for (Type type : genTypes) {
+ if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
+ GeneratedType genType = (GeneratedType) type;
+ if (genType.getName().equals(genTypeName) && genType.getPackageName().equals(packageName)) {
+ searchedGenType = genType;
+ searchedGenTypeCounter++;
+ }
+ }
+ }
+ assertNotNull("Generated type " + genTypeName + " wasn't found", searchedGenType);
+ assertEquals(genTypeName + " generated type has incorrect number of occurences.", occurences,
+ searchedGenTypeCounter);
+ return searchedGenType;
+
+ }
+
+ private static GeneratedType checkGeneratedType(List<Type> genTypes, String genTypeName, String packageName) {
+ return checkGeneratedType(genTypes, genTypeName, packageName, 1);
+ }
+
@Test
public void choiceCaseResolvingTypeTest() {
final YangModelParser parser = new YangParserImpl();
assertNotNull("genTypes is null", genTypes);
assertFalse("genTypes is empty", genTypes.isEmpty());
+
+ // test for file choice-monitoring
+ String pcgPref = "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.choice.monitoring.rev201371.netconf.state.datastores.datastore.locks";
+ GeneratedType genType = null;
+
+ checkGeneratedType(genTypes, "LockType", pcgPref); // choice
+
+ genType = checkGeneratedType(genTypes, "GlobalLock", pcgPref + ".lock.type"); // case
+ containsSignatures(genType, new MethodSignaturePattern("getGlobalLock", "GlobalLock"));
+ containsInterface("LockType", genType);
+
+ genType = checkGeneratedType(genTypes, "PartialLock", pcgPref + ".lock.type"); // case
+ containsSignatures(genType, new MethodSignaturePattern("getPartialLock", "List<PartialLock>"));
+ containsInterface("LockType", genType);
+
+ genType = checkGeneratedType(genTypes, "Fingerprint", pcgPref + ".lock.type"); // case
+ containsSignatures(genType, new MethodSignaturePattern("getAlgorithmAndHash", "AlgorithmAndHash"));
+ containsInterface("LockType", genType);
+
+ genType = checkGeneratedType(genTypes, "AlgorithmAndHash", pcgPref + ".lock.type.fingerprint"); // choice
+
+ genType = checkGeneratedType(genTypes, "Md5", pcgPref + ".lock.type.fingerprint.algorithm.and.hash"); // case
+ containsSignatures(genType, new MethodSignaturePattern("getMd5", "TlsFingerprintType"));
+ containsInterface("AlgorithmAndHash", genType);
+
+ genType = checkGeneratedType(genTypes, "Sha1", pcgPref + ".lock.type.fingerprint.algorithm.and.hash"); // case
+ containsSignatures(genType, new MethodSignaturePattern("getSha1", "TlsFingerprintType"));
+ containsInterface("AlgorithmAndHash", genType);
+
+ genType = checkGeneratedType(genTypes, "Sha224", pcgPref + ".lock.type.fingerprint.algorithm.and.hash"); // case
+ containsSignatures(genType, new MethodSignaturePattern("getSha224", "TlsFingerprintType"));
+ containsInterface("AlgorithmAndHash", genType);
+
+ genType = checkGeneratedType(genTypes, "Sha256", pcgPref + ".lock.type.fingerprint.algorithm.and.hash"); // case
+ containsSignatures(genType, new MethodSignaturePattern("getSha256", "TlsFingerprintType"));
+ containsInterface("AlgorithmAndHash", genType);
+
+ genType = checkGeneratedType(genTypes, "Sha384", pcgPref + ".lock.type.fingerprint.algorithm.and.hash"); // case
+ containsSignatures(genType, new MethodSignaturePattern("getSha384", "TlsFingerprintType"));
+ containsInterface("AlgorithmAndHash", genType);
+
+ genType = checkGeneratedType(genTypes, "Sha512", pcgPref + ".lock.type.fingerprint.algorithm.and.hash"); // case
+ containsSignatures(genType, new MethodSignaturePattern("getSha512", "TlsFingerprintType"));
+ containsInterface("AlgorithmAndHash", genType);
+
+ // test for file augment-monitoring
+ // augment
+ // "/nm:netconf-state/nm:datastores/nm:datastore/nm:locks/nm:lock-type"
+ pcgPref = "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.augment.monitoring.rev201371";
+ genType = null;
+
+ genType = checkGeneratedType(genTypes, "AutonomousLock", pcgPref
+ + ".netconf.state.datastores.datastore.locks.lock.type"); // choice
+ containsSignatures(genType, new MethodSignaturePattern("getAutonomousDef", "AutonomousDef"));
+ containsInterface("LockType", genType);
+
+ genType = checkGeneratedType(genTypes, "AnonymousLock", pcgPref
+ + ".netconf.state.datastores.datastore.locks.lock.type"); // choice
+ containsSignatures(genType, new MethodSignaturePattern("getLockTime", "Long"));
+ containsInterface("LockType", genType);
+
+ genType = checkGeneratedType(genTypes, "LeafAugCase", pcgPref
+ + ".netconf.state.datastores.datastore.locks.lock.type"); // choice
+ containsSignatures(genType, new MethodSignaturePattern("getLeafAugCase", "String"));
+ containsInterface("LockType", genType);
+
+ // augment
+ // "/nm:netconf-state/nm:datastores/nm:datastore/nm:locks/nm:lock-type/nm:partial-lock"
+ // {
+ genType = checkGeneratedType(genTypes, "PartialLock1", pcgPref); // case
+ containsSignatures(genType, new MethodSignaturePattern("getAugCaseByChoice", "AugCaseByChoice"));
+ containsInterface("Augmentation<PartialLock>", genType);
+
+ genType = checkGeneratedType(genTypes, "AugCaseByChoice", pcgPref
+ + ".netconf.state.datastores.datastore.locks.lock.type.partial.lock"); // choice
+
+ genType = checkGeneratedType(genTypes, "Foo", pcgPref
+ + ".netconf.state.datastores.datastore.locks.lock.type.partial.lock.aug._case.by.choice"); // case
+ containsSignatures(genType, new MethodSignaturePattern("getFoo", "String"));
+ containsInterface("AugCaseByChoice", genType);
+
+ genType = checkGeneratedType(genTypes, "Bar", pcgPref
+ + ".netconf.state.datastores.datastore.locks.lock.type.partial.lock.aug._case.by.choice"); // case
+ containsSignatures(genType, new MethodSignaturePattern("getBar", "Boolean"));
+ containsInterface("AugCaseByChoice", genType);
+
+ // augment "/nm:netconf-state/nm:datastores/nm:datastore" {
+ genType = checkGeneratedType(genTypes, "Datastore1", pcgPref);
+ containsSignatures(genType, new MethodSignaturePattern("getStorageFormat", "StorageFormat"));
+ containsInterface("Augmentation<Datastore>", genType);
+
+ genType = checkGeneratedType(genTypes, "StorageFormat", pcgPref + ".netconf.state.datastores.datastore"); // choice
+
+ genType = checkGeneratedType(genTypes, "UnknownFiles", pcgPref
+ + ".netconf.state.datastores.datastore.storage.format"); // case
+ containsSignatures(genType, new MethodSignaturePattern("getFiles", "List<Files>"));
+ containsInterface("StorageFormat", genType);
+
+ genType = checkGeneratedType(genTypes, "Xml", pcgPref + ".netconf.state.datastores.datastore.storage.format"); // case
+ containsSignatures(genType, new MethodSignaturePattern("getXmlDef", "XmlDef"));
+ containsInterface("StorageFormat", genType);
+
+ genType = checkGeneratedType(genTypes, "Yang", pcgPref + ".netconf.state.datastores.datastore.storage.format"); // case
+ containsSignatures(genType, new MethodSignaturePattern("getYangFileName", "String"));
+ containsInterface("StorageFormat", genType);
+
}
}
--- /dev/null
+package org.opendaylight.controller.sal.binding.generator.impl;
+
+public class MethodSignaturePattern {
+ final String name;
+ final String type;
+
+ public MethodSignaturePattern(String methodName, String methodType) {
+ this.name = methodName;
+ this.type = methodType;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public String getType() {
+ return this.type;
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.opendaylight.controller.sal.binding.generator.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
+import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
+import org.opendaylight.controller.sal.binding.model.api.ParameterizedType;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+
+public class SupportTestUtil {
+
+ public static void containsSignatures(final GeneratedType genType,
+ final MethodSignaturePattern... searchedSignsWhat) {
+ final List<MethodSignature> searchedSignsIn = genType.getMethodDefinitions();
+ containsSignatures(searchedSignsIn, searchedSignsWhat);
+ }
+
+ public static void containsSignatures(final List<MethodSignature> searchedSignsIn,
+ final MethodSignaturePattern... searchedSignsWhat) {
+ if (searchedSignsIn == null) {
+ throw new IllegalArgumentException("List of method signatures in which should be searched can't be null");
+ }
+ if (searchedSignsWhat == null) {
+ throw new IllegalArgumentException("Array of method signatures which should be searched can't be null");
+ }
+
+ for (MethodSignaturePattern searchedSignWhat : searchedSignsWhat) {
+ boolean nameMatchFound = false;
+ String typeNameFound = "";
+ for (MethodSignature searchedSignIn : searchedSignsIn) {
+ if (searchedSignWhat.getName().equals(searchedSignIn.getName())) {
+ nameMatchFound = true;
+ typeNameFound = resolveFullNameOfReturnType(searchedSignIn.getReturnType());
+ if (searchedSignWhat.getType().equals(typeNameFound)) {
+ break;
+ }
+ }
+ }
+ assertTrue("Method " + searchedSignWhat.getName() + " wasn't found.", nameMatchFound);
+ assertEquals("Return type in method " + searchedSignWhat.getName() + " doesn't match expected type ",
+ searchedSignWhat.getType(), typeNameFound);
+
+ }
+ }
+
+ public static String resolveFullNameOfReturnType(final Type type) {
+ final StringBuilder nameBuilder = new StringBuilder();
+ if (type instanceof ParameterizedType) {
+ nameBuilder.append(type.getName() + "<");
+ ParameterizedType parametrizedTypes = (ParameterizedType) type;
+ for (Type parametrizedType : parametrizedTypes.getActualTypeArguments()) {
+ nameBuilder.append(parametrizedType.getName() + ",");
+ }
+ if (nameBuilder.charAt(nameBuilder.length() - 1) == ',') {
+ nameBuilder.deleteCharAt(nameBuilder.length() - 1);
+ }
+ nameBuilder.append(">");
+ } else {
+ nameBuilder.append(type.getName());
+ }
+ return nameBuilder.toString();
+ }
+
+ public static void containsInterface(String interfaceNameSearched, GeneratedType genType) {
+ List<Type> caseCImplements = genType.getImplements();
+ boolean interfaceFound = false;
+ for (Type caseCImplement : caseCImplements) {
+ String interfaceName = resolveFullNameOfReturnType(caseCImplement);
+ if (interfaceName.equals(interfaceNameSearched)) {
+ interfaceFound = true;
+ break;
+ }
+ }
+ assertTrue("Generated type " + genType.getName() + " doesn't implement inrerface " + interfaceNameSearched,
+ interfaceFound);
+ }
+
+}
*/
package org.opendaylight.controller.sal.binding.generator.impl;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.opendaylight.controller.sal.binding.generator.impl.SupportTestUtil.containsInterface;
+import static org.opendaylight.controller.sal.binding.generator.impl.SupportTestUtil.containsSignatures;
import java.io.File;
import java.util.ArrayList;
import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
-import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
-import org.opendaylight.controller.sal.binding.model.api.ParameterizedType;
import org.opendaylight.controller.sal.binding.model.api.Type;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
public class UsesTest {
- private class MethodSignaturePattern {
- final String name;
- final String type;
-
- public MethodSignaturePattern(String methodName, String methodType) {
- this.name = methodName;
- this.type = methodType;
- }
-
- public String getName() {
- return this.name;
- }
-
- public String getType() {
- return this.type;
- }
- }
-
- private static void containsSignatures(final List<MethodSignature> searchedSignsIn,
- final MethodSignaturePattern... searchedSignsWhat) {
- if (searchedSignsIn == null) {
- throw new IllegalArgumentException("List of method signatures in which should be searched can't be null");
- }
- if (searchedSignsWhat == null) {
- throw new IllegalArgumentException("Array of method signatures which should be searched can't be null");
- }
-
- for (MethodSignaturePattern searchedSignWhat : searchedSignsWhat) {
- boolean nameMatchFound = false;
- String typeNameFound = "";
- for (MethodSignature searchedSignIn : searchedSignsIn) {
- if (searchedSignWhat.getName().equals(searchedSignIn.getName())) {
- nameMatchFound = true;
- typeNameFound = resolveFullNameOfReturnType(searchedSignIn);
- if (searchedSignWhat.getType().equals(typeNameFound)) {
- break;
- }
- }
- }
- assertTrue("Method " + searchedSignWhat.getName() + " wasn't found.", nameMatchFound);
- assertEquals("Return type in method " + searchedSignWhat.getName() + " doesn't match expected type ",
- searchedSignWhat.getType(), typeNameFound);
-
- }
- }
-
- private static String resolveFullNameOfReturnType(final MethodSignature methodSignature) {
- final StringBuilder nameBuilder = new StringBuilder();
- if (methodSignature.getReturnType() instanceof ParameterizedType) {
- nameBuilder.append(methodSignature.getReturnType().getName() + "<");
- ParameterizedType parametrizedTypes = (ParameterizedType) methodSignature.getReturnType();
- for (Type parametrizedType : parametrizedTypes.getActualTypeArguments()) {
- nameBuilder.append(parametrizedType.getName() + ",");
- }
- if (nameBuilder.charAt(nameBuilder.length() - 1) == ',') {
- nameBuilder.deleteCharAt(nameBuilder.length() - 1);
- }
- nameBuilder.append(">");
- } else {
- nameBuilder.append(methodSignature.getReturnType().getName());
- }
- return nameBuilder.toString();
- }
-
- private static boolean containsInterface(String interfaceName, GeneratedType genType) {
- List<Type> caseCImplements = genType.getImplements();
- for (Type caseCImplement : caseCImplements) {
- if (caseCImplement.getName().equals(interfaceName)) {
- return true;
- }
- }
- return false;
- }
-
private static List<File> loadTestResources(String testFile) {
final List<File> testModels = new ArrayList<File>();
final File listModelFile = new File(UsesTest.class.getResource(testFile).getPath());
assertEquals("GroupingX is in wrong package.",
"org.opendaylight.yang.gen.v1.urn.grouping.dependencies.rev2013718", groupingX.getPackageName());
- assertTrue("GroupingV doesn't extend GroupingU.", containsInterface("GroupingV", groupingU));
- assertTrue("GroupingX doesn't extend GroupingU.", containsInterface("GroupingX", groupingU));
- assertTrue("GroupingZ doesn't extend GroupingV.", containsInterface("GroupingZ", groupingV));
- assertTrue("GroupingZZ doesn't extend GroupingV.", containsInterface("GroupingZZ", groupingV));
- assertTrue("GroupingY doesn't extend GroupingX.", containsInterface("GroupingY", groupingX));
+ containsInterface("GroupingV", groupingU);
+ containsInterface("GroupingX", groupingU);
+ containsInterface("GroupingZ", groupingV);
+ containsInterface("GroupingZZ", groupingV);
+ containsInterface("GroupingY", groupingX);
}
@Test
assertEquals("GroupingCaseTest is in wrong package.",
"org.opendaylight.yang.gen.v1.urn.grouping.uses._case.rev2013718", groupingCaseTest.getPackageName());
- assertTrue("Case C doesn't extend GroupingCaseTest.", containsInterface("GroupingCaseTest", caseC));
+ containsInterface("GroupingCaseTest", caseC);
assertTrue("Case C shouldn't contain any method.", caseC.getMethodDefinitions().isEmpty());
assertEquals("Number of method in GroupingCaseTest is incorrect", 1, groupingCaseTest.getMethodDefinitions()
assertEquals("ContainerTest isn't in correct package",
"org.opendaylight.yang.gen.v1.urn.grouping.uses.container.rev2013718", containerTest.getPackageName());
- assertTrue("ContainerTest doesn't extend GroupingContainerTest.",
- containsInterface("GroupingContainerTest", containerTest));
+ containsInterface("GroupingContainerTest", containerTest);
assertEquals("Number of method in GroupingContainerTestis incorrect", 2, groupingContainerTest
.getMethodDefinitions().size());
assertEquals("GroupingTest isn't in correct package",
"org.opendaylight.yang.gen.v1.urn.grouping.uses.grouping.rev2013718", groupingTest.getPackageName());
- assertTrue("GroupingTest doesn't extend GroupingGroupingTest.",
- containsInterface("GroupingGroupingTest", groupingTest));
+ containsInterface("GroupingGroupingTest", groupingTest);
assertEquals("Number of method in GroupingGroupingTest is incorrect", 1, groupingGroupingTest
.getMethodDefinitions().size());
"org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev2013718.grouping.list.test",
listGroupingListTest.getPackageName());
- assertTrue("ListTest doesn't extend GroupingGroupingTest.", containsInterface("GroupingListTest", listTest));
+ containsInterface("GroupingListTest", listTest);
assertEquals("Number of method in GroupingListTest is incorrect", 4, groupingListTest.getMethodDefinitions()
.size());
"org.opendaylight.yang.gen.v1.urn.grouping.uses.modul.rev2013718",
groupingUsesModulData.getPackageName());
- assertTrue("GroupingUsesModulData doesn't extend GroupingModulTest.",
- containsInterface("GroupingModulTest", groupingUsesModulData));
+ containsInterface("GroupingModulTest", groupingUsesModulData);
assertEquals("Number of method in GroupingUsesModulData is incorrect", 0, groupingUsesModulData
.getMethodDefinitions().size());
"org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev2013718.grouping.rpc.input.test",
containerGroupingRpcInputTest.getPackageName());
- assertTrue("RpcTestInput doesn't extend GroupingRpcInputTest.",
- containsInterface("GroupingRpcInputTest", rpcTestInput));
- assertTrue("RpcTestOutput doesn't extend GroupingRpcOutputTest.",
- containsInterface("GroupingRpcOutputTest", rpcTestOutput));
+ containsInterface("GroupingRpcInputTest", rpcTestInput);
+ containsInterface("GroupingRpcOutputTest", rpcTestOutput);
assertEquals("Number of method in RpcTestInput is incorrect", 0, rpcTestInput.getMethodDefinitions().size());
assertEquals("Number of method in RpcTestOutput is incorrect", 0, rpcTestOutput.getMethodDefinitions().size());
"org.opendaylight.yang.gen.v1.urn.grouping.uses.augment.rev2013718",
groupingAugmentTest.getPackageName());
- assertTrue("ContainerAugment1 doesn't extend GroupingAugmentTest.",
- containsInterface("GroupingAugmentTest", containerAugment1));
+ containsInterface("GroupingAugmentTest", containerAugment1);
assertEquals("Number of method in GroupingCaseTest is incorrect", 0, containerAugment1.getMethodDefinitions()
.size());
"org.opendaylight.yang.gen.v1.urn.grouping.uses.notification.rev2013718.grouping.notification.test",
containerGroupingNotificationTest.getPackageName());
- assertTrue("NotificationTest doesn't extend GroupingNotificationTest.",
- containsInterface("GroupingNotificationTest", notificationTest));
+ containsInterface("GroupingNotificationTest", notificationTest);
assertEquals("Number of method in NotificationTest is incorrect", 1, notificationTest.getMethodDefinitions()
.size());