Java Code Examples for org.opendaylight.yangtools.yang.model.api.Module#getDeviations()

The following examples show how to use org.opendaylight.yangtools.yang.model.api.Module#getDeviations() . 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: YangParserWithContextTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testDeviation() throws ReactorException {
    final SchemaContext context = RFC7950Reactors.defaultReactor().newBuild()
            .addSource(sourceForResource("/model/bar.yang"))
            .addSource(sourceForResource("/context-test/deviation-test.yang"))
            .buildEffective();

    final Module testModule = context.findModule("deviation-test", Revision.of("2013-02-27")).get();
    final Collection<? extends Deviation> deviations = testModule.getDeviations();
    assertEquals(1, deviations.size());
    final Deviation dev = deviations.iterator().next();

    assertEquals(Optional.of("system/user ref"), dev.getReference());

    final URI expectedNS = URI.create("urn:opendaylight.bar");
    final Revision expectedRev = Revision.of("2013-07-03");

    assertEquals(Absolute.of(
        QName.create(expectedNS, expectedRev, "interfaces"), QName.create(expectedNS, expectedRev, "ifEntry")),
        dev.getTargetPath());
    assertEquals(DeviateKind.ADD, dev.getDeviates().iterator().next().getDeviateType());
}
 
Example 2
Source File: Bug7440Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testRestrictedTypeParentSchemaPathInDeviate() throws Exception {
    final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug7440");
    assertNotNull(schemaContext);

    final Revision revision = Revision.of("2016-12-23");
    final Module foo = schemaContext.findModule("foo", revision).get();
    final Module bar = schemaContext.findModule("bar", revision).get();

    final Collection<? extends Deviation> deviations = foo.getDeviations();
    assertEquals(1, deviations.size());
    final Deviation deviation = deviations.iterator().next();

    final Collection<? extends DeviateDefinition> deviates = deviation.getDeviates();
    assertEquals(1, deviates.size());
    final DeviateDefinition deviateReplace = deviates.iterator().next();

    final SchemaPath deviatedTypePath = SchemaPath.create(true, QName.create(bar.getQNameModule(), "test-leaf"),
            QName.create(bar.getQNameModule(), "uint32"));

    final TypeDefinition<?> deviatedType = deviateReplace.getDeviatedType();
    assertEquals(deviatedTypePath, deviatedType.getPath());
}
 
Example 3
Source File: Bug9242Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testDeviateReplaceWithUserDefinedTypes() throws Exception {
    final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug9242/");
    assertNotNull(schemaContext);

    final Revision revision = Revision.of("2017-10-13");
    final Module rootModule = schemaContext.findModule("root-module", revision).get();
    final Module impModule = schemaContext.findModule("imp-module", revision).get();

    TypeDefinition<?> deviatedMyLeafType = null;
    TypeDefinition<?> deviatedMyLeaf2Type = null;

    for (final Deviation deviation : rootModule.getDeviations()) {
        final QName last = Iterables.getLast(deviation.getTargetPath().getNodeIdentifiers());
        if (last.equals(QName.create(impModule.getQNameModule(), "my-leaf"))) {
            deviatedMyLeafType = deviation.getDeviates().iterator().next().getDeviatedType();
        }

        if (last.equals(QName.create(impModule.getQNameModule(), "my-leaf-2"))) {
            deviatedMyLeaf2Type = deviation.getDeviates().iterator().next().getDeviatedType();
        }
    }

    assertNotNull(deviatedMyLeafType);
    assertNotNull(deviatedMyLeaf2Type);

    final LeafSchemaNode myLeaf = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
            impModule.getQNameModule(), "my-leaf"));
    assertSame(deviatedMyLeafType, myLeaf.getType());

    final LeafSchemaNode myLeaf2 = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
            impModule.getQNameModule(), "my-leaf-2"));
    assertSame(deviatedMyLeaf2Type, myLeaf2.getType());
}
 
