X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fsal%2Fyang-prototype%2Fcode-generator%2Fbinding-generator-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Fgenerator%2Fimpl%2FChoiceCaseGenTypesTest.java;h=e283c65a8aebcc36831049116f19b1541d6b237d;hp=ba51672c596f2668badf2a512c42d4836f6b06e0;hb=refs%2Fchanges%2F89%2F789%2F1;hpb=d4c36ceaa53ca2d748d8c53920617d746bb4fecb diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/ChoiceCaseGenTypesTest.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/ChoiceCaseGenTypesTest.java index ba51672c59..e283c65a8a 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/ChoiceCaseGenTypesTest.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/ChoiceCaseGenTypesTest.java @@ -7,7 +7,11 @@ */ 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; @@ -17,6 +21,8 @@ import java.util.Set; 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; @@ -39,6 +45,30 @@ public class ChoiceCaseGenTypesTest { } } + private static GeneratedType checkGeneratedType(List 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 genTypes, String genTypeName, String packageName) { + return checkGeneratedType(genTypes, genTypeName, packageName, 1); + } + @Test public void choiceCaseResolvingTypeTest() { final YangModelParser parser = new YangParserImpl(); @@ -51,5 +81,111 @@ public class ChoiceCaseGenTypesTest { 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")); + 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", 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", 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")); + 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); + } }