Migrate Bug4621Test 97/96897/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 15 Jul 2021 12:16:55 +0000 (14:16 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 15 Jul 2021 12:18:36 +0000 (14:18 +0200)
Move the test into the appropriate package and migrate it to work on top
of DefaultBindingGenerator.

Change-Id: Idc86823388898341d5fe54adc224ad3d5e4fbb27
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/reactor/GeneratorReactor.java
binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Bug4621Test.java [new file with mode: 0644]
binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/yang/types/Bug4621.java [deleted file]

index 6253cfd5481ea9f97318919a400ebebca42d2a5c..5519d1438aa44e5cb4aa9245d6db4464190adaa9 100644 (file)
@@ -305,7 +305,7 @@ public final class GeneratorReactor extends GeneratorContext implements Mutable
         try {
             stmt = inferenceStack.resolvePathExpression(path);
         } catch (IllegalArgumentException e) {
-            throw new IllegalArgumentException("Failed to find leafref target " + path, e);
+            throw new IllegalArgumentException("Failed to find leafref target " + path.getOriginalString(), e);
         }
         return mapToGenerator(stmt);
     }
diff --git a/binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Bug4621Test.java b/binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Bug4621Test.java
new file mode 100644 (file)
index 0000000..4572f4d
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. 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.assertThrows;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+
+public class Bug4621Test {
+    @Test
+    public void testMissingLeafrefTarget() {
+        final EffectiveModelContext context = YangParserTestUtils.parseYangResource("/bug4621.yang");
+        final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
+            () -> DefaultBindingGenerator.generateFor(context));
+        assertEquals("Failed to find leafref target /foo:neighbor/foo:mystring1", ex.getMessage());
+    }
+}
\ No newline at end of file
diff --git a/binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/yang/types/Bug4621.java b/binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/yang/types/Bug4621.java
deleted file mode 100644 (file)
index 65bc201..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.yang.types;
-
-import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertThrows;
-
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.XMLNamespace;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-
-public class Bug4621 {
-    @Test
-    public void bug4621test() {
-        final EffectiveModelContext schemaContext = YangParserTestUtils.parseYangResource("/bug4621.yang");
-        final Module moduleValid = schemaContext.findModules(XMLNamespace.of("foo")).iterator().next();
-        final AbstractTypeProvider typeProvider = new RuntimeTypeProvider(schemaContext);
-
-        final QName listNode = QName.create(moduleValid.getQNameModule(), "neighbor");
-        final QName leafrefNode = QName.create(moduleValid.getQNameModule(), "neighbor2-id");
-        final DataSchemaNode leafrefRel = ((ListSchemaNode) moduleValid.getDataChildByName(listNode))
-                .getDataChildByName(leafrefNode);
-        final LeafSchemaNode leafRel = (LeafSchemaNode) leafrefRel;
-        final TypeDefinition<?> leafTypeRel = leafRel.getType();
-
-        final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
-            () -> typeProvider.javaTypeForSchemaDefinitionType(leafTypeRel, leafRel));
-        assertThat(ex.getMessage(),
-            startsWith("Failed to find leafref target: /foo:neighbor/foo:mystring1 in module foo"));
-    }
-}
\ No newline at end of file