org.opendaylight.yangtools.yang.model.api.SchemaContext Java Examples

The following examples show how to use org.opendaylight.yangtools.yang.model.api.SchemaContext. 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: Bug6972Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void allUnitsShouldBeTheSameInstance() throws Exception {
    final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug6972");
    assertNotNull(schemaContext);
    assertEquals(3, schemaContext.getModules().size());

    final Revision revision = Revision.of("2016-10-20");
    final Module foo = schemaContext.findModule("foo", revision).get();
    final Module bar = schemaContext.findModule("bar", revision).get();
    final Module baz = schemaContext.findModule("baz", revision).get();

    final QName barExportCont = QName.create("bar-ns", "bar-export", revision);
    final QName barFooCont = QName.create("bar-ns", "bar-foo", revision);
    final QName barFooLeaf = QName.create("bar-ns", "foo", revision);

    final UnitsEffectiveStatement unitsBar1 = getEffectiveUnits(bar, barExportCont, barFooLeaf);
    assertSame(unitsBar1, getEffectiveUnits(bar, barFooCont, barFooLeaf));

    final QName bazExportCont = QName.create("baz-ns", "baz-export", revision);
    final QName bazFooCont = QName.create("baz-ns", "baz-foo", revision);
    final QName bazFooLeaf = QName.create("baz-ns", "foo", revision);

    assertSame(unitsBar1, getEffectiveUnits(baz, bazExportCont, bazFooLeaf));
    assertSame(unitsBar1, getEffectiveUnits(baz, bazFooCont, bazFooLeaf));
}
 
Example #2
Source File: SchemaUtils.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Finds schema node for given path in schema context. This method performs lookup in both the namespace
 * of groupings and the namespace of all leafs, leaf-lists, lists, containers, choices, rpcs, actions,
 * notifications, anydatas and anyxmls according to Rfc6050/Rfc7950 section 6.2.1.
 *
 * <p>
 * This method returns collection of SchemaNodes, because name conflicts can occur between the namespace
 * of groupings and namespace of data nodes. This method finds and collects all schema nodes that matches supplied
 * SchemaPath and returns them all as collection of schema nodes.
 *
 * @param schemaContext
 *            schema context
 * @param path
 *            path
 * @return collection of schema nodes on path
 */
public static Collection<SchemaNode> findParentSchemaNodesOnPath(final SchemaContext schemaContext,
        final SchemaPath path) {
    final Collection<SchemaNode> currentNodes = new ArrayList<>();
    final Collection<SchemaNode> childNodes = new ArrayList<>();
    currentNodes.add(requireNonNull(schemaContext));
    for (final QName qname : path.getPathFromRoot()) {
        for (final SchemaNode current : currentNodes) {
            childNodes.addAll(findChildSchemaNodesByQName(current, qname));
        }
        currentNodes.clear();
        currentNodes.addAll(childNodes);
        childNodes.clear();
    }

    return currentNodes;
}
 
Example #3
Source File: TypedefSubStmtsTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void typedefSubStmtsTest() throws ReactorException {
    SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
            .addSource(sourceForResource("/typedef-substmts-test/typedef-substmts-test.yang"))
            .buildEffective();
    assertNotNull(result);

    Collection<? extends TypeDefinition<?>> typedefs = result.getTypeDefinitions();
    assertEquals(1, typedefs.size());

    TypeDefinition<?> typedef = typedefs.iterator().next();
    assertEquals("time-of-the-day", typedef.getQName().getLocalName());
    assertEquals("string", typedef.getBaseType().getQName().getLocalName());
    assertEquals(Optional.of("24-hour-clock"), typedef.getUnits());
    assertEquals("1am", typedef.getDefaultValue().map(Object::toString).orElse(null));
}
 
Example #4
Source File: ExtensionStmtTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testExtensionDefinition() throws ReactorException {
    final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
            .addSource(sourceForResource("/model/bar.yang"))
            .buildEffective();
    assertNotNull(result);

    final Module testModule = result.findModules("bar").iterator().next();
    assertNotNull(testModule);

    assertEquals(1, testModule.getExtensionSchemaNodes().size());

    final Collection<? extends ExtensionDefinition> extensions = testModule.getExtensionSchemaNodes();
    final ExtensionDefinition extension = extensions.iterator().next();
    assertEquals("opendaylight", extension.getQName().getLocalName());
    assertEquals("name", extension.getArgument());
    assertTrue(extension.isYinElement());
}
 
