Split out Bug1862Test 00/96900/4
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 15 Jul 2021 12:44:24 +0000 (14:44 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 15 Jul 2021 15:05:22 +0000 (17:05 +0200)
We have a disabled test here. Split it out and reactivate it.

Change-Id: I38b72751eb38bc492208fdd47af0534c8b6b6c4d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Bug1862Test.java [new file with mode: 0644]
binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/yang/types/TypeProviderTest.java
binding/mdsal-binding-generator/src/test/resources/test-type-provider.yang

diff --git a/binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Bug1862Test.java b/binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Bug1862Test.java
new file mode 100644 (file)
index 0000000..670275c
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2021 PANTHEON.tech, 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.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+
+import com.google.common.collect.ImmutableRangeSet;
+import com.google.common.collect.Range;
+import com.google.common.collect.RangeSet;
+import java.util.List;
+import org.junit.Test;
+import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
+import org.opendaylight.mdsal.binding.model.api.GeneratedType;
+import org.opendaylight.mdsal.binding.model.api.MethodSignature;
+import org.opendaylight.mdsal.binding.model.api.Type;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+
+public class Bug1862Test {
+    @Test
+    public void restrictedTypedefTransformationTest() {
+        final EffectiveModelContext context = YangParserTestUtils.parseYangResources(Bug1862Test.class,
+            "/base-yang-types.yang", "/test-type-provider.yang");
+        final List<GeneratedType> types = DefaultBindingGenerator.generateFor(context);
+        assertEquals(41, types.size());
+        final MethodSignature fooGetter = types.stream()
+            .filter(type -> type.getFullyQualifiedName().equals(
+                "org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.type.provider.model.rev140912.Foo"))
+            .findFirst().orElseThrow()
+            .getMethodDefinitions().stream()
+            .filter(method -> method.getName().equals("getBug1862RestrictedTypedef"))
+            .findFirst().orElseThrow();
+
+        final Type returnType = fooGetter.getReturnType();
+        assertThat(returnType, instanceOf(GeneratedTransferObject.class));
+        final RangeSet<?> range = ((GeneratedTransferObject) returnType).getRestrictions().getRangeConstraint()
+            .orElseThrow().getAllowedRanges();
+        assertEquals(ImmutableRangeSet.of(Range.closed((byte) 1, (byte) 100)), range);
+    }
+}
\ No newline at end of file
index 954289562e6e4e76b152238840c19380ba914280..64715448bad80a5ef425c60ff7ca50e3c01cd93f 100644 (file)
@@ -183,22 +183,6 @@ public class TypeProviderTest {
         return result;
     }
 
-    // FIXME: Remove @Ignore annotation once the bug https://bugs.opendaylight.org/show_bug.cgi?id=1862 is fixed
-    @Ignore
-    @Test
-    public void bug1862RestrictedTypedefTransformationTest() {
-        final AbstractTypeProvider provider = new CodegenTypeProvider(SCHEMA_CONTEXT);
-        final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(TEST_TYPE_PROVIDER, "foo",
-            "bug-1862-restricted-typedef");
-
-        final TypeDefinition<?> leafType = leaf.getType();
-        final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(leafType);
-        final Type result = provider.javaTypeForSchemaDefinitionType(leafType, leaf, restrictions);
-        assertNotNull(result);
-        assertTrue(result instanceof GeneratedTransferObject);
-        //TODO: complete test after bug 1862 is fixed
-    }
-
     @Test
     public void javaTypeForSchemaDefinitionEnumExtTypeTest() {
         final AbstractTypeProvider provider = new CodegenTypeProvider(SCHEMA_CONTEXT);
index ab4418c8bed2b5f26e83564281a16f7ca229de34..e64270954f72e8138b4c45240edd92f28240f278 100644 (file)
@@ -270,7 +270,7 @@ module test-type-provider {
 
         leaf foo-cond-bar-item {
             type leafref {
-                path "../../foo/bars/bar-item[id=current()/../bar-id]";
+                path "../../foo/bars/bar-item[id=current()/../bar-id]/id";
             }
         }