Example 4
Source File: Bug4933Test.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("/bugs/bug4933/correct");
    assertNotNull(context);

    final Module foo = context.findModules("foo").iterator().next();
    Collection<? extends Deviation> deviations = foo.getDeviations();
    assertEquals(4, deviations.size());
}
 
Example 5
Source File: EffectiveModuleTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void effectiveBuildTest() throws SourceException, ReactorException {
    SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
            .addSources(ROOT_MODULE, IMPORTED_MODULE, SUBMODULE)
            .buildEffective();

    assertNotNull(result);

    Module rootModule = result.findModules("root").iterator().next();
    assertNotNull(rootModule);

    assertEquals("root-pref", rootModule.getPrefix());
    assertEquals(YangVersion.VERSION_1, rootModule.getYangVersion());
    assertEquals(Optional.of("cisco"), rootModule.getOrganization());
    assertEquals(Optional.of("cisco email"), rootModule.getContact());

    final ContainerSchemaNode contSchemaNode = (ContainerSchemaNode) rootModule.getDataChildByName(CONT);
    assertNotNull(contSchemaNode);

    final Collection<? extends AugmentationSchemaNode> augmentations = rootModule.getAugmentations();
    assertEquals(1, augmentations.size());
    assertEquals(Absolute.of(CONT), augmentations.iterator().next().getTargetPath());

    final Collection<? extends ModuleImport> imports = rootModule.getImports();
    assertEquals(1, imports.size());
    final ModuleImport importStmt = imports.iterator().next();
    assertNotNull(importStmt);
    assertEquals("imported", importStmt.getModuleName());
    assertEquals(Optional.of(REVISION), importStmt.getRevision());
    assertEquals("imp-pref", importStmt.getPrefix());

    final Collection<? extends Module> submodules = rootModule.getSubmodules();
    assertEquals(1, submodules.size());
    assertEquals("submod", submodules.iterator().next().getName());

    final Collection<? extends NotificationDefinition> notifications = rootModule.getNotifications();
    assertEquals(1, notifications.size());
    assertEquals("notif1", notifications.iterator().next().getQName().getLocalName());

    final Collection<? extends RpcDefinition> rpcs = rootModule.getRpcs();
    assertEquals(1, rpcs.size());
    assertEquals("rpc1", rpcs.iterator().next().getQName().getLocalName());

    final Collection<? extends Deviation> deviations = rootModule.getDeviations();
    assertEquals(1, deviations.size());
    final Deviation deviationStmt = deviations.iterator().next();
    assertNotNull(deviationStmt);
    final QNameModule importedModuleQName = QNameModule.create(URI.create("imported"), REVISION);
    final QName importedContQName = QName.create(importedModuleQName, "cont");
    assertEquals(Absolute.of(importedContQName), deviationStmt.getTargetPath());
    assertEquals(DeviateKind.ADD, deviationStmt.getDeviates().iterator().next().getDeviateType());
    assertEquals(Optional.of("deviate reference"), deviationStmt.getReference());

    final Collection<? extends IdentitySchemaNode> identities = rootModule.getIdentities();
    assertEquals(1, identities.size());
    assertEquals("identity1", identities.iterator().next().getQName().getLocalName());

    final Collection<? extends FeatureDefinition> features = rootModule.getFeatures();
    assertEquals(1, features.size());
    final FeatureDefinition featureStmt = features.iterator().next();
    assertNotNull(featureStmt);
    assertEquals(FEATURE1, featureStmt.getQName());
    assertEquals(FEATURE1_SCHEMA_PATH, featureStmt.getPath());
    assertEquals(Optional.of("feature1 description"), featureStmt.getDescription());
    assertEquals(Optional.of("feature1 reference"), featureStmt.getReference());
    assertEquals(Status.CURRENT, featureStmt.getStatus());

    final Collection<? extends ExtensionDefinition> extensionSchemaNodes = rootModule.getExtensionSchemaNodes();
    assertEquals(1, extensionSchemaNodes.size());
    assertEquals("ext1", extensionSchemaNodes.iterator().next().getQName().getLocalName());
}