From 13c63e40f626d56f7bed0acc5d413671a39048e3 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 10 Feb 2021 17:02:37 +0100 Subject: [PATCH] Clean up SchemaContextFactoryDeviationsTest We are being overly verbose here and use SchemaContextUtil for functionality readily available. Clean up the test, removing yet another user of SchemaContextUtil. JIRA: YANGTOOLS-1052 Change-Id: I4145e3d715cd1a2f524a892c178719f178d96e07 Signed-off-by: Robert Varga --- .../SchemaContextFactoryDeviationsTest.java | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/SchemaContextFactoryDeviationsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/SchemaContextFactoryDeviationsTest.java index 6cafef6803..82a85c0d04 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/SchemaContextFactoryDeviationsTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/SchemaContextFactoryDeviationsTest.java @@ -10,8 +10,9 @@ package org.opendaylight.yangtools.yang.parser.repo; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.startsWith; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; @@ -21,6 +22,7 @@ import com.google.common.collect.SetMultimap; import com.google.common.util.concurrent.ListenableFuture; import java.util.ArrayList; import java.util.Collection; +import java.util.Optional; import java.util.concurrent.ExecutionException; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; @@ -28,12 +30,9 @@ import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.Revision; import org.opendaylight.yangtools.yang.common.XMLNamespace; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration; import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; -import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; import org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource; import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer; import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException; @@ -70,28 +69,28 @@ public class SchemaContextFactoryDeviationsTest { final ListenableFuture lf = createSchemaContext(modulesWithSupportedDeviations, FOO, BAR, BAZ, FOOBAR); assertTrue(lf.isDone()); - final SchemaContext schemaContext = lf.get(); + final EffectiveModelContext schemaContext = lf.get(); assertNotNull(schemaContext); - assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_A))); - assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_B))); - assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_C))); - assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_BAR_CONT_A))); - assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_BAR_CONT_B))); + assertAbsent(schemaContext, MY_FOO_CONT_A); + assertAbsent(schemaContext, MY_FOO_CONT_B); + assertPresent(schemaContext, MY_FOO_CONT_C); + assertAbsent(schemaContext, MY_BAR_CONT_A); + assertPresent(schemaContext, MY_BAR_CONT_B); } @Test public void testDeviationsSupportedInAllModules() throws Exception { final ListenableFuture lf = createSchemaContext(null, FOO, BAR, BAZ, FOOBAR); assertTrue(lf.isDone()); - final SchemaContext schemaContext = lf.get(); + final EffectiveModelContext schemaContext = lf.get(); assertNotNull(schemaContext); - assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_A))); - assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_B))); - assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_C))); - assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_BAR_CONT_A))); - assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_BAR_CONT_B))); + assertAbsent(schemaContext, MY_FOO_CONT_A); + assertAbsent(schemaContext, MY_FOO_CONT_B); + assertAbsent(schemaContext, MY_FOO_CONT_C); + assertAbsent(schemaContext, MY_BAR_CONT_A); + assertAbsent(schemaContext, MY_BAR_CONT_B); } @Test @@ -99,14 +98,14 @@ public class SchemaContextFactoryDeviationsTest { final ListenableFuture lf = createSchemaContext(ImmutableSetMultimap.of(), FOO, BAR, BAZ, FOOBAR); assertTrue(lf.isDone()); - final SchemaContext schemaContext = lf.get(); + final EffectiveModelContext schemaContext = lf.get(); assertNotNull(schemaContext); - assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_A))); - assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_B))); - assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_FOO_CONT_C))); - assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_BAR_CONT_A))); - assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, MY_BAR_CONT_B))); + assertPresent(schemaContext, MY_FOO_CONT_A); + assertPresent(schemaContext, MY_FOO_CONT_B); + assertPresent(schemaContext, MY_FOO_CONT_C); + assertPresent(schemaContext, MY_BAR_CONT_A); + assertPresent(schemaContext, MY_BAR_CONT_B); } @Test @@ -121,6 +120,14 @@ public class SchemaContextFactoryDeviationsTest { startsWith("Deviation must not target the same module as the one it is defined in")); } + private static void assertAbsent(final EffectiveModelContext schemaContext, final QName qname) { + assertEquals(Optional.empty(), schemaContext.findDataTreeChild(qname)); + } + + private static void assertPresent(final EffectiveModelContext schemaContext, final QName qname) { + assertNotEquals(Optional.empty(), schemaContext.findDataTreeChild(qname)); + } + private static SettableSchemaProvider getImmediateYangSourceProviderFromResource( final String resourceName) throws Exception { final YangTextSchemaSource yangSource = YangTextSchemaSource.forResource(resourceName); -- 2.36.6