Java Code Examples for org.opendaylight.yangtools.yang.model.api.SchemaContext#getDataChildByName()

The following examples show how to use org.opendaylight.yangtools.yang.model.api.SchemaContext#getDataChildByName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThirdPartyExtensionPluginTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void test() throws URISyntaxException, ReactorException, IOException, YangSyntaxErrorException {
    final CrossSourceStatementReactor.BuildAction reactor = CustomInferencePipeline.CUSTOM_REACTOR.newBuild();
    reactor.addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource("/plugin-test/foo.yang")));

    final SchemaContext schema = reactor.buildEffective();
    final DataSchemaNode dataChildByName = schema.getDataChildByName(QName.create(NS, REV, "root"));
    assertThat(dataChildByName, isA(ContainerSchemaNode.class));

    final ContainerSchemaNode root = (ContainerSchemaNode) dataChildByName;

    final Collection<? extends UnknownSchemaNode> unknownSchemaNodes = root.getUnknownSchemaNodes();
    assertEquals(1, unknownSchemaNodes.size());

    final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.iterator().next();
    assertThat(unknownSchemaNode, isA(ThirdPartyExtensionEffectiveStatement.class));
    final ThirdPartyExtensionEffectiveStatement thirdPartyExtensionStmt =
            (ThirdPartyExtensionEffectiveStatement) unknownSchemaNode;
    assertEquals("Third-party namespace test.", thirdPartyExtensionStmt.getValueFromNamespace());
    assertEquals("plugin test", thirdPartyExtensionStmt.argument());
}
 
Example 2
Source File: ImmutableNodes.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Convert YangInstanceIdentifier into a normalized node structure.
 *
 * @param ctx schema context to used during serialization
 * @param id instance identifier to convert to node structure starting from root
 * @param deepestElement pre-built deepest child that will be inserted at the last path argument of provided
 *                       instance identifier
 * @return serialized normalized node for provided instance Id with (optionally) overridden last child
 *         and (optionally) marked with specific operation attribute.
 */
public static @NonNull NormalizedNode<?, ?> fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id,
        final Optional<NormalizedNode<?, ?>> deepestElement) {
    final PathArgument topLevelElement;
    final InstanceIdToNodes<?> instanceIdToNodes;
    final Iterator<PathArgument> it = id.getPathArguments().iterator();
    if (it.hasNext()) {
        topLevelElement = it.next();
        final DataSchemaNode dataChildByName = ctx.getDataChildByName(topLevelElement.getNodeType());
        checkNotNull(dataChildByName,
            "Cannot find %s node in schema context. Instance identifier has to start from root", topLevelElement);
        instanceIdToNodes = InstanceIdToNodes.fromSchemaAndQNameChecked(ctx, topLevelElement.getNodeType());
    } else {
        topLevelElement = SCHEMACONTEXT_NAME;
        instanceIdToNodes = InstanceIdToNodes.fromDataSchemaNode(ctx);
    }

    return instanceIdToNodes.create(topLevelElement, it, deepestElement);
}
 
Example 3
Source File: AugmentProcessTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void caseShortHandAugmentingTest() throws Exception {
    final SchemaContext context = StmtTestUtils.parseYangSources("/choice-case-type-test-models");

    assertNotNull(context);

    final String rev = "2013-07-01";
    final String ns = "urn:ietf:params:xml:ns:yang:choice-monitoring";
    final String nsAug = "urn:ietf:params:xml:ns:yang:augment-monitoring";

    final ContainerSchemaNode netconf = (ContainerSchemaNode) context.getDataChildByName(QName.create(ns, rev,
            "netconf-state"));
    final ContainerSchemaNode datastores = (ContainerSchemaNode) netconf.getDataChildByName(QName.create(ns, rev,
            "datastores"));
    final ListSchemaNode datastore = (ListSchemaNode) datastores.getDataChildByName(QName.create(ns, rev,
            "datastore"));
    final ContainerSchemaNode locks = (ContainerSchemaNode) datastore.getDataChildByName(QName.create(ns, rev,
            "locks"));
    final ChoiceSchemaNode lockType = (ChoiceSchemaNode) locks.getDataChildByName(QName
            .create(ns, rev, "lock-type"));

    final CaseSchemaNode leafAugCase = lockType.findCaseNodes("leaf-aug-case").iterator().next();
    assertTrue(leafAugCase.isAugmenting());
    final DataSchemaNode leafAug = leafAugCase.getDataChildByName(QName.create(nsAug, rev, "leaf-aug-case"));
    assertFalse(leafAug.isAugmenting());
}
 
