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.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.opendaylight.mdsal.binding.generator.impl.SupportTestUtil.containsInterface;
14 import static org.opendaylight.mdsal.binding.generator.impl.SupportTestUtil.containsMethods;
16 import java.util.List;
17 import org.junit.Test;
18 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
19 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
20 import org.opendaylight.mdsal.binding.model.api.Type;
21 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
23 public class ChoiceCaseGenTypesTest extends AbstractTypesTest {
25 public ChoiceCaseGenTypesTest() {
26 super(ChoiceCaseGenTypesTest.class.getResource("/choice-case-type-test-models"));
29 private static GeneratedType checkGeneratedType(final List<Type> genTypes, final String genTypeName,
30 final String packageName, final int occurences) {
31 GeneratedType searchedGenType = null;
32 int searchedGenTypeCounter = 0;
33 for (Type type : genTypes) {
34 if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
35 GeneratedType genType = (GeneratedType) type;
36 if (genType.getName().equals(genTypeName) && genType.getPackageName().equals(packageName)) {
37 searchedGenType = genType;
38 searchedGenTypeCounter++;
42 assertNotNull("Generated type " + genTypeName + " wasn't found", searchedGenType);
43 assertEquals(genTypeName + " generated type has incorrect number of occurences.", occurences,
44 searchedGenTypeCounter);
45 return searchedGenType;
49 private static GeneratedType checkGeneratedType(final List<Type> genTypes, final String genTypeName,
50 final String packageName) {
51 return checkGeneratedType(genTypes, genTypeName, packageName, 1);
55 public void choiceCaseResolvingTypeTest() {
56 final List<Type> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangFiles(testModels));
58 assertNotNull("genTypes is null", genTypes);
59 assertFalse("genTypes is empty", genTypes.isEmpty());
61 // test for file choice-monitoring
62 String pcgPref = "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.choice.monitoring.rev130701."
63 + "netconf.state.datastores.datastore.locks";
64 GeneratedType genType = null;
66 checkGeneratedType(genTypes, "LockType", pcgPref); // choice
68 genType = checkGeneratedType(genTypes, "GlobalLock", pcgPref + ".lock.type"); // case
69 SupportTestUtil.containsMethods(genType, new NameTypePattern("getGlobalLock", "GlobalLock"));
70 containsInterface("LockType", genType);
72 genType = checkGeneratedType(genTypes, "PartialLock", pcgPref + ".lock.type"); // case
73 containsMethods(genType, new NameTypePattern("getPartialLock", "Map<PartialLockKey,PartialLock>"));
74 containsInterface("LockType", genType);
76 genType = checkGeneratedType(genTypes, "Fingerprint", pcgPref + ".lock.type"); // case
77 containsMethods(genType, new NameTypePattern("getAlgorithmAndHash", "AlgorithmAndHash"));
78 containsInterface("LockType", genType);
80 genType = checkGeneratedType(genTypes, "AlgorithmAndHash", pcgPref + ".lock.type.fingerprint"); // choice
82 genType = checkGeneratedType(genTypes, "Md5", pcgPref + ".lock.type.fingerprint.algorithm.and.hash"); // case
83 containsMethods(genType, new NameTypePattern("getMd5", "TlsFingerprintType"));
84 containsInterface("AlgorithmAndHash", genType);
86 genType = checkGeneratedType(genTypes, "Sha1", pcgPref + ".lock.type.fingerprint.algorithm.and.hash"); // case
87 containsMethods(genType, new NameTypePattern("getSha1", "TlsFingerprintType"));
88 containsInterface("AlgorithmAndHash", genType);
90 genType = checkGeneratedType(genTypes, "Sha224", pcgPref + ".lock.type.fingerprint.algorithm.and.hash"); // case
91 containsMethods(genType, new NameTypePattern("getSha224", "TlsFingerprintType"));
92 containsInterface("AlgorithmAndHash", genType);
94 genType = checkGeneratedType(genTypes, "Sha256", pcgPref + ".lock.type.fingerprint.algorithm.and.hash"); // case
95 containsMethods(genType, new NameTypePattern("getSha256", "TlsFingerprintType"));
96 containsInterface("AlgorithmAndHash", genType);
98 genType = checkGeneratedType(genTypes, "Sha384", pcgPref + ".lock.type.fingerprint.algorithm.and.hash"); // case
99 containsMethods(genType, new NameTypePattern("getSha384", "TlsFingerprintType"));
100 containsInterface("AlgorithmAndHash", genType);
102 genType = checkGeneratedType(genTypes, "Sha512", pcgPref + ".lock.type.fingerprint.algorithm.and.hash"); // case
103 containsMethods(genType, new NameTypePattern("getSha512", "TlsFingerprintType"));
104 containsInterface("AlgorithmAndHash", genType);
106 // test for file augment-monitoring
108 // "/nm:netconf-state/nm:datastores/nm:datastore/nm:locks/nm:lock-type"
109 pcgPref = "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.augment.monitoring.rev130701";
111 genType = checkGeneratedType(genTypes, "AutonomousLock", pcgPref
112 + ".netconf.state.datastores.datastore.locks.lock.type"); // choice
113 containsMethods(genType, new NameTypePattern("getAutonomousDef", "AutonomousDef"));
114 containsInterface("LockType", genType);
116 genType = checkGeneratedType(genTypes, "AnonymousLock", pcgPref
117 + ".netconf.state.datastores.datastore.locks.lock.type"); // choice
118 containsMethods(genType, new NameTypePattern("getLockTime", "Uint32"));
119 containsInterface("LockType", genType);
121 genType = checkGeneratedType(genTypes, "LeafAugCase", pcgPref
122 + ".netconf.state.datastores.datastore.locks.lock.type"); // choice
123 containsMethods(genType, new NameTypePattern("getLeafAugCase", "String"));
124 containsInterface("LockType", genType);
127 // "/nm:netconf-state/nm:datastores/nm:datastore/nm:locks/nm:lock-type/nm:partial-lock"
129 genType = checkGeneratedType(genTypes, "PartialLock1", pcgPref); // case
130 containsMethods(genType, new NameTypePattern("getAugCaseByChoice", "AugCaseByChoice"));
131 containsInterface("Augmentation<PartialLock>", genType);
133 genType = checkGeneratedType(genTypes, "AugCaseByChoice", pcgPref
134 + ".netconf.state.datastores.datastore.locks.lock.type.partial.lock"); // choice
136 genType = checkGeneratedType(genTypes, "Foo", pcgPref
137 + ".netconf.state.datastores.datastore.locks.lock.type.partial.lock.aug._case.by.choice"); // case
138 containsMethods(genType, new NameTypePattern("getFoo", "String"));
139 containsInterface("AugCaseByChoice", genType);
141 genType = checkGeneratedType(genTypes, "Bar", pcgPref
142 + ".netconf.state.datastores.datastore.locks.lock.type.partial.lock.aug._case.by.choice"); // case
143 containsMethods(genType, new NameTypePattern("getBar", "Boolean"));
144 containsMethods(genType, new NameTypePattern("isBar", "Boolean"));
145 containsInterface("AugCaseByChoice", genType);
147 // augment "/nm:netconf-state/nm:datastores/nm:datastore" {
148 genType = checkGeneratedType(genTypes, "Datastore1", pcgPref);
149 containsMethods(genType, new NameTypePattern("getStorageFormat", "StorageFormat"));
150 containsInterface("Augmentation<Datastore>", genType);
153 genType = checkGeneratedType(genTypes, "StorageFormat", pcgPref + ".netconf.state.datastores.datastore");
155 genType = checkGeneratedType(genTypes, "UnknownFiles", pcgPref
156 + ".netconf.state.datastores.datastore.storage.format"); // case
157 containsMethods(genType, new NameTypePattern("getFiles", "Map<FilesKey,Files>"));
158 containsInterface("StorageFormat", genType);
161 genType = checkGeneratedType(genTypes, "Xml", pcgPref + ".netconf.state.datastores.datastore.storage.format");
162 containsMethods(genType, new NameTypePattern("getXmlDef", "XmlDef"));
163 containsInterface("StorageFormat", genType);
166 genType = checkGeneratedType(genTypes, "Yang", pcgPref + ".netconf.state.datastores.datastore.storage.format");
167 containsMethods(genType, new NameTypePattern("getYangFileName", "String"));
168 containsInterface("StorageFormat", genType);