Clean up PatternConstraint's String confusion
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / TypesResolutionTest.java
index 01c44391d570053942492bd369343e0dc5baa269..4588fc2962174ce1fd41132770fdf2b636f3109c 100644 (file)
@@ -10,18 +10,24 @@ package org.opendaylight.yangtools.yang.stmt;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Range;
 import java.net.URI;
 import java.util.List;
+import java.util.Optional;
 import java.util.Set;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.Status;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
@@ -35,40 +41,34 @@ import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
 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;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
 
 public class TypesResolutionTest {
-    private Set<Module> testedModules;
+    private SchemaContext context;
 
     @Before
     public void init() throws Exception {
-        final StatementStreamSource yangFile =
-                new YangStatementSourceImpl("/types/custom-types-test@2012-4-4.yang", false);
-        final StatementStreamSource yangFileDependency1 =
-                new YangStatementSourceImpl ("/ietf/iana-timezones@2012-07-09.yang", false);
-        final StatementStreamSource yangFileDependency2 =
-                new YangStatementSourceImpl ("/ietf/ietf-inet-types@2010-09-24.yang", false);
-        final StatementStreamSource yangFileDependency3 =
-                new YangStatementSourceImpl ("/ietf/ietf-yang-types@2010-09-24.yang", false);
-
-        testedModules = TestUtils.parseYangSources(yangFile, yangFileDependency1, yangFileDependency2,
-                yangFileDependency3).getModules();
-        assertEquals(4, testedModules.size());
+        final StatementStreamSource yangFile = sourceForResource("/types/custom-types-test@2012-04-04.yang");
+        final StatementStreamSource yangFileDependency1 = sourceForResource("/ietf/iana-timezones@2012-07-09.yang");
+        final StatementStreamSource yangFileDependency2 = sourceForResource("/ietf/ietf-inet-types@2010-09-24.yang");
+        final StatementStreamSource yangFileDependency3 = sourceForResource("/ietf/ietf-yang-types@2010-09-24.yang");
+        context = TestUtils.parseYangSources(yangFile, yangFileDependency1, yangFileDependency2, yangFileDependency3);
+        assertEquals(4, context.getModules().size());
     }
 
     @Test
     public void testIPVersion() {
-        Module tested = TestUtils.findModule(testedModules, "ietf-inet-types");
+        Module tested = TestUtils.findModule(context, "ietf-inet-types").get();
         Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
         assertEquals(14, typedefs.size());
 
         TypeDefinition<?> type = TestUtils.findTypedef(typedefs, "ip-version");
-        assertTrue(type.getDescription().contains("This value represents the version of the IP protocol."));
-        assertTrue(type.getReference().contains("RFC 2460: Internet Protocol, Version 6 (IPv6) Specification"));
+        assertTrue(type.getDescription().get().contains("This value represents the version of the IP protocol."));
+        assertTrue(type.getReference().get().contains("RFC 2460: Internet Protocol, Version 6 (IPv6) Specification"));
 
         EnumTypeDefinition enumType = (EnumTypeDefinition) type.getBaseType();
         List<EnumPair> values = enumType.getValues();
@@ -76,23 +76,24 @@ public class TypesResolutionTest {
 
         EnumPair value0 = values.get(0);
         assertEquals("unknown", value0.getName());
-        assertEquals(0, (int) value0.getValue());
-        assertEquals("An unknown or unspecified version of the Internet protocol.", value0.getDescription());
+        assertEquals(0, value0.getValue());
+        assertEquals(Optional.of("An unknown or unspecified version of the Internet protocol."),
+            value0.getDescription());
 
         EnumPair value1 = values.get(1);
         assertEquals("ipv4", value1.getName());
-        assertEquals(1, (int) value1.getValue());
-        assertEquals("The IPv4 protocol as defined in RFC 791.", value1.getDescription());
+        assertEquals(1, value1.getValue());
+        assertEquals(Optional.of("The IPv4 protocol as defined in RFC 791."), value1.getDescription());
 
         EnumPair value2 = values.get(2);
         assertEquals("ipv6", value2.getName());
-        assertEquals(2, (int) value2.getValue());
-        assertEquals("The IPv6 protocol as defined in RFC 2460.", value2.getDescription());
+        assertEquals(2, value2.getValue());
+        assertEquals(Optional.of("The IPv6 protocol as defined in RFC 2460."), value2.getDescription());
     }
 
     @Test
     public void testEnumeration() {
-        Module tested = TestUtils.findModule(testedModules, "custom-types-test");
+        Module tested = TestUtils.findModule(context, "custom-types-test").get();
         Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
 
         TypeDefinition<?> type = TestUtils.findTypedef(typedefs, "ip-version");
@@ -102,74 +103,75 @@ public class TypesResolutionTest {
 
         EnumPair value0 = values.get(0);
         assertEquals("unknown", value0.getName());
-        assertEquals(0, (int) value0.getValue());
-        assertEquals("An unknown or unspecified version of the Internet protocol.", value0.getDescription());
+        assertEquals(0, value0.getValue());
+        assertEquals(Optional.of("An unknown or unspecified version of the Internet protocol."),
+            value0.getDescription());
 
         EnumPair value1 = values.get(1);
         assertEquals("ipv4", value1.getName());
-        assertEquals(19, (int) value1.getValue());
-        assertEquals("The IPv4 protocol as defined in RFC 791.", value1.getDescription());
+        assertEquals(19, value1.getValue());
+        assertEquals(Optional.of("The IPv4 protocol as defined in RFC 791."), value1.getDescription());
 
         EnumPair value2 = values.get(2);
         assertEquals("ipv6", value2.getName());
-        assertEquals(7, (int) value2.getValue());
-        assertEquals("The IPv6 protocol as defined in RFC 2460.", value2.getDescription());
+        assertEquals(7, value2.getValue());
+        assertEquals(Optional.of("The IPv6 protocol as defined in RFC 2460."), value2.getDescription());
 
         EnumPair value3 = values.get(3);
         assertEquals("default", value3.getName());
-        assertEquals(20, (int) value3.getValue());
-        assertEquals("default ip", value3.getDescription());
+        assertEquals(20, value3.getValue());
+        assertEquals(Optional.of("default ip"), value3.getDescription());
     }
 
     @Test
     public void testIpAddress() {
-        Module tested = TestUtils.findModule(testedModules, "ietf-inet-types");
+        Module tested = TestUtils.findModule(context, "ietf-inet-types").get();
         Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
         TypeDefinition<?> type = TestUtils.findTypedef(typedefs, "ip-address");
         UnionTypeDefinition baseType = (UnionTypeDefinition) type.getBaseType();
         List<TypeDefinition<?>> unionTypes = baseType.getTypes();
 
         StringTypeDefinition ipv4 = (StringTypeDefinition) unionTypes.get(0);
-        assertTrue(ipv4.getBaseType() instanceof StringTypeDefinition);
+        assertNotNull(ipv4.getBaseType());
         String expectedPattern = "^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}"
                 + "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" + "(%[\\p{N}\\p{L}]+)?$";
-        assertEquals(expectedPattern, ipv4.getPatternConstraints().get(0).getRegularExpression());
+        assertEquals(expectedPattern, ipv4.getPatternConstraints().get(0).getJavaPatternString());
 
         StringTypeDefinition ipv6 = (StringTypeDefinition) unionTypes.get(1);
-        assertTrue(ipv6.getBaseType() instanceof StringTypeDefinition);
+        assertNotNull(ipv6.getBaseType());
         List<PatternConstraint> ipv6Patterns = ipv6.getPatternConstraints();
         expectedPattern = "^((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}"
                 + "((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|" + "(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}"
                 + "(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))" + "(%[\\p{N}\\p{L}]+)?$";
-        assertEquals(expectedPattern, ipv6Patterns.get(0).getRegularExpression());
+        assertEquals(expectedPattern, ipv6Patterns.get(0).getJavaPatternString());
 
         expectedPattern = "^(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|" + "((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)"
                 + "(%.+)?$";
-        assertEquals(expectedPattern, ipv6Patterns.get(1).getRegularExpression());
+        assertEquals(expectedPattern, ipv6Patterns.get(1).getJavaPatternString());
     }
 
     @Test
     public void testDomainName() {
-        Module tested = TestUtils.findModule(testedModules, "ietf-inet-types");
+        Module tested = TestUtils.findModule(context, "ietf-inet-types").get();
         Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
         StringTypeDefinition type = (StringTypeDefinition) TestUtils.findTypedef(typedefs, "domain-name");
-        assertTrue(type.getBaseType() instanceof StringTypeDefinition);
+        assertNotNull(type.getBaseType());
         List<PatternConstraint> patterns = type.getPatternConstraints();
         assertEquals(1, patterns.size());
         String expectedPattern = "^((([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.)*"
                 + "([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.?)" + "|\\.$";
-        assertEquals(expectedPattern, patterns.get(0).getRegularExpression());
+        assertEquals(expectedPattern, patterns.get(0).getJavaPatternString());
 
-        List<LengthConstraint> lengths = type.getLengthConstraints();
-        assertEquals(1, lengths.size());
-        LengthConstraint length = type.getLengthConstraints().get(0);
-        assertEquals(Integer.valueOf(1), length.getMin());
-        assertEquals(Integer.valueOf(253), length.getMax());
+        LengthConstraint lengths = type.getLengthConstraint().get();
+        assertEquals(1, lengths.getAllowedRanges().asRanges().size());
+        Range<Integer> length = lengths.getAllowedRanges().span();
+        assertEquals(Integer.valueOf(1), length.lowerEndpoint());
+        assertEquals(Integer.valueOf(253), length.upperEndpoint());
     }
 
     @Test
     public void testInstanceIdentifier1() {
-        Module tested = TestUtils.findModule(testedModules, "custom-types-test");
+        Module tested = TestUtils.findModule(context, "custom-types-test").get();
         LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName(
                 QName.create(tested.getQNameModule(), "inst-id-leaf1"));
         InstanceIdentifierTypeDefinition leafType = (InstanceIdentifierTypeDefinition) leaf.getType();
@@ -179,7 +181,7 @@ public class TypesResolutionTest {
 
     @Test
     public void testInstanceIdentifier2() {
-        Module tested = TestUtils.findModule(testedModules, "custom-types-test");
+        Module tested = TestUtils.findModule(context, "custom-types-test").get();
         LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName(
                 QName.create(tested.getQNameModule(), "inst-id-leaf2"));
         InstanceIdentifierTypeDefinition leafType = (InstanceIdentifierTypeDefinition) leaf.getType();
@@ -188,7 +190,7 @@ public class TypesResolutionTest {
 
     @Test
     public void testIdentity() {
-        Module tested = TestUtils.findModule(testedModules, "custom-types-test");
+        Module tested = TestUtils.findModule(context, "custom-types-test").get();
         Set<IdentitySchemaNode> identities = tested.getIdentities();
         assertEquals(5, identities.size());
         IdentitySchemaNode cryptoAlg = null;
@@ -204,13 +206,13 @@ public class TypesResolutionTest {
             }
         }
         assertNotNull(cryptoAlg);
-        IdentitySchemaNode baseIdentity = cryptoAlg.getBaseIdentity();
+        IdentitySchemaNode baseIdentity = Iterables.getOnlyElement(cryptoAlg.getBaseIdentities());
         assertEquals("crypto-base", baseIdentity.getQName().getLocalName());
         assertTrue(cryptoAlg.getDerivedIdentities().isEmpty());
-        assertNull(baseIdentity.getBaseIdentity());
+        assertTrue(baseIdentity.getBaseIdentities().isEmpty());
 
         assertNotNull(cryptoBase);
-        assertNull(cryptoBase.getBaseIdentity());
+        assertTrue(cryptoBase.getBaseIdentities().isEmpty());
         assertEquals(3, cryptoBase.getDerivedIdentities().size());
 
         assertNotNull(cryptoId);
@@ -219,7 +221,7 @@ public class TypesResolutionTest {
 
     @Test
     public void testBitsType1() {
-        Module tested = TestUtils.findModule(testedModules, "custom-types-test");
+        Module tested = TestUtils.findModule(context, "custom-types-test").get();
         LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName(
                 QName.create(tested.getQNameModule(), "mybits"));
         BitsTypeDefinition leafType = (BitsTypeDefinition) leaf.getType();
@@ -228,20 +230,20 @@ public class TypesResolutionTest {
 
         Bit bit1 = bits.get(0);
         assertEquals("disable-nagle", bit1.getName());
-        assertEquals(0L, (long) bit1.getPosition());
+        assertEquals(0L, bit1.getPosition());
 
         Bit bit2 = bits.get(1);
         assertEquals("auto-sense-speed", bit2.getName());
-        assertEquals(1L, (long) bit2.getPosition());
+        assertEquals(1L, bit2.getPosition());
 
         Bit bit3 = bits.get(2);
         assertEquals("10-Mb-only", bit3.getName());
-        assertEquals(2L, (long) bit3.getPosition());
+        assertEquals(2L, bit3.getPosition());
     }
 
     @Test
     public void testBitsType2() {
-        Module tested = TestUtils.findModule(testedModules, "custom-types-test");
+        Module tested = TestUtils.findModule(context, "custom-types-test").get();
         Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
         TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "access-operations-type");
 
@@ -250,35 +252,40 @@ public class TypesResolutionTest {
         assertEquals(5, bits.size());
 
         Bit bit0 = bits.get(0);
-        assertEquals(0L, (long) bit0.getPosition());
+        assertEquals("create", bit0.getName());
+        assertEquals(0L, bit0.getPosition());
 
         Bit bit1 = bits.get(1);
-        assertEquals(500L, (long) bit1.getPosition());
+        assertEquals("delete", bit1.getName());
+        assertEquals(365L, bit1.getPosition());
 
         Bit bit2 = bits.get(2);
-        assertEquals(501L, (long) bit2.getPosition());
+        assertEquals("read", bit2.getName());
+        assertEquals(500L, bit2.getPosition());
 
         Bit bit3 = bits.get(3);
-        assertEquals(502L, (long) bit3.getPosition());
+        assertEquals("update", bit3.getName());
+        assertEquals(501L, bit3.getPosition());
 
         Bit bit4 = bits.get(4);
-        assertEquals(365L, (long) bit4.getPosition());
+        assertEquals("exec", bit4.getName());
+        assertEquals(502L, bit4.getPosition());
     }
 
     @Test
     public void testIanaTimezones() {
-        Module tested = TestUtils.findModule(testedModules, "iana-timezones");
+        Module tested = TestUtils.findModule(context, "iana-timezones").get();
         Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
         TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "iana-timezone");
 
         String expectedDesc = "A timezone location as defined by the IANA timezone";
-        assertTrue(testedType.getDescription().contains(expectedDesc));
-        assertNull(testedType.getReference());
+        assertTrue(testedType.getDescription().get().contains(expectedDesc));
+        assertFalse(testedType.getReference().isPresent());
         assertEquals(Status.CURRENT, testedType.getStatus());
 
         QName testedTypeQName = testedType.getQName();
         assertEquals(URI.create("urn:ietf:params:xml:ns:yang:iana-timezones"), testedTypeQName.getNamespace());
-        assertEquals(TestUtils.createDate("2012-07-09"), testedTypeQName.getRevision());
+        assertEquals(Revision.ofNullable("2012-07-09"), testedTypeQName.getRevision());
         assertEquals("iana-timezone", testedTypeQName.getLocalName());
 
         EnumTypeDefinition enumType = (EnumTypeDefinition) testedType.getBaseType();
@@ -287,18 +294,18 @@ public class TypesResolutionTest {
 
         EnumPair enum168 = values.get(168);
         assertEquals("America/Danmarkshavn", enum168.getName());
-        assertEquals(168, (int) enum168.getValue());
-        assertEquals("east coast, north of Scoresbysund", enum168.getDescription());
+        assertEquals(168, enum168.getValue());
+        assertEquals(Optional.of("east coast, north of Scoresbysund"), enum168.getDescription());
 
         EnumPair enum374 = values.get(374);
         assertEquals("America/Indiana/Winamac", enum374.getName());
-        assertEquals(374, (int) enum374.getValue());
-        assertEquals("Eastern Time - Indiana - Pulaski County", enum374.getDescription());
+        assertEquals(374, enum374.getValue());
+        assertEquals(Optional.of("Eastern Time - Indiana - Pulaski County"), enum374.getDescription());
     }
 
     @Test
     public void testObjectId128() {
-        Module tested = TestUtils.findModule(testedModules, "ietf-yang-types");
+        Module tested = TestUtils.findModule(context, "ietf-yang-types").get();
         Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
         StringTypeDefinition testedType = (StringTypeDefinition) TestUtils.findTypedef(typedefs,
                 "object-identifier-128");
@@ -306,11 +313,11 @@ public class TypesResolutionTest {
         List<PatternConstraint> patterns = testedType.getPatternConstraints();
         assertEquals(1, patterns.size());
         PatternConstraint pattern = patterns.get(0);
-        assertEquals("^\\d*(\\.\\d*){1,127}$", pattern.getRegularExpression());
+        assertEquals("^\\d*(\\.\\d*){1,127}$", pattern.getJavaPatternString());
 
         QName testedTypeQName = testedType.getQName();
         assertEquals(URI.create("urn:ietf:params:xml:ns:yang:ietf-yang-types"), testedTypeQName.getNamespace());
-        assertEquals(TestUtils.createDate("2010-09-24"), testedTypeQName.getRevision());
+        assertEquals(Revision.ofNullable("2010-09-24"), testedTypeQName.getRevision());
         assertEquals("object-identifier-128", testedTypeQName.getLocalName());
 
         StringTypeDefinition testedTypeBase = testedType.getBaseType();
@@ -319,23 +326,23 @@ public class TypesResolutionTest {
 
         pattern = patterns.get(0);
         assertEquals("^(([0-1](\\.[1-3]?[0-9]))|(2\\.(0|([1-9]\\d*))))(\\.(0|([1-9]\\d*)))*$",
-                pattern.getRegularExpression());
+                pattern.getJavaPatternString());
 
         QName testedTypeBaseQName = testedTypeBase.getQName();
         assertEquals(URI.create("urn:ietf:params:xml:ns:yang:ietf-yang-types"), testedTypeBaseQName.getNamespace());
-        assertEquals(TestUtils.createDate("2010-09-24"), testedTypeBaseQName.getRevision());
+        assertEquals(Revision.ofNullable("2010-09-24"), testedTypeBaseQName.getRevision());
         assertEquals("object-identifier", testedTypeBaseQName.getLocalName());
     }
 
     @Test
     public void testIdentityref() {
-        Module tested = TestUtils.findModule(testedModules, "custom-types-test");
+        Module tested = TestUtils.findModule(context, "custom-types-test").get();
         Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
         TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "service-type-ref");
         IdentityrefTypeDefinition baseType = (IdentityrefTypeDefinition) testedType.getBaseType();
         QName identity = baseType.getIdentity().getQName();
         assertEquals(URI.create("urn:custom.types.demo"), identity.getNamespace());
-        assertEquals(TestUtils.createDate("2012-04-16"), identity.getRevision());
+        assertEquals(Revision.ofNullable("2012-04-16"), identity.getRevision());
         assertEquals("service-type", identity.getLocalName());
 
         LeafSchemaNode type = (LeafSchemaNode) tested.getDataChildByName(QName.create(tested.getQNameModule(), "type"));
@@ -345,53 +352,43 @@ public class TypesResolutionTest {
     @Test
     public void testUnionWithExt() throws ReactorException {
 
-        final YangStatementSourceImpl yangFile1 = new YangStatementSourceImpl("/types/union-with-ext/extdef.yang",
-                false);
-        final YangStatementSourceImpl yangFile2 = new YangStatementSourceImpl("/types/union-with-ext/unionbug.yang",
-                false);
-        final YangStatementSourceImpl yangFile3 = new YangStatementSourceImpl("/ietf/ietf-inet-types@2010-09-24.yang",
-                false);
+        final StatementStreamSource yangFile1 = sourceForResource("/types/union-with-ext/extdef.yang");
+        final StatementStreamSource yangFile2 = sourceForResource("/types/union-with-ext/unionbug.yang");
+        final StatementStreamSource yangFile3 = sourceForResource("/ietf/ietf-inet-types@2010-09-24.yang");
 
         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, yangFile1, yangFile2, yangFile3);
+        reactor.addSources(yangFile1, yangFile2, yangFile3);
 
-        final EffectiveSchemaContext result = reactor.buildEffective();
+        final SchemaContext result = reactor.buildEffective();
         assertNotNull(result);
     }
 
     @Test
     public void testUnionWithBits() throws ReactorException {
 
-        final YangStatementSourceImpl yangFile = new YangStatementSourceImpl(
-                "/types/union-with-bits/union-bits-model.yang", false);
+        final StatementStreamSource yangFile = sourceForResource("/types/union-with-bits/union-bits-model.yang");
 
         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, yangFile);
+        reactor.addSources(yangFile);
 
-        final EffectiveSchemaContext result = reactor.buildEffective();
+        final SchemaContext result = reactor.buildEffective();
         assertNotNull(result);
     }
 
     @Test
     public void testUnionInList() {
-        final YangStatementSourceImpl yangFile = new YangStatementSourceImpl(
-                "/types/union-in-list/unioninlisttest.yang", false);
+        final StatementStreamSource yangFile = sourceForResource("/types/union-in-list/unioninlisttest.yang");
 
         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, yangFile);
+        reactor.addSources(yangFile);
 
         try {
-            final EffectiveSchemaContext result = reactor.buildEffective();
+            final SchemaContext result = reactor.buildEffective();
             fail("effective build should fail due to union in list; this is not allowed");
-        } catch (Exception e) {
-            assertEquals(IllegalArgumentException.class, e.getClass());
-            assertTrue(e.getMessage().startsWith("union is not a YANG statement or use of extension"));
-        }
-    }
-
-    private static void addSources(final CrossSourceStatementReactor.BuildAction reactor, final YangStatementSourceImpl... sources) {
-        for (YangStatementSourceImpl source : sources) {
-            reactor.addSource(source);
+        } catch (ReactorException e) {
+            assertEquals(SomeModifiersUnresolvedException.class, e.getClass());
+            assertTrue(e.getCause() instanceof SourceException);
+            assertTrue(e.getCause().getMessage().startsWith("union is not a YANG statement or use of extension"));
         }
     }
 }