Example 4
Source File: Bug7865Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void test() throws Exception {
    final SchemaContext context = TestUtils.parseYangSources("/bugs/bug7865");
    assertNotNull(context);

    final DataSchemaNode root = context.getDataChildByName(foo("root"));
    assertTrue(root instanceof ContainerSchemaNode);
    final Collection<? extends UnknownSchemaNode> unknownSchemaNodes = root.getUnknownSchemaNodes();
    assertEquals(1, unknownSchemaNodes.size());

    final UnknownSchemaNode unknownNode = unknownSchemaNodes.iterator().next();
    final Collection<? extends UnknownSchemaNode> subUnknownSchemaNodes = unknownNode.getUnknownSchemaNodes();
    assertEquals(1, subUnknownSchemaNodes.size());

    final UnknownSchemaNode subUnknownNode = subUnknownSchemaNodes.iterator().next();
    final Collection<? extends UnknownSchemaNode> subSubUnknownSchemaNodes = subUnknownNode.getUnknownSchemaNodes();
    assertEquals(1, subSubUnknownSchemaNodes.size());

    final UnknownSchemaNode subSubUnknownNode = subSubUnknownSchemaNodes.iterator().next();
    final SchemaPath expectedPath = SchemaPath.create(true, foo("root"), foo("p"), foo("p"), foo("p"));
    assertEquals(expectedPath, subSubUnknownNode.getPath());
}
 
Example 5
Source File: Bug2872Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void test() throws Exception {
    final SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug2872");
    assertNotNull(schema);

    final QNameModule bug2872module = QNameModule.create(URI.create("bug2872"), Revision.of("2016-06-08"));
    final QName foo = QName.create(bug2872module, "bar");

    final DataSchemaNode dataSchemaNode = schema.getDataChildByName(foo);
    assertTrue(dataSchemaNode instanceof LeafSchemaNode);
    final LeafSchemaNode myLeaf = (LeafSchemaNode) dataSchemaNode;

    final TypeDefinition<?> type = myLeaf.getType();
    assertTrue(type instanceof EnumTypeDefinition);
    final EnumTypeDefinition myEnum = (EnumTypeDefinition) type;

    final List<EnumTypeDefinition.EnumPair> values = myEnum.getValues();
    assertEquals(2, values.size());

    final List<String> valueNames = new ArrayList<>();
    for (EnumTypeDefinition.EnumPair pair : values) {
        valueNames.add(pair.getName());
    }
    assertTrue(valueNames.contains("value-one"));
    assertTrue(valueNames.contains("value-two"));
}
 
Example 6
Source File: Bug5884Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testBug5884() throws Exception {
    final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5884");
    assertNotNull(context);

    final QName root = QName.create(NS, REV, "main-container");
    final QName choice = QName.create(NS, REV, "test-choice");
    final QName testContainerQname = QName.create(NS, REV, "test");
    final Module foo = context.findModule("foo", Revision.of("2016-01-01")).get();
    final ContainerSchemaNode rootContainer = (ContainerSchemaNode) context.getDataChildByName(root);
    final ContainerSchemaNode testContainer = (ContainerSchemaNode) rootContainer.getDataChildByName(
        testContainerQname);
    final ChoiceSchemaNode dataChildByName = (ChoiceSchemaNode) testContainer.getDataChildByName(choice);

    testIterator(foo.getAugmentations().iterator());
    testIterator(dataChildByName.getAvailableAugmentations().iterator());
}
 
Example 7
Source File: Bug6180Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
private static void verifySingleQuotesExpression(final SchemaContext schemaContext) {
    final DataSchemaNode dataNodeBar = schemaContext.getDataChildByName(QName.create("foo", "2016-07-11", "bar"));
    assertTrue(dataNodeBar instanceof ContainerSchemaNode);
    final ContainerSchemaNode bar = (ContainerSchemaNode) dataNodeBar;
    final RevisionAwareXPath whenCondition = bar.getWhenCondition().get();
    assertEquals("/foo != 'bar'", whenCondition.getOriginalString());

    final Collection<? extends TypeDefinition<?>> typeDefinitions = schemaContext.getTypeDefinitions();
    assertEquals(1, typeDefinitions.size());
    final TypeDefinition<?> type = typeDefinitions.iterator().next();
    assertTrue(type instanceof StringTypeDefinition);
    final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) type).getPatternConstraints();
    assertEquals(1, patternConstraints.size());
    final PatternConstraint pattern = patternConstraints.iterator().next();
    assertEquals("^(?:'.*')$", pattern.getJavaPatternString());
    assertTrue(Pattern.compile(pattern.getJavaPatternString()).matcher("'enclosed string in quotes'").matches());
}
 