Example #5
Source File: SchemaContextProxyTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testChainAdditionalModulesConfig() {
    Module moduleConfig = mockModule(CONFIG_NAME);
    Module module2 = mockModule(MODULE2_NAME);

    Module module3 = mockModule(MODULE3_NAME);
    Module module4 = mockModule(MODULE4_NAME);
    Module module5 = mockModule(MODULE5_NAME);

    mockModuleImport(module2, moduleConfig);
    mockModuleImport(module3, module4);

    SchemaContext schemaContext = mockSchema(moduleConfig, module2, module3, module4, module5);

    FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext,
        Collections.singleton(module3), moduleConfig);
    assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2, module3, module4);
}
 
Example #6
Source File: Bug6961Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testBug6961SchemaContext() throws Exception {
    final Optional<Revision> revision = Revision.ofNullable("2016-01-01");
    final SourceIdentifier foo = RevisionSourceIdentifier.create("foo", revision);
    final SourceIdentifier sub1Foo = RevisionSourceIdentifier.create("sub1-foo", revision);
    final SourceIdentifier sub2Foo = RevisionSourceIdentifier.create("sub2-foo", revision);
    final SourceIdentifier bar = RevisionSourceIdentifier.create("bar", revision);
    final SourceIdentifier sub1Bar = RevisionSourceIdentifier.create("sub1-bar", revision);
    final SourceIdentifier baz = RevisionSourceIdentifier.create("baz", revision);
    final Set<SourceIdentifier> testSet = ImmutableSet.of(foo, sub1Foo, sub2Foo, bar, sub1Bar, baz);
    final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6961/");
    assertNotNull(context);
    final Set<SourceIdentifier> allModuleIdentifiers = SchemaContextUtil.getConstituentModuleIdentifiers(context);
    assertNotNull(allModuleIdentifiers);
    assertEquals(6, allModuleIdentifiers.size());
    final SchemaContext schemaContext = SimpleSchemaContext.forModules(context.getModules());
    assertNotNull(schemaContext);
    final Set<SourceIdentifier> allModuleIdentifiersResolved = SchemaContextUtil.getConstituentModuleIdentifiers(
        schemaContext);
    assertNotNull(allModuleIdentifiersResolved);
    assertEquals(6, allModuleIdentifiersResolved.size());
    assertEquals(allModuleIdentifiersResolved, allModuleIdentifiers);
    assertEquals(allModuleIdentifiers, testSet);
    assertTrue(allModuleIdentifiers.contains(foo));
}
 
Example #7
Source File: Bug8713Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void dataTreeCanditateValidationTest() throws Exception {
    final SchemaContext context = YangParserTestUtils.parseYangResourceDirectory("/bug8713/");
    final LeafRefContext rootLeafRefContext = LeafRefContext.create(context);
    final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
        DataTreeConfiguration.DEFAULT_OPERATIONAL, context);

    final ContainerNode root = createRootContainer();
    final YangInstanceIdentifier rootPath = YangInstanceIdentifier.of(foo("root"));
    final DataTreeModification writeModification = inMemoryDataTree.takeSnapshot().newModification();
    writeModification.write(rootPath, root);
    writeModification.ready();

    final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree.prepare(writeModification);

    LeafRefValidation.validate(writeContributorsCandidate, rootLeafRefContext);
    inMemoryDataTree.commit(writeContributorsCandidate);
}
 
Example #8
Source File: DataTreeCandidatesTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);

    final ContainerNode testContainer = ImmutableContainerNodeBuilder.create()
            .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
            .withChild(ImmutableContainerNodeBuilder.create()
                    .withNodeIdentifier(new NodeIdentifier(SchemaContext.NAME))
                    .build())
            .build();

    final InMemoryDataTreeModification modification = (InMemoryDataTreeModification) dataTree.takeSnapshot()
            .newModification();
    final DataTreeModificationCursor cursor = modification.openCursor();
    cursor.write(TestModel.TEST_PATH.getLastPathArgument(), testContainer);
    modification.ready();

    dataTree.validate(modification);
    final DataTreeCandidate candidate = dataTree.prepare(modification);
    dataTree.commit(candidate);
}
 
