From: Robert Varga Date: Wed, 11 May 2022 15:54:23 +0000 (+0200) Subject: Stabilize and update EffectiveIdentityTest X-Git-Tag: v9.0.0~65 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=yangtools.git;a=commitdiff_plain;h=4050600ef5777852a94fcea178abad08803c0b31 Stabilize and update EffectiveIdentityTest The order of exceptions can vary based on resolution order. Make sure we sort them and make assertions on that. Also improve other assertions in this test suite. Change-Id: I2d8f6f7848f5bd22abbb0284aa4780aec60bd0d8 Signed-off-by: Robert Varga --- diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveIdentityTest.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveIdentityTest.java index e3ba4bcca0..e03bb0a6b5 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveIdentityTest.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveIdentityTest.java @@ -12,13 +12,17 @@ import static org.hamcrest.CoreMatchers.startsWith; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource; import com.google.common.collect.Iterables; -import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; @@ -27,33 +31,48 @@ import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors; import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource; public class EffectiveIdentityTest { - private static final StatementStreamSource IDENTITY_TEST = sourceForResource( "/stmt-test/identity/identity-test.yang"); - private static final StatementStreamSource CYCLIC_IDENTITY_TEST = sourceForResource( "/stmt-test/identity/cyclic-identity-test.yang"); @Test - public void cyclicefineTest() throws SourceException, ReactorException, URISyntaxException { + public void cyclicDefineTest() { final var reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(CYCLIC_IDENTITY_TEST); final var cause = assertThrows(SomeModifiersUnresolvedException.class, reactor::buildEffective).getCause(); assertThat(cause, instanceOf(InferenceException.class)); assertThat(cause.getMessage(), startsWith("Yang model processing phase STATEMENT_DEFINITION failed [at ")); + // This is a bit complicated, as the order of exceptions may differ + final var causes = new ArrayList(); final var cause1 = cause.getCause(); - assertThat(cause1, instanceOf(InferenceException.class)); - assertThat(cause1.getMessage(), startsWith("Unable to resolve identity (cyclic.identity.test)child-identity-1 " - + "and base identity (cyclic.identity.test)child-identity-2 [at ")); + if (cause1 != null) { + causes.add(cause1); + } + causes.addAll(Arrays.asList(cause.getSuppressed())); + causes.sort(Comparator.comparing(Throwable::getMessage)); + assertEquals(4, causes.size()); + causes.forEach(throwable -> assertThat(throwable, instanceOf(InferenceException.class))); + + assertThat(causes.get(0).getMessage(), + startsWith("Unable to resolve identity (cyclic.identity.test)child-identity-1 and base identity " + + "(cyclic.identity.test)child-identity-2 [at ")); + assertThat(causes.get(1).getMessage(), + startsWith("Unable to resolve identity (cyclic.identity.test)child-identity-2 and base identity " + + "(cyclic.identity.test)child-identity-3 [at ")); + assertThat(causes.get(2).getMessage(), + startsWith("Unable to resolve identity (cyclic.identity.test)child-identity-3 and base identity " + + "(cyclic.identity.test)child-identity-4 [at ")); + assertThat(causes.get(3).getMessage(), + startsWith("Unable to resolve identity (cyclic.identity.test)child-identity-4 and base identity " + + "(cyclic.identity.test)child-identity-1 [at ")); } @Test - public void identityTest() throws SourceException, ReactorException, - URISyntaxException { + public void identityTest() throws ReactorException { SchemaContext result = RFC7950Reactors.defaultReactor().newBuild().addSources(IDENTITY_TEST).buildEffective(); assertNotNull(result); @@ -99,10 +118,10 @@ public class EffectiveIdentityTest { assertTrue(rootDerivedIdentities.contains(child1)); assertTrue(rootDerivedIdentities.contains(child2)); assertFalse(rootDerivedIdentities.contains(child12)); - assertFalse(child1.equals(child2)); + assertNotEquals(child1, child2); - assertTrue(root == Iterables.getOnlyElement(child1.getBaseIdentities())); - assertTrue(root == Iterables.getOnlyElement(child2.getBaseIdentities())); + assertSame(root, Iterables.getOnlyElement(child1.getBaseIdentities())); + assertSame(root, Iterables.getOnlyElement(child2.getBaseIdentities())); assertEquals(0, result.getDerivedIdentities(child2).size()); @@ -111,7 +130,7 @@ public class EffectiveIdentityTest { assertTrue(child1DerivedIdentities.contains(child12)); assertFalse(child1DerivedIdentities.contains(child1)); - assertTrue(child1 == Iterables.getOnlyElement(child12.getBaseIdentities())); - assertTrue(child12 == child1DerivedIdentities.iterator().next()); + assertSame(child1, Iterables.getOnlyElement(child12.getBaseIdentities())); + assertSame(child12, child1DerivedIdentities.iterator().next()); } }