import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import java.io.FileNotFoundException;
+import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
+
import java.net.URI;
import java.net.URISyntaxException;
import java.text.ParseException;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
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 MoreRevisionsTest {
- private static final YangStatementSourceImpl REVFILE = new YangStatementSourceImpl(
- "/semantic-statement-parser/revisions/more-revisions-test.yang",
- false);
+ private static final StatementStreamSource REVFILE = sourceForResource(
+ "/semantic-statement-parser/revisions/more-revisions-test.yang");
- private static final YangStatementSourceImpl TED_20130712 = new YangStatementSourceImpl(
- "/semantic-statement-parser/two-revisions/ted@2013-07-12.yang",
- false);
+ private static final StatementStreamSource TED_20130712 = sourceForResource(
+ "/semantic-statement-parser/two-revisions/ted@2013-07-12.yang");
- private static final YangStatementSourceImpl TED_20131021 = new YangStatementSourceImpl(
- "/semantic-statement-parser/two-revisions/ted@2013-10-21.yang",
- false);
+ private static final StatementStreamSource TED_20131021 = sourceForResource(
+ "/semantic-statement-parser/two-revisions/ted@2013-10-21.yang");
- private static final YangStatementSourceImpl IETF_TYPES = new YangStatementSourceImpl(
- "/ietf/ietf-inet-types@2010-09-24.yang", false);
+ private static final StatementStreamSource IETF_TYPES = sourceForResource(
+ "/ietf/ietf-inet-types@2010-09-24.yang");
- private static final YangStatementSourceImpl NETWORK_TOPOLOGY_20130712 = new YangStatementSourceImpl(
- "/ietf/network-topology@2013-07-12.yang", false);
+ private static final StatementStreamSource NETWORK_TOPOLOGY_20130712 = sourceForResource(
+ "/ietf/network-topology@2013-07-12.yang");
- private static final YangStatementSourceImpl NETWORK_TOPOLOGY_20131021 = new YangStatementSourceImpl(
- "/ietf/network-topology@2013-10-21.yang", false);
+ private static final StatementStreamSource NETWORK_TOPOLOGY_20131021 = sourceForResource(
+ "/ietf/network-topology@2013-10-21.yang");
- private static final YangStatementSourceImpl ISIS_20130712 = new YangStatementSourceImpl(
- "/semantic-statement-parser/two-revisions/isis-topology@2013-07-12.yang",
- false);
+ private static final StatementStreamSource ISIS_20130712 = sourceForResource(
+ "/semantic-statement-parser/two-revisions/isis-topology@2013-07-12.yang");
- private static final YangStatementSourceImpl ISIS_20131021 = new YangStatementSourceImpl(
- "/semantic-statement-parser/two-revisions/isis-topology@2013-10-21.yang",
- false);
+ private static final StatementStreamSource ISIS_20131021 = sourceForResource(
+ "/semantic-statement-parser/two-revisions/isis-topology@2013-10-21.yang");
- private static final YangStatementSourceImpl L3_20130712 = new YangStatementSourceImpl(
- "/semantic-statement-parser/two-revisions/l3-unicast-igp-topology@2013-07-12.yang",
- false);
+ private static final StatementStreamSource L3_20130712 = sourceForResource(
+ "/semantic-statement-parser/two-revisions/l3-unicast-igp-topology@2013-07-12.yang");
- private static final YangStatementSourceImpl L3_20131021 = new YangStatementSourceImpl(
- "/semantic-statement-parser/two-revisions/l3-unicast-igp-topology@2013-10-21.yang",
- false);
+ private static final StatementStreamSource L3_20131021 = sourceForResource(
+ "/semantic-statement-parser/two-revisions/l3-unicast-igp-topology@2013-10-21.yang");
@Test
public void readAndParseYangFileTest() throws SourceException,
CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
.newBuild();
reactor.addSource(REVFILE);
- EffectiveSchemaContext result = reactor.buildEffective();
+ SchemaContext result = reactor.buildEffective();
assertNotNull(result);
final Module moduleByName = result.getModules().iterator().next();
final QNameModule qNameModule = moduleByName.getQNameModule();
reactor.addSources(TED_20130712, TED_20131021, IETF_TYPES);
- EffectiveSchemaContext result = reactor.buildEffective();
+ SchemaContext result = reactor.buildEffective();
assertNotNull(result);
}
reactor.addSources(NETWORK_TOPOLOGY_20130712,
NETWORK_TOPOLOGY_20131021, IETF_TYPES);
- EffectiveSchemaContext result = reactor.buildEffective();
+ SchemaContext result = reactor.buildEffective();
assertNotNull(result);
Set<Module> modules = result.getModules();
ISIS_20131021, L3_20130712, L3_20131021, IETF_TYPES,
NETWORK_TOPOLOGY_20130712, NETWORK_TOPOLOGY_20131021);
- EffectiveSchemaContext result = reactor.buildEffective();
+ SchemaContext result = reactor.buildEffective();
assertNotNull(result);
}
@Test
- public void multipleRevisionsTest() throws SourceException,
- ReactorException, FileNotFoundException, URISyntaxException {
+ public void multipleRevisionsTest() throws Exception {
for (int i = 0; i < 100; i++) {
SchemaContext context = StmtTestUtils
.parseYangSources("/semantic-statement-parser/multiple-revisions");
}
@Test
- public void multipleRevisionsFullTest() throws SourceException,
- ReactorException, FileNotFoundException, URISyntaxException,
+ public void multipleRevisionsFullTest() throws Exception,
ParseException {
for (int i = 0; i < 100; i++) {
SchemaContext context = StmtTestUtils
}
}
- private static void checkContentFullTest(final SchemaContext context) throws ParseException,
- URISyntaxException {
+ private static void checkContentFullTest(final SchemaContext context) throws ParseException, URISyntaxException {
String yangTypesNSStr = "urn:ietf:params:xml:ns:yang:ietf-yang-types";
URI yangTypesNS = new URI(yangTypesNSStr);
}
@Test
- public void multipleRevisionsSimpleTest() throws SourceException,
- ReactorException, FileNotFoundException, URISyntaxException,
- ParseException {
+ public void multipleRevisionsSimpleTest() throws Exception {
for (int i = 0; i < 1000; i++) {
- SchemaContext context = StmtTestUtils
- .parseYangSources("/semantic-statement-parser/multiple-revisions/simple");
+ SchemaContext context = StmtTestUtils.parseYangSources(
+ "/semantic-statement-parser/multiple-revisions/simple");
assertNotNull(context);
assertEquals(5, context.getModules().size());
checkContentSimpleTest(context);
}
return false;
}
+
+ @Test
+ public void nodeTest() throws Exception {
+ SchemaContext context = StmtTestUtils.parseYangSources("/semantic-statement-parser/multiple-revisions/node-test");
+ assertNotNull(context);
+
+ QName root = QName.create("foo", "2016-04-06", "foo-root");
+ QName container20160404 = QName.create("foo", "2016-04-06", "con20160404");
+ SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root, container20160404));
+ assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);
+
+ QName container20160405 = QName.create("foo", "2016-04-06", "con20160405");
+ findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root, container20160405));
+ assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);
+
+ QName container20160406 = QName.create("foo", "2016-04-06", "con20160406");
+ findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root, container20160406));
+ assertNull(findDataSchemaNode);
+ }
}