Lookup leaf key methods in parents
[mdsal.git] / binding / mdsal-binding-generator-impl / src / test / java / org / opendaylight / mdsal / binding / generator / impl / Mdsal161Test.java
diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal161Test.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal161Test.java
new file mode 100644 (file)
index 0000000..8f2301b
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.generator.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+import java.util.Optional;
+import org.junit.Test;
+import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
+import org.opendaylight.mdsal.binding.model.api.Type;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+
+public class Mdsal161Test {
+
+    /**
+     * Test if leaves with inner union type defined in groupings can be used as list keys at the place of instantiation.
+     */
+    @Test
+    public void mdsal269Test() throws Exception {
+        final SchemaContext context = YangParserTestUtils.parseYangSource("/mdsal161.yang");
+        final Collection<Type> types = new BindingGeneratorImpl(false).generateTypes(context);
+        assertNotNull(types);
+        assertEquals(24, types.size());
+
+        assertKeyStructure(types, "org.opendaylight.yang.gen.v1.mdsal161.rev700101.WithGrpKey");
+        assertKeyStructure(types, "org.opendaylight.yang.gen.v1.mdsal161.rev700101.WithGrpExtKey");
+        assertKeyStructure(types, "org.opendaylight.yang.gen.v1.mdsal161.rev700101.WithGrpTypedefKey");
+        assertKeyStructure(types, "org.opendaylight.yang.gen.v1.mdsal161.rev700101.WithoutGrpKey");
+        assertKeyStructure(types, "org.opendaylight.yang.gen.v1.mdsal161.rev700101.WithoutGrpExtKey");
+        assertKeyStructure(types, "org.opendaylight.yang.gen.v1.mdsal161.rev700101.WithoutGrpTypedefKey");
+    }
+
+    private static void assertKeyStructure(final Collection<Type> types, final String className) {
+        final Optional<Type> optType = types.stream().filter(t -> t.getFullyQualifiedName().equals(className))
+                .findFirst();
+        assertTrue("Type for " + className + " not found", optType.isPresent());
+
+        final Type type = optType.get();
+        assertTrue(type instanceof GeneratedTransferObject);
+        final GeneratedTransferObject gto = (GeneratedTransferObject) type;
+        assertEquals(2, gto.getEqualsIdentifiers().size());
+    }
+}