Example 8
Source File: Bug6180Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
private static void verifyDoubleQuotesExpression(final SchemaContext schemaContext) {
    final DataSchemaNode dataNodeBar = schemaContext.getDataChildByName(QName.create("foo", "2016-07-11", "bar"));
    assertTrue(dataNodeBar instanceof ContainerSchemaNode);
    final ContainerSchemaNode bar = (ContainerSchemaNode) dataNodeBar;
    final RevisionAwareXPath whenCondition = bar.getWhenCondition().get();
    assertEquals("/foo != \"bar\"", whenCondition.getOriginalString());

    final Collection<? extends TypeDefinition<?>> typeDefinitions = schemaContext.getTypeDefinitions();
    assertEquals(1, typeDefinitions.size());
    final TypeDefinition<?> type = typeDefinitions.iterator().next();
    assertTrue(type instanceof StringTypeDefinition);
    final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) type).getPatternConstraints();
    assertEquals(1, patternConstraints.size());
    final PatternConstraint pattern = patternConstraints.iterator().next();
    assertEquals("^(?:\".*\")$", pattern.getJavaPatternString());
    assertTrue(Pattern.compile(pattern.getJavaPatternString()).matcher("\"enclosed string in quotes\"").matches());
}
 
Example 9
Source File: Bug6316Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static void verifyBitsTypedefinition(final SchemaContext context) {
    final DataSchemaNode dataChildByName = context.getDataChildByName(QName.create("foo", "bits-leaf"));
    assertTrue(dataChildByName instanceof LeafSchemaNode);
    final LeafSchemaNode bitsLeaf = (LeafSchemaNode) dataChildByName;
    final TypeDefinition<? extends TypeDefinition<?>> type = bitsLeaf.getType();
    assertTrue(type instanceof BitsTypeDefinition);
    final BitsTypeDefinition myBits = (BitsTypeDefinition) type;
    for (final Bit bit : myBits.getBits()) {
        final String name = bit.getName();
        switch (name) {
            case "zero":
                assertEquals(Uint32.ZERO, bit.getPosition());
                break;
            case "twenty":
                assertEquals(Uint32.valueOf(20), bit.getPosition());
                break;
            case "twenty-one":
                assertEquals(Uint32.valueOf(21), bit.getPosition());
                break;
            case "two":
                assertEquals(Uint32.TWO, bit.getPosition());
                break;
            case "twenty-two":
                assertEquals(Uint32.valueOf(22), bit.getPosition());
                break;
            default:
                fail("Unexpected bit name.");
        }
    }
}
 
Example 10
Source File: Bug5518Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5518");
    assertNotNull(context);

    final DataSchemaNode dataChildByName = context.getDataChildByName(QName.create("foo", "root"));
    assertTrue(dataChildByName instanceof ContainerSchemaNode);
    final ContainerSchemaNode root = (ContainerSchemaNode) dataChildByName;
    final Collection<? extends MustDefinition> mustConstraints = root.getMustConstraints();
    assertEquals(1, mustConstraints.size());
    final MustDefinition must = mustConstraints.iterator().next();
    assertEquals("not(deref(.)/../same-pass)", must.getXpath().getOriginalString());
}
 
Example 11
Source File: Bug5942Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug5942");
    assertNotNull(schemaContext);

    final DataSchemaNode root = schemaContext.getDataChildByName(QName.create("foo", "2016-06-02", "root"));
    assertTrue(root instanceof ContainerSchemaNode);

    final Collection<? extends UsesNode> uses = ((ContainerSchemaNode) root).getUses();
    assertEquals(1, uses.size());
    final UsesNode usesNode = uses.iterator().next();

    assertEquals(Optional.of("uses description"), usesNode.getDescription());
    assertEquals(Optional.of("uses reference"), usesNode.getReference());
    assertEquals(Status.DEPRECATED, usesNode.getStatus());

    final RevisionAwareXPath when = usesNode.getWhenCondition().get();
    assertFalse(when.isAbsolute());
    assertThat(when, instanceOf(WithExpression.class));
    assertEquals("0!=1", when.getOriginalString());

    final Collection<? extends UnknownSchemaNode> unknownSchemaNodes = usesNode.getUnknownSchemaNodes();
    assertEquals(1, unknownSchemaNodes.size());
    final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.iterator().next();
    assertEquals("argument", unknownSchemaNode.getNodeParameter());
    assertEquals(QName.create("foo", "2016-06-02", "e"), unknownSchemaNode.getExtensionDefinition().getQName());
}
 