Example #9
Source File: Bug5830Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
private static void testMandatoryDataLeafIsPresent(final SchemaContext schemaContext)
        throws DataValidationFailedException {
    final DataTree inMemoryDataTree = initDataTree(schemaContext);

    final MapEntryNode taskEntryNode = Builders.mapEntryBuilder()
            .withNodeIdentifier(NodeIdentifierWithPredicates.of(TASK, ImmutableMap.of(TASK_ID, "123")))
            .withChild(ImmutableNodes.leafNode(TASK_ID, "123"))
            .withChild(ImmutableNodes.leafNode(TASK_MANDATORY_LEAF, "mandatory data"))
            .withChild(createTaskDataContainer(true)).build();

    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    modificationTree.write(
            YangInstanceIdentifier.of(TASK_CONTAINER).node(TASK)
                    .node(NodeIdentifierWithPredicates.of(TASK, ImmutableMap.of(TASK_ID, "123"))), taskEntryNode);
    modificationTree.ready();

    inMemoryDataTree.validate(modificationTree);
    final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
    inMemoryDataTree.commit(prepare);
}
 
Example #10
Source File: SchemaContextProxyTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testBasicMoreRootModules() {
    final Module moduleConfig = mockModule(CONFIG_NAME);
    final Module moduleRoot = mockModule(ROOT_NAME);
    final Module module2 = mockModule(MODULE2_NAME);
    final Module module3 = mockModule(MODULE3_NAME);

    mockModuleImport(module2, moduleConfig);
    mockModuleImport(module3, moduleRoot);

    SchemaContext schemaContext = mockSchema(moduleConfig, moduleRoot, module2, module3);

    FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleRoot,
            moduleConfig);
    assertProxyContext(filteringSchemaContextProxy, moduleRoot, module3, moduleConfig, module2);
}
 
Example #11
Source File: Bug394Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testParseList() throws Exception {
    final SchemaContext context = TestUtils.loadModules(getClass().getResource("/bugs/bug394-retest").toURI());
    final Module bug394 = TestUtils.findModule(context, "bug394").get();
    final Module bug394_ext = TestUtils.findModule(context, "bug394-ext").get();

    final ContainerSchemaNode logrecords = (ContainerSchemaNode) bug394.getDataChildByName(QName.create(
            bug394.getQNameModule(), "logrecords"));
    assertNotNull(logrecords);

    final Collection<? extends UnknownSchemaNode> nodes = logrecords.getUnknownSchemaNodes();
    assertEquals(2, nodes.size());

    final Collection<? extends ExtensionDefinition> extensions = bug394_ext.getExtensionSchemaNodes();
    assertEquals(3, extensions.size());

    final Iterator<? extends UnknownSchemaNode> it = nodes.iterator();
    assertTrue(extensions.contains(it.next().getExtensionDefinition()));
    assertTrue(extensions.contains(it.next().getExtensionDefinition()));
}
 
Example #12
Source File: IoCSwaggerGenerator.java    From yang2swagger with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Preconfigure generator. By default it will genrate api for Data and RCP with JSon payloads only.
 * The api will be in YAML format. You might change default setting with config methods of the class
 * @param ctx context for generation
 * @param modulesToGenerate modules that will be transformed to swagger API
 */
@Inject
public IoCSwaggerGenerator(@Assisted SchemaContext ctx, @Assisted Set<Module> modulesToGenerate) {
    Objects.requireNonNull(ctx);
    Objects.requireNonNull(modulesToGenerate);
    if(modulesToGenerate.isEmpty()) throw new IllegalStateException("No modules to generate has been specified");
    this.ctx = ctx;
    this.modules = modulesToGenerate;
    target = new Swagger();
    converter = new AnnotatingTypeConverter(ctx);
    moduleUtils = new ModuleUtils(ctx);
    this.moduleNames = modulesToGenerate.stream().map(ModuleIdentifier::getName).collect(Collectors.toSet());
    //assign default strategy
    strategy(Strategy.optimizing);

    //no exposed swagger API
    target.info(new Info());

    //default postprocessors
    postprocessor = new ReplaceEmptyWithParent();
}
 
