From 213f9b58d6e73d8760fc3daee16117d17a13d8d0 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 5 Oct 2021 14:07:18 +0200 Subject: [PATCH] Fix yang-export warnings We have a number of tests using deprecated methods, migrate them to silence warnings. Also schedule those methods for removal. Change-Id: I189c3c6dad4110413cb33d2d713a6b65aafa6cf4 Signed-off-by: Robert Varga --- .../yang/model/export/YinExportUtils.java | 4 ++-- .../model/export/AbstractYinExportTest.java | 18 +++++++++--------- .../yang/model/export/Bug5531Test.java | 8 ++++---- .../yang/model/export/Bug6856Test.java | 7 ++++--- .../yang/model/export/SimpleModuleTest.java | 2 +- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/model/yang-model-export/src/main/java/org/opendaylight/yangtools/yang/model/export/YinExportUtils.java b/model/yang-model-export/src/main/java/org/opendaylight/yangtools/yang/model/export/YinExportUtils.java index ce289805e8..3d60db7181 100644 --- a/model/yang-model-export/src/main/java/org/opendaylight/yangtools/yang/model/export/YinExportUtils.java +++ b/model/yang-model-export/src/main/java/org/opendaylight/yangtools/yang/model/export/YinExportUtils.java @@ -71,7 +71,7 @@ public final class YinExportUtils { * @deprecated Prefer {@link #writeModuleAsYinText(ModuleEffectiveStatement, OutputStream)}. */ @Beta - @Deprecated + @Deprecated(forRemoval = true) public static void writeModuleAsYinText(final Module module, final OutputStream output) throws XMLStreamException { writeModuleAsYinText(module.asEffectiveStatement(), output); } @@ -105,7 +105,7 @@ public final class YinExportUtils { * OutputStream)}. */ @Beta - @Deprecated + @Deprecated(forRemoval = true) public static void writeSubmoduleAsYinText(final Module parentModule, final Submodule submodule, final OutputStream output) throws XMLStreamException { writeSubmoduleAsYinText(parentModule.asEffectiveStatement(), submodule.asEffectiveStatement(), output); diff --git a/model/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/AbstractYinExportTest.java b/model/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/AbstractYinExportTest.java index 004ea00c73..2b6f57a1aa 100644 --- a/model/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/AbstractYinExportTest.java +++ b/model/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/AbstractYinExportTest.java @@ -18,8 +18,8 @@ import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.ElementNameAndAttributeQualifier; import org.custommonkey.xmlunit.XMLAssert; import org.custommonkey.xmlunit.XMLUnit; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.Submodule; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.w3c.dom.Document; @@ -28,7 +28,7 @@ import org.xml.sax.SAXException; abstract class AbstractYinExportTest { final void exportYinModules(final String yangDir, final String yinDir) throws IOException, SAXException, XMLStreamException { - final SchemaContext schemaContext = YangParserTestUtils.parseYangResourceDirectory(yangDir); + final EffectiveModelContext schemaContext = YangParserTestUtils.parseYangResourceDirectory(yangDir); final Collection modules = schemaContext.getModules(); assertNotEquals(0, modules.size()); @@ -50,13 +50,13 @@ abstract class AbstractYinExportTest { } } - private void readAndValidateModule(final SchemaContext schemaContext, final Module module, final String yinDir) - throws XMLStreamException, IOException, SAXException { + private void readAndValidateModule(final EffectiveModelContext schemaContext, final Module module, + final String yinDir) throws XMLStreamException, IOException, SAXException { final String fileName = YinExportUtils.wellFormedYinName(module.getName(), module.getRevision()); validateOutput(yinDir, fileName, export(module)); } - private void readAndValidateSubmodule(final SchemaContext schemaContext, final Module module, + private void readAndValidateSubmodule(final EffectiveModelContext schemaContext, final Module module, final Submodule submodule, final String yinDir) throws XMLStreamException, IOException, SAXException { final String fileName = YinExportUtils.wellFormedYinName(submodule.getName(), submodule.getRevision()); validateOutput(yinDir, fileName, export(module, submodule)); @@ -64,14 +64,14 @@ abstract class AbstractYinExportTest { private static String export(final Module module) throws XMLStreamException { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); - YinExportUtils.writeModuleAsYinText(module, bos); - return new String(bos.toByteArray(), StandardCharsets.UTF_8); + YinExportUtils.writeModuleAsYinText(module.asEffectiveStatement(), bos); + return bos.toString(StandardCharsets.UTF_8); } private static String export(final Module module, final Submodule submodule) throws XMLStreamException { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); - YinExportUtils.writeSubmoduleAsYinText(module, submodule, bos); - return new String(bos.toByteArray(), StandardCharsets.UTF_8); + YinExportUtils.writeSubmoduleAsYinText(module.asEffectiveStatement(), submodule.asEffectiveStatement(), bos); + return bos.toString(StandardCharsets.UTF_8); } private static void assertXMLEquals(final String fileName, final Document expectedXMLDoc, final String output) diff --git a/model/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/Bug5531Test.java b/model/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/Bug5531Test.java index c2320367f5..c694dfc06f 100644 --- a/model/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/Bug5531Test.java +++ b/model/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/Bug5531Test.java @@ -15,14 +15,14 @@ import static org.junit.Assert.assertTrue; import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import org.junit.Test; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; +import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class Bug5531Test { @Test public void test() throws Exception { - SchemaContext schema = YangParserTestUtils.parseYangResourceDirectory("/bugs/bug5531"); + EffectiveModelContext schema = YangParserTestUtils.parseYangResourceDirectory("/bugs/bug5531"); assertNotNull(schema); assertNotNull(schema.getModules()); @@ -32,7 +32,7 @@ public class Bug5531Test { BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream); // write small module of size less than 8kB - for (Module module : schema.getModules()) { + for (ModuleEffectiveStatement module : schema.getModuleStatements().values()) { YinExportUtils.writeModuleAsYinText(module, bufferedOutputStream); } diff --git a/model/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/Bug6856Test.java b/model/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/Bug6856Test.java index b2f8fe312c..68c4a86ee6 100644 --- a/model/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/Bug6856Test.java +++ b/model/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/Bug6856Test.java @@ -17,6 +17,7 @@ import java.io.ByteArrayOutputStream; import java.io.OutputStream; import org.junit.Test; import org.opendaylight.yangtools.yang.common.Revision; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; @@ -25,7 +26,7 @@ public class Bug6856Test { @Test public void testImplicitInputAndOutputInRpc() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(Bug6856Test.class, + final EffectiveModelContext schemaContext = YangParserTestUtils.parseYangResources(Bug6856Test.class, "/bugs/bug-6856/foo.yang"); assertNotNull(schemaContext); @@ -33,7 +34,7 @@ public class Bug6856Test { final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream); final Module fooModule = schemaContext.findModule("foo", Revision.of("2017-02-28")).get(); - YinExportUtils.writeModuleAsYinText(fooModule, bufferedOutputStream); + YinExportUtils.writeModuleAsYinText(fooModule.asEffectiveStatement(), bufferedOutputStream); final String output = byteArrayOutputStream.toString(); assertNotNull(output); @@ -53,7 +54,7 @@ public class Bug6856Test { final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream); final Module barModule = schemaContext.findModule("bar", Revision.of("2017-02-28")).get(); - YinExportUtils.writeModuleAsYinText(barModule, bufferedOutputStream); + YinExportUtils.writeModuleAsYinText(barModule.asEffectiveStatement(), bufferedOutputStream); final String output = byteArrayOutputStream.toString(); assertNotNull(output); diff --git a/model/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/SimpleModuleTest.java b/model/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/SimpleModuleTest.java index e4aa534c71..4716eded62 100644 --- a/model/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/SimpleModuleTest.java +++ b/model/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/SimpleModuleTest.java @@ -79,7 +79,7 @@ public class SimpleModuleTest { throws Exception { final File outFile = new File(outDir, YinExportUtils.wellFormedYinName(module.getName(), module.getRevision())); try (OutputStream output = new FileOutputStream(outFile)) { - YinExportUtils.writeModuleAsYinText(module, output); + YinExportUtils.writeModuleAsYinText(module.asEffectiveStatement(), output); } return outFile; } -- 2.36.6