Example 12
Source File: Bug6316Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static void verifyEnumTypedefinition(final SchemaContext context) {
    final DataSchemaNode dataChildByName = context.getDataChildByName(QName.create("foo", "enum-leaf"));
    assertTrue(dataChildByName instanceof LeafSchemaNode);
    final LeafSchemaNode enumLeaf = (LeafSchemaNode) dataChildByName;
    final TypeDefinition<? extends TypeDefinition<?>> type = enumLeaf.getType();
    assertTrue(type instanceof EnumTypeDefinition);
    final EnumTypeDefinition myEnumeration = (EnumTypeDefinition) type;
    final List<EnumPair> values = myEnumeration.getValues();
    for (final EnumPair enumPair : values) {
        final String name = enumPair.getName();
        switch (name) {
            case "zero":
                assertEquals(0, enumPair.getValue());
                break;
            case "twenty":
                assertEquals(20, enumPair.getValue());
                break;
            case "twenty-one":
                assertEquals(21, enumPair.getValue());
                break;
            case "two":
                assertEquals(2, enumPair.getValue());
                break;
            case "twenty-two":
                assertEquals(22, enumPair.getValue());
                break;
            default:
                fail("Unexpected enum name.");
        }
    }
}
 
Example 13
Source File: Bug5410Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static PatternConstraint getPatternConstraintOf(final SchemaContext context, final String leafName) {
    final DataSchemaNode dataChildByName = context.getDataChildByName(foo(leafName));
    assertTrue(dataChildByName instanceof LeafSchemaNode);
    final LeafSchemaNode leaf = (LeafSchemaNode) dataChildByName;
    final TypeDefinition<? extends TypeDefinition<?>> type = leaf.getType();
    assertTrue(type instanceof StringTypeDefinition);
    final StringTypeDefinition strType = (StringTypeDefinition) type;
    return strType.getPatternConstraints().iterator().next();
}
 
Example 14
Source File: Bug6897Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static void assertContainsNotifications(final SchemaContext schemaContext, final String dataContainerName,
        final String... notificationNames) {
    final DataSchemaNode dataChildByName = schemaContext.getDataChildByName(
        QName.create(FOO_NS, dataContainerName));
    assertTrue(dataChildByName instanceof NotificationNodeContainer);
    assertContainsNotifications((NotificationNodeContainer) dataChildByName, notificationNames);
}
 
Example 15
Source File: ActionStatementTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static void assertContainsActions(final SchemaContext schemaContext, final String dataContainerName,
        final String... actionNames) {
    final DataSchemaNode dataChildByName = schemaContext.getDataChildByName(QName.create(FOO_NS, FOO_REV,
            dataContainerName));
    assertTrue(dataChildByName instanceof ActionNodeContainer);
    assertContainsActions((ActionNodeContainer) dataChildByName, actionNames);
}
 
Example 16
Source File: EffectiveModulesAndSubmodulesTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
private static void getDataChildByNameSubTest(final SchemaContext result, final Module root) {
    final DataSchemaNode containerInRoot = result.getDataChildByName(QName
            .create(root.getQNameModule(), "container-in-root-module"));
    assertNotNull(containerInRoot);
    assertEquals(Optional.of("desc"), containerInRoot.getDescription());
}
 
Example 17
Source File: Bug5946Test.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
private static @NonNull Collection<? extends UniqueConstraint> getListConstraints(final SchemaContext context,
        final QName listQName) {
    DataSchemaNode dataChildByName = context.getDataChildByName(listQName);
    assertTrue(dataChildByName instanceof ListSchemaNode);
    return ((ListSchemaNode) dataChildByName).getUniqueConstraints();
}
 
Example 18
Source File: Bug6183Test.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
public void assertSchemaContext(final SchemaContext context) throws Exception {
    assertNotNull(context);
    assertEquals(3, context.getChildNodes().size());
    assertEquals(1, context.getModules().size());
    assertEquals(4, context.getModules().iterator().next().getAugmentations().size());

    assertTrue(context.getDataChildByName(foo("before")) instanceof ContainerSchemaNode);
    assertTrue(context.getDataChildByName(foo("after")) instanceof ContainerSchemaNode);

    final DataSchemaNode dataChildByName = context.getDataChildByName(foo("my-choice"));
    assertTrue(dataChildByName instanceof ChoiceSchemaNode);
    final ChoiceSchemaNode myChoice = (ChoiceSchemaNode) dataChildByName;

    assertEquals(4, myChoice.getCases().size());

    final CaseSchemaNode implCase = myChoice.findCase(foo("implicit-case-container")).get();
    final CaseSchemaNode declCaseOne = myChoice.findCase(foo("declared-case-one")).get();
    final CaseSchemaNode secondImplCase = myChoice.findCase(foo("second-implicit-case-container")).get();
    final CaseSchemaNode declCaseTwo = myChoice.findCase(foo("declared-case-two")).get();

    assertEquals(1, declCaseOne.getChildNodes().size());
    assertFalse(getLeafSchemaNode(declCaseOne, "leaf-in-declare-case-one").isAugmenting());
    assertEquals(1, declCaseTwo.getChildNodes().size());
    assertFalse(getLeafSchemaNode(declCaseTwo, "leaf-in-declare-case-two").isAugmenting());

    assertEquals(2, implCase.getChildNodes().size());
    assertTrue(getLeafSchemaNode(implCase, "leaf-after-container").isAugmenting());
    final ContainerSchemaNode implCaseContainer = getContainerSchemaNode(implCase, "implicit-case-container");

    assertEquals(3, implCaseContainer.getChildNodes().size());
    assertTrue(getLeafSchemaNode(implCaseContainer, "leaf-inside-container").isAugmenting());
    assertFalse(getLeafSchemaNode(implCaseContainer, "declared-leaf-in-case-container").isAugmenting());
    final ContainerSchemaNode declContInCaseCont = getContainerSchemaNode(implCaseContainer,
            "declared-container-in-case-container");

    assertEquals(1, declContInCaseCont.getChildNodes().size());
    assertFalse(getLeafSchemaNode(declContInCaseCont, "declared-leaf").isAugmenting());

    assertEquals(2, secondImplCase.getChildNodes().size());
    assertTrue(getLeafSchemaNode(secondImplCase, "leaf-after-second-container").isAugmenting());
    final ContainerSchemaNode secondImplCaseContainer = getContainerSchemaNode(secondImplCase,
            "second-implicit-case-container");

    assertEquals(2, secondImplCaseContainer.getChildNodes().size());
    assertTrue(getLeafSchemaNode(secondImplCaseContainer, "leaf-inside-second-container").isAugmenting());
    assertFalse(getLeafSchemaNode(secondImplCaseContainer, "declared-leaf-in-second-case-container")
        .isAugmenting());
}
 
Example 19
Source File: YangTypes2StmtTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void readAndParseYangFileTest() throws ReactorException {
    SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
            .addSources(TYPEFILE1, TYPEFILE2, TYPEFILE3, TYPEFILE4)
            .buildEffective();
    assertNotNull(result);

    final LeafSchemaNode lfDecimalNode = (LeafSchemaNode) result.getDataChildByName(LF_DECIMAL);
    assertNotNull(lfDecimalNode);

    assertTrue(lfDecimalNode.getType() instanceof DecimalTypeDefinition);
    final DecimalTypeDefinition lfDecimalNodeType = (DecimalTypeDefinition) lfDecimalNode.getType();
    assertEquals(2, lfDecimalNodeType.getFractionDigits());

    final LeafSchemaNode lfInt8Node = (LeafSchemaNode) result.getDataChildByName(LF_INT8);
    assertNotNull(lfInt8Node);
    assertEquals(BaseTypes.int8Type().getClass(), lfInt8Node.getType().getClass());

    final LeafSchemaNode lfInt16Node = (LeafSchemaNode) result.getDataChildByName(LF_INT16);
    assertNotNull(lfInt16Node);
    assertEquals(BaseTypes.int16Type().getClass(), lfInt16Node.getType().getClass());

    final LeafSchemaNode lfInt32Node = (LeafSchemaNode) result.getDataChildByName(LF_INT32);
    assertNotNull(lfInt32Node);
    assertEquals(BaseTypes.int32Type().getClass(), lfInt32Node.getType().getClass());

    final LeafSchemaNode lfInt64Node = (LeafSchemaNode) result.getDataChildByName(LF_INT64);
    assertNotNull(lfInt64Node);
    assertEquals(BaseTypes.int64Type().getClass(), lfInt64Node.getType().getClass());

    final LeafSchemaNode lfUInt8Node = (LeafSchemaNode) result.getDataChildByName(LF_UINT8);
    assertNotNull(lfUInt8Node);
    assertEquals(BaseTypes.uint8Type().getClass(), lfUInt8Node.getType().getClass());

    final LeafSchemaNode lfUInt16Node = (LeafSchemaNode) result.getDataChildByName(LF_UINT16);
    assertNotNull(lfUInt16Node);
    assertEquals(BaseTypes.uint16Type().getClass(), lfUInt16Node.getType().getClass());

    final LeafSchemaNode lfUInt32Node = (LeafSchemaNode) result.getDataChildByName(LF_UINT32);
    assertNotNull(lfUInt32Node);
    assertEquals(BaseTypes.uint32Type().getClass(), lfUInt32Node.getType().getClass());

    final LeafSchemaNode lfUInt64Node = (LeafSchemaNode) result.getDataChildByName(LF_UINT64);
    assertNotNull(lfUInt64Node);
    assertEquals(BaseTypes.uint64Type().getClass(), lfUInt64Node.getType().getClass());

    final LeafSchemaNode lfBoolNode = (LeafSchemaNode) result.getDataChildByName(LF_BOOL);
    assertNotNull(lfBoolNode);
    assertEquals(BaseTypes.booleanType().getClass(), lfBoolNode.getType().getClass());
}
 
Example 20
Source File: AugmentProcessTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void readAndParseYangFileTest() throws ReactorException {
    final SchemaContext root = RFC7950Reactors.defaultReactor().newBuild()
            .addSources(AUGMENTED, ROOT)
            .buildEffective();
    assertNotNull(root);

    final Module augmentedModule = root.findModules("augmented").iterator().next();
    assertNotNull(augmentedModule);

    final ContainerSchemaNode augParent1Node = (ContainerSchemaNode) root.getDataChildByName(augParent1);
    final ContainerSchemaNode augParent2Node = (ContainerSchemaNode) augParent1Node.getDataChildByName(augParent2);
    final ContainerSchemaNode targetContNode = (ContainerSchemaNode) augParent2Node.getDataChildByName(contTarget);
    assertNotNull(targetContNode);

    assertNotNull(targetContNode.getChildNodes());
    assertEquals(3, targetContNode.getChildNodes().size());

    final ContainerSchemaNode contAdded1Node = (ContainerSchemaNode) targetContNode.getDataChildByName(contAdded1);
    assertNotNull(contAdded1Node);
    final ListSchemaNode list1Node = (ListSchemaNode) contAdded1Node.getDataChildByName(list1);
    assertNotNull(list1Node);

    final ContainerSchemaNode contAdded2Node = (ContainerSchemaNode) targetContNode.getDataChildByName(contAdded2);
    assertNotNull(contAdded2Node);
    final AnyxmlSchemaNode axmlNode = (AnyxmlSchemaNode) contAdded2Node.getDataChildByName(axml);
    assertNotNull(axmlNode);

    final ContainerSchemaNode contGrpNode = (ContainerSchemaNode) targetContNode.getDataChildByName(contGrp);
    assertNotNull(contGrpNode);
    final AnyxmlSchemaNode axmlGrpNode = (AnyxmlSchemaNode) contGrpNode.getDataChildByName(axmlGrp);
    assertNotNull(axmlGrpNode);

    final ContainerSchemaNode augCont1Node = (ContainerSchemaNode) root.getDataChildByName(augCont1);
    final ContainerSchemaNode augCont2Node = (ContainerSchemaNode) augCont1Node.getDataChildByName(augCont2);
    assertNotNull(augCont2Node);

    final ContainerSchemaNode grpCont2Node = (ContainerSchemaNode) augCont2Node.getDataChildByName(grpCont2);
    final ContainerSchemaNode grpCont22Node = (ContainerSchemaNode) grpCont2Node.getDataChildByName(grpCont22);
    assertNotNull(grpCont22Node);

    final ContainerSchemaNode grpAddNode = (ContainerSchemaNode) grpCont22Node.getDataChildByName(grpAdd);
    assertNotNull(grpAddNode);
}