Example #13
Source File: Bug9244Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testDeviateReplaceOfImplicitSubstatements() throws Exception {
    final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug9244/");
    assertNotNull(schemaContext);

    final Module barModule = schemaContext.findModule("bar", Revision.of("2017-10-13")).get();
    final ContainerSchemaNode barCont = (ContainerSchemaNode) barModule.getDataChildByName(
            QName.create(barModule.getQNameModule(), "bar-cont"));
    assertNotNull(barCont);
    assertFalse(barCont.isConfiguration());

    final LeafListSchemaNode barLeafList = (LeafListSchemaNode) barModule.getDataChildByName(
            QName.create(barModule.getQNameModule(), "bar-leaf-list"));
    assertNotNull(barLeafList);
    final ElementCountConstraint constraint = barLeafList.getElementCountConstraint().get();
    assertEquals(5, constraint.getMinElements().intValue());
    assertEquals(10, constraint.getMaxElements().intValue());

    final LeafSchemaNode barLeaf = (LeafSchemaNode) barModule.getDataChildByName(
            QName.create(barModule.getQNameModule(), "bar-leaf"));
    assertNotNull(barLeaf);
    assertTrue(barLeaf.isMandatory());
}
 
Example #14
Source File: MoreRevisionsTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static void checkInterfacesModuleFullTest(final SchemaContext context, final Revision rev20100924,
        final QName dateTimeTypeDef20100924) {
    Revision rev20121115 = Revision.of("2012-11-15");

    Module interfacesModule20121115 = context.findModule("ietf-interfaces", rev20121115).get();
    Collection<? extends ModuleImport> imports = interfacesModule20121115.getImports();
    assertEquals(1, imports.size());
    ModuleImport interfacesImport = imports.iterator().next();
    assertEquals("ietf-yang-types", interfacesImport.getModuleName());
    assertEquals(Optional.of(rev20100924), interfacesImport.getRevision());
}
 
Example #15
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 #16
Source File: NormalizedNodeStreamReaderWriterTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testNormalizedNodeStreaming() throws IOException {

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    NormalizedNodeDataOutput nnout = version.newDataOutput(ByteStreams.newDataOutput(bos));

    NormalizedNode<?, ?> testContainer = createTestContainer();
    nnout.writeNormalizedNode(testContainer);

    QName toaster = QName.create("http://netconfcentral.org/ns/toaster","2009-11-20","toaster");
    QName darknessFactor = QName.create("http://netconfcentral.org/ns/toaster","2009-11-20","darknessFactor");
    QName description = QName.create("http://netconfcentral.org/ns/toaster","2009-11-20","description");
    ContainerNode toasterNode = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(toaster))
            .withChild(ImmutableNodes.leafNode(darknessFactor, "1000"))
            .withChild(ImmutableNodes.leafNode(description, largeString(20))).build();

    ContainerNode toasterContainer = Builders.containerBuilder()
            .withNodeIdentifier(new NodeIdentifier(SchemaContext.NAME)).withChild(toasterNode).build();
    nnout.writeNormalizedNode(toasterContainer);

    final byte[] bytes = bos.toByteArray();
    assertEquals(normalizedNodeStreamingSize, bytes.length);

    NormalizedNodeDataInput nnin = NormalizedNodeDataInput.newDataInput(ByteStreams.newDataInput(bytes));

    NormalizedNode<?, ?> node = nnin.readNormalizedNode();
    Assert.assertEquals(testContainer, node);

    node = nnin.readNormalizedNode();
    Assert.assertEquals(toasterContainer, node);
}
 
Example #17
Source File: MoreRevisionsTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void moreRevisionsListKeyTest() throws ReactorException {
    SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
            .addSources(TED_20130712, TED_20131021, ISIS_20130712, ISIS_20131021, L3_20130712, L3_20131021)
            .addSources(IETF_TYPES,NETWORK_TOPOLOGY_20130712, NETWORK_TOPOLOGY_20131021)
            .buildEffective();
    assertNotNull(result);
}
 
Example #18
Source File: EffectiveUsesRefineAndConstraintsTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static void checkRefinedContainer(final SchemaContext result, final SchemaPath path) {
    SchemaNode containerInContainerNode = SchemaContextUtil.findDataSchemaNode(result, path);
    assertNotNull(containerInContainerNode);

    ContainerSchemaNode containerSchemaNode = (ContainerSchemaNode) containerInContainerNode;
    assertEquals(Optional.of("new reference"), containerSchemaNode.getReference());
    assertEquals(Optional.of("new description"), containerSchemaNode.getDescription());
    assertTrue(containerSchemaNode.isConfiguration());
    assertTrue(containerSchemaNode.isPresenceContainer());
    assertEquals(1, containerSchemaNode.getMustConstraints().size());
}
 
