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 java.net.URI;
import java.util.List;
import java.util.Set;
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 {
@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);
+ final StatementStreamSource yangFile = sourceForResource("/types/custom-types-test@2012-4-4.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");
testedModules = TestUtils.parseYangSources(yangFile, yangFileDependency1, yangFileDependency2,
yangFileDependency3).getModules();
EnumPair value0 = values.get(0);
assertEquals("unknown", value0.getName());
- assertEquals(0, (int) value0.getValue());
+ assertEquals(0, value0.getValue());
assertEquals("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(1, value1.getValue());
assertEquals("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(2, value2.getValue());
assertEquals("The IPv6 protocol as defined in RFC 2460.", value2.getDescription());
}
EnumPair value0 = values.get(0);
assertEquals("unknown", value0.getName());
- assertEquals(0, (int) value0.getValue());
+ assertEquals(0, value0.getValue());
assertEquals("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(19, value1.getValue());
assertEquals("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(7, value2.getValue());
assertEquals("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(20, value3.getValue());
assertEquals("default ip", value3.getDescription());
}
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
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
EnumPair enum168 = values.get(168);
assertEquals("America/Danmarkshavn", enum168.getName());
- assertEquals(168, (int) enum168.getValue());
+ assertEquals(168, enum168.getValue());
assertEquals("east coast, north of Scoresbysund", enum168.getDescription());
EnumPair enum374 = values.get(374);
assertEquals("America/Indiana/Winamac", enum374.getName());
- assertEquals(374, (int) enum374.getValue());
+ assertEquals(374, enum374.getValue());
assertEquals("Eastern Time - Indiana - Pulaski County", enum374.getDescription());
}
@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();
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();
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();
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);
+ 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"));
}
}
}