X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Frepo%2FSchemaContextFactoryDeviationsTest.java;h=82a85c0d04fcfa60c5713bff1790c614cab7c318;hb=13c63e40f626d56f7bed0acc5d413671a39048e3;hp=6cafef6803e0befa3fb58582afd7b9757044f4e1;hpb=2ce5c16564c49ee32aea1f82e08974f2fbb25941;p=yangtools.git 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);