Example #19
Source File: Bug6771Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void augmentTest() throws Exception {
    final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6771/augment");
    assertNotNull(context);

    verifyLeafType(SchemaContextUtil
            .findDataSchemaNode(context, SchemaPath.create(true, ROOT, CONT_B, LEAF_CONT_B)));
    verifyLeafType(SchemaContextUtil.findDataSchemaNode(context,
            SchemaPath.create(true, ROOT, CONT_B, INNER_CONTAINER, LEAF_CONT_B)));
}
 
Example #20
Source File: Bug5335Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void correctTest4() throws Exception {
    final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5335/correct/case-4");
    assertNotNull(context);

    final SchemaPath schemaPath = SchemaPath.create(true, ROOT, NON_PRESENCE_CONTAINER_F, MANDATORY_LEAF_F);
    final SchemaNode mandatoryLeaf = SchemaContextUtil.findDataSchemaNode(context, schemaPath);
    assertTrue(mandatoryLeaf instanceof LeafSchemaNode);
}
 
Example #21
Source File: Bug8083Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testInstanceIdentifierPathWithEmptyListKey() throws IOException, URISyntaxException {
    final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/baz.yang");
    final String inputJson = loadTextFile("/bug8083/json/baz.json");

    // deserialization
    final NormalizedNodeResult result = new NormalizedNodeResult();
    final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
    final JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
        JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext));
    jsonParser.parse(new JsonReader(new StringReader(inputJson)));
    final NormalizedNode<?, ?> transformedInput = result.getResult();
    assertNotNull(transformedInput);
}
 
Example #22
Source File: Bug5946Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    SchemaContext context = StmtTestUtils.parseYangSources(new File(getClass()
            .getResource("/bugs/bug5946/foo.yang").toURI()));
    assertNotNull(context);

    Collection<? extends UniqueConstraint> uniqueConstraints = getListConstraints(context, WITHOUT_UNIQUE);
    assertNotNull(uniqueConstraints);
    assertTrue(uniqueConstraints.isEmpty());

    Collection<? extends UniqueConstraint> simpleUniqueConstraints = getListConstraints(context, SIMPLE_UNIQUE);
    assertNotNull(simpleUniqueConstraints);
    assertEquals(1, simpleUniqueConstraints.size());
    Collection<Descendant> simpleUniqueConstraintTag = simpleUniqueConstraints.iterator().next().getTag();
    assertTrue(simpleUniqueConstraintTag.contains(L1_ID));
    assertTrue(simpleUniqueConstraintTag.contains(C_L3_ID));

    Collection<? extends UniqueConstraint> multipleUniqueConstraints = getListConstraints(context, MULTIPLE_UNIQUE);
    assertNotNull(multipleUniqueConstraints);
    assertEquals(3, multipleUniqueConstraints.size());
    boolean l1l2 = false;
    boolean l1cl3 = false;
    boolean cl3l2 = false;
    for (UniqueConstraint uniqueConstraint : multipleUniqueConstraints) {
        Collection<Descendant> uniqueConstraintTag = uniqueConstraint.getTag();
        if (uniqueConstraintTag.contains(L1_ID) && uniqueConstraintTag.contains(L2_ID)) {
            l1l2 = true;
        } else if (uniqueConstraintTag.contains(L1_ID) && uniqueConstraintTag.contains(C_L3_ID)) {
            l1cl3 = true;
        } else if (uniqueConstraintTag.contains(C_L3_ID) && uniqueConstraintTag.contains(L2_ID)) {
            cl3l2 = true;
        }
    }
    assertTrue(l1l2 && l1cl3 && cl3l2);
}
 
Example #23
Source File: YangDataExtensionTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testConfigStatementBeingIgnoredInYangDataBody() throws Exception {
    final SchemaContext schemaContext = reactor.newBuild().addSources(BAZ_MODULE, IETF_RESTCONF_MODULE)
            .buildEffective();
    assertNotNull(schemaContext);

    final Module baz = schemaContext.findModule("baz", REVISION).get();
    final Collection<? extends UnknownSchemaNode> unknownSchemaNodes = baz.getUnknownSchemaNodes();
    assertEquals(1, unknownSchemaNodes.size());

    final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.iterator().next();
    assertTrue(unknownSchemaNode instanceof YangDataSchemaNode);
    final YangDataSchemaNode myYangDataNode = (YangDataSchemaNode) unknownSchemaNode;
    assertNotNull(myYangDataNode);

    final ContainerSchemaNode contInYangData = myYangDataNode.getContainerSchemaNode();
    assertNotNull(contInYangData);
    assertTrue(contInYangData.isConfiguration());
    final ContainerSchemaNode innerCont = (ContainerSchemaNode) contInYangData.findDataChildByName(
            QName.create(baz.getQNameModule(), "inner-cont")).get();
    assertNotNull(innerCont);
    assertTrue(innerCont.isConfiguration());
    final ContainerSchemaNode grpCont = (ContainerSchemaNode) contInYangData.findDataChildByName(
            QName.create(baz.getQNameModule(), "grp-cont")).get();
    assertNotNull(grpCont);
    assertTrue(grpCont.isConfiguration());
}
 
Example #24
Source File: SchemaContextUtil.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Beta
public static SchemaNode findDataTreeSchemaNode(final SchemaContext ctx, final QNameModule localModule,
        final PathExpression absPath) {
    final Steps pathSteps = absPath.getSteps();
    if (pathSteps instanceof LocationPathSteps) {
        return findDataTreeSchemaNode(ctx, localModule, ((LocationPathSteps) pathSteps).getLocationPath());
    }

    // We would need a reference schema node and no, we do not want to use SchemaContext in its SchemaNode capacity
    checkArgument(!(pathSteps instanceof DerefSteps), "No reference node for steps %s", pathSteps);

    // We are missing proper API alignment, if this ever triggers
    throw new IllegalStateException("Unsupported path " + pathSteps);
}
 
Example #25
Source File: InMemoryDataTreeFactory.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static DataSchemaNode getRootSchemaNode(final SchemaContext schemaContext,
        final YangInstanceIdentifier rootPath) {
    final DataSchemaContextTree contextTree = DataSchemaContextTree.from(schemaContext);
    final Optional<DataSchemaContextNode<?>> rootContextNode = contextTree.findChild(rootPath);
    checkArgument(rootContextNode.isPresent(), "Failed to find root %s in schema context", rootPath);

    final DataSchemaNode rootSchemaNode = rootContextNode.get().getDataSchemaNode();
    checkArgument(rootSchemaNode instanceof DataNodeContainer, "Root %s resolves to non-container type %s",
        rootPath, rootSchemaNode);
    return rootSchemaNode;
}
 
Example #26
Source File: Bug5335Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void correctTest2() throws Exception {
    final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5335/correct/case-2");
    assertNotNull(context);

    final SchemaPath schemaPath = SchemaPath.create(true, ROOT, PRESENCE_CONTAINER_B, NON_PRESENCE_CONTAINER_B,
            MANDATORY_LEAF_B);
    final SchemaNode mandatoryLeaf = SchemaContextUtil.findDataSchemaNode(context, schemaPath);
    assertTrue(mandatoryLeaf instanceof LeafSchemaNode);
}
 
Example #27
Source File: Bug6883Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static AnydataSchemaNode assertAnyData(final SchemaContext context, final Iterable<String> localNamesPath) {
    final Iterable<QName> qNames = Iterables.transform(localNamesPath,
        localName -> QName.create(FOO_NS, localName));
    final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
            SchemaPath.create(qNames, true));
    assertTrue(findDataSchemaNode instanceof AnydataSchemaNode);
    return (AnydataSchemaNode) findDataSchemaNode;
}
 
Example #28
Source File: Bug6150Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void effectiveAugmentSecondTest() throws ReactorException {
    final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
            .addSources(TARGET, AUGMENT_SECOND)
            .buildEffective();
    assertNotNull(result);
}
 
Example #29
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 #30
Source File: SchemaContextUtil.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Extract the identifiers of all modules and submodules which were used to create a particular SchemaContext.
 *
 * @param context SchemaContext to be examined
 * @return Set of ModuleIdentifiers.
 */
public static Set<SourceIdentifier> getConstituentModuleIdentifiers(final SchemaContext context) {
    final Set<SourceIdentifier> ret = new HashSet<>();

    for (Module module : context.getModules()) {
        ret.add(moduleToIdentifier(module));

        for (Module submodule : module.getSubmodules()) {
            ret.add(moduleToIdentifier(submodule));
        }
    }

    return ret;
}