import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
-import java.text.ParseException;
import java.util.Collections;
import java.util.Optional;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
public void testFindDummyData() {
MockitoAnnotations.initMocks(this);
doReturn(Optional.empty()).when(mockSchemaContext).findModule(any(QNameModule.class));
+ doReturn(URI.create("dummy")).when(mockModule).getNamespace();
+ doReturn(Optional.empty()).when(mockModule).getRevision();
- final QName qName = QName.create("TestQName");
+ final QName qName = QName.create("dummy", "TestQName");
final SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qName), true);
assertEquals("Should be null. Module TestQName not found", null,
SchemaContextUtil.findDataSchemaNode(mockSchemaContext, schemaPath));
@Test
public void findNodeInSchemaContextTest() throws URISyntaxException, IOException, YangSyntaxErrorException,
- ParseException, ReactorException {
+ ReactorException {
final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
- final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
+ final Module myModule = context.findModule(new URI("uri:my-module"),Revision.of("2014-10-07")).get();
SchemaNode testNode = ((ContainerSchemaNode) myModule.getDataChildByName(QName.create(
myModule.getQNameModule(), "my-container"))).getDataChildByName(QName.create(myModule.getQNameModule(),
assertEquals(testNode, foundNode);
testNode = ((ChoiceSchemaNode) myModule
- .getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice"))).getCaseNodeByName("one")
+ .getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice")))
+ .findCaseNodes("one").iterator().next()
.getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice-leaf-one"));
path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
@Test
public void findNodeInSchemaContextTest2() throws URISyntaxException, IOException, YangSyntaxErrorException,
- ParseException, ReactorException {
+ ReactorException {
final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
- final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
+ final Module myModule = context.findModule(new URI("uri:my-module"), Revision.of("2014-10-07")).get();
SchemaNode testNode = ((ContainerSchemaNode) myModule.getDataChildByName(QName.create(
myModule.getQNameModule(), "my-container"))).getDataChildByName(QName.create(myModule.getQNameModule(),
assertNull(foundNode);
testNode = ((ChoiceSchemaNode) myModule
- .getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice"))).getCaseNodeByName("one")
+ .getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice")))
+ .findCaseNodes("one").iterator().next()
.getDataChildByName(QName.create(myModule.getQNameModule(), "no-choice-leaf"));
path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
@Test
public void findNodeInSchemaContextTest3() throws URISyntaxException, IOException, YangSyntaxErrorException,
- ParseException, ReactorException {
+ ReactorException {
final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
- final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
+ final Module myModule = context.findModule(new URI("uri:my-module"), Revision.of("2014-10-07")).get();
SchemaNode testNode = myModule.getDataChildByName(QName.create(myModule.getQNameModule(), "my-container"));
@Test
public void findParentModuleTest() throws URISyntaxException, IOException, YangSyntaxErrorException,
- ParseException, ReactorException {
+ ReactorException {
final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
- final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
+ final Module myModule = context.findModule(new URI("uri:my-module"), Revision.of("2014-10-07")).get();
- final DataSchemaNode node = myModule
- .getDataChildByName(QName.create(myModule.getQNameModule(), "my-container"));
+ final DataSchemaNode node = myModule.getDataChildByName(QName.create(myModule.getQNameModule(),
+ "my-container"));
final Module foundModule = SchemaContextUtil.findParentModule(context, node);
public void findDataSchemaNodeTest() throws URISyntaxException, IOException, YangSyntaxErrorException,
ReactorException {
final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
- final Module module = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
+ final Module module = context.findModule(new URI("uri:my-module"), Revision.of("2014-10-07")).get();
final Module importedModule = context.findModule(new URI("uri:imported-module"),
- QName.parseRevision("2014-10-07")).get();
+ Revision.of("2014-10-07")).get();
final SchemaNode testNode = ((ContainerSchemaNode) importedModule.getDataChildByName(QName.create(
importedModule.getQNameModule(), "my-imported-container"))).getDataChildByName(QName.create(
// final RevisionAwareXPath nonCondXPath) {
final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
- final Module module = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
+ final Module module = context.findModule(new URI("uri:my-module"), Revision.of("2014-10-07")).get();
final GroupingDefinition grouping = getGroupingByName(module, "my-grouping");
final SchemaNode testNode = grouping.getDataChildByName(QName.create(module.getQNameModule(),
@Test
public void findNodeInSchemaContextGroupingsTest() throws URISyntaxException, IOException,
- YangSyntaxErrorException, ParseException, ReactorException {
+ YangSyntaxErrorException, ReactorException {
final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
- final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
+ final Module myModule = context.findModule(URI.create("uri:my-module"), Revision.of("2014-10-07")).get();
// find grouping in container
DataNodeContainer dataContainer = (DataNodeContainer) myModule.getDataChildByName(QName.create(
assertEquals(testNode, foundNode);
// find grouping in case
- dataContainer = (DataNodeContainer) ((ChoiceSchemaNode) myModule.getDataChildByName(QName.create(
- myModule.getQNameModule(), "my-choice"))).getCaseNodeByName("one").getDataChildByName(
- QName.create(myModule.getQNameModule(), "my-container-in-case"));
+ dataContainer = (DataNodeContainer) ((ChoiceSchemaNode) myModule.getDataChildByName(
+ QName.create(myModule.getQNameModule(), "my-choice")))
+ .findCaseNodes("one").iterator().next()
+ .getDataChildByName(QName.create(myModule.getQNameModule(), "my-container-in-case"));
testNode = getGroupingByName(dataContainer, "my-grouping-in-case");
path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
@Test
public void findNodeInSchemaContextGroupingsTest2() throws URISyntaxException, IOException,
- YangSyntaxErrorException, ParseException, ReactorException {
+ YangSyntaxErrorException, ReactorException {
final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
- final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
+ final Module myModule = context.findModule(new URI("uri:my-module"), Revision.of("2014-10-07")).get();
// find grouping in container
DataNodeContainer dataContainer = (DataNodeContainer) myModule.getDataChildByName(QName.create(
assertNull(foundNode);
// find grouping in case
- dataContainer = (DataNodeContainer) ((ChoiceSchemaNode) myModule.getDataChildByName(QName.create(
- myModule.getQNameModule(), "my-choice"))).getCaseNodeByName("one").getDataChildByName(
- QName.create(myModule.getQNameModule(), "my-container-in-case"));
+ dataContainer = (DataNodeContainer) ((ChoiceSchemaNode) myModule.getDataChildByName(
+ QName.create(myModule.getQNameModule(), "my-choice")))
+ .findCaseNodes("one").iterator().next()
+ .getDataChildByName(QName.create(myModule.getQNameModule(), "my-container-in-case"));
testNode = getGroupingByName(dataContainer, "my-grouping-in-case2");
path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
@Test
public void findNodeInSchemaContextTheSameNameOfSiblingsTest() throws URISyntaxException, IOException,
- YangSyntaxErrorException, ParseException, ReactorException {
+ YangSyntaxErrorException, ReactorException {
final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
- final Module myModule = context.findModule(new URI("uri:my-module"), QName.parseRevision("2014-10-07")).get();
+ final Module myModule = context.findModule(new URI("uri:my-module"), Revision.of("2014-10-07")).get();
final ChoiceSchemaNode choice = (ChoiceSchemaNode) getRpcByName(myModule, "my-name").getInput()
.getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice"));
- final SchemaNode testNode = choice.getCaseNodeByName("case-two").getDataChildByName(
- QName.create(myModule.getQNameModule(), "two"));
+ final SchemaNode testNode = choice.findCaseNodes("case-two").iterator().next()
+ .getDataChildByName(QName.create(myModule.getQNameModule(), "two"));
final SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-name"),
QName.create(myModule.getQNameModule(), "input"), QName.create(myModule.getQNameModule(), "my-choice"),