Search in sources :

Example 1 with Deviation

use of org.opendaylight.yangtools.yang.model.api.Deviation in project yangtools by opendaylight.

the class Bug7440Test method testRestrictedTypeParentSchemaPathInDeviate.

@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 TypeDefinition<?> deviatedType = deviateReplace.getDeviatedType();
    assertEquals(QName.create(bar.getQNameModule(), "uint32"), deviatedType.getQName());
}
Also used : DeviateDefinition(org.opendaylight.yangtools.yang.model.api.DeviateDefinition) Revision(org.opendaylight.yangtools.yang.common.Revision) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Module(org.opendaylight.yangtools.yang.model.api.Module) Deviation(org.opendaylight.yangtools.yang.model.api.Deviation) Test(org.junit.Test)

Example 2 with Deviation

use of org.opendaylight.yangtools.yang.model.api.Deviation in project yangtools by opendaylight.

the class Bug9242Test method testDeviateReplaceWithUserDefinedTypes.

@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());
}
Also used : Revision(org.opendaylight.yangtools.yang.common.Revision) QName(org.opendaylight.yangtools.yang.common.QName) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) Module(org.opendaylight.yangtools.yang.model.api.Module) Deviation(org.opendaylight.yangtools.yang.model.api.Deviation) Test(org.junit.Test)

Example 3 with Deviation

use of org.opendaylight.yangtools.yang.model.api.Deviation in project yangtools by opendaylight.

the class DeviationStmtTest method testDeviationAndDeviate.

@Test
public void testDeviationAndDeviate() throws ReactorException {
    final SchemaContext schemaContext = RFC7950Reactors.defaultReactor().newBuild().addSources(FOO_MODULE, FOO_IMP_MODULE, BAR_MODULE, BAR_IMP_MODULE).buildEffective();
    assertNotNull(schemaContext);
    Module testModule = schemaContext.findModule("foo", Revision.of("2016-06-23")).get();
    Collection<? extends Deviation> deviations = testModule.getDeviations();
    assertEquals(4, deviations.size());
    for (Deviation deviation : deviations) {
        final Collection<? extends DeviateDefinition> deviates = deviation.getDeviates();
        final String targetLocalName = Iterables.getLast(deviation.getTargetPath().getNodeIdentifiers()).getLocalName();
        if ("test-leaf".equals(targetLocalName)) {
            assertEquals(Optional.of("test-leaf is not supported"), deviation.getDescription());
            assertEquals(1, deviates.size());
            assertEquals(DeviateKind.NOT_SUPPORTED, deviates.iterator().next().getDeviateType());
        } else if ("test-leaf-2".equals(targetLocalName)) {
            assertEquals(1, deviates.size());
            assertEquals(DeviateKind.ADD, deviates.iterator().next().getDeviateType());
            assertEquals("added-def-val", deviates.iterator().next().getDeviatedDefault());
            assertFalse(deviates.iterator().next().getDeviatedConfig());
            assertTrue(deviates.iterator().next().getDeviatedMandatory());
        } else if ("test-leaf-list".equals(targetLocalName)) {
            assertEquals(3, deviates.size());
            for (DeviateDefinition deviate : deviates) {
                if (DeviateKind.ADD.equals(deviate.getDeviateType())) {
                    assertEquals(12, deviate.getDeviatedMaxElements().intValue());
                } else if (DeviateKind.REPLACE.equals(deviate.getDeviateType())) {
                    assertEquals(5, deviate.getDeviatedMinElements().intValue());
                    assertTrue(deviate.getDeviatedType() instanceof Uint32TypeDefinition);
                } else {
                    assertEquals(2, deviate.getDeviatedMusts().size());
                    assertEquals("minutes", deviate.getDeviatedUnits());
                }
            }
        } else {
            assertEquals(1, deviation.getDeviates().size());
            assertEquals(DeviateKind.DELETE, deviates.iterator().next().getDeviateType());
            assertEquals(2, deviates.iterator().next().getDeviatedUniques().size());
        }
    }
    testModule = schemaContext.findModule("bar", Revision.of("2016-09-22")).get();
    assertNotNull(testModule);
    deviations = testModule.getDeviations();
    assertEquals(7, deviations.size());
    Deviation deviation1 = null;
    Deviation deviation2 = null;
    Deviation deviation3 = null;
    Deviation deviation4 = null;
    Deviation deviation5 = null;
    Deviation deviation6 = null;
    Deviation deviation7 = null;
    for (Deviation deviation : deviations) {
        final Collection<? extends DeviateDefinition> deviates = deviation.getDeviates();
        final String targetLocalName = Iterables.getLast(deviation.getTargetPath().getNodeIdentifiers()).getLocalName();
        if ("bar-container-1".equals(targetLocalName)) {
            deviation1 = deviation;
        }
        if ("bar-container-2".equals(targetLocalName)) {
            DeviateKind deviateKind = deviates.iterator().next().getDeviateType();
            if (deviateKind.equals(DeviateKind.DELETE)) {
                deviation2 = deviation;
            } else if (deviateKind.equals(DeviateKind.ADD)) {
                deviation3 = deviation;
            }
        }
        if ("bar-leaf-1".equals(targetLocalName)) {
            if (Optional.of("desc").equals(deviation.getDescription())) {
                deviation4 = deviation;
            } else {
                deviation5 = deviation;
            }
        }
        if ("bar-leaf-2".equals(targetLocalName)) {
            if (Optional.of("ref").equals(deviation.getReference())) {
                deviation6 = deviation;
            } else {
                deviation7 = deviation;
            }
        }
    }
    assertEquals(0, deviation1.getUnknownSchemaNodes().size());
    assertEquals(1, deviation1.asEffectiveStatement().getDeclared().declaredSubstatements(UnrecognizedStatement.class).size());
    assertTrue(deviation1.equals(deviation1));
    assertFalse(deviation1.equals(null));
    assertFalse(deviation1.equals("str"));
    DeviateDefinition deviate = deviation1.getDeviates().iterator().next();
    assertTrue(deviate.equals(deviate));
    assertFalse(deviate.equals(null));
    assertFalse(deviate.equals("str"));
    assertFalse(deviation1.equals(deviation2));
    assertFalse(deviation2.equals(deviation3));
    assertFalse(deviation4.equals(deviation5));
    assertFalse(deviation6.equals(deviation7));
}
Also used : DeviateDefinition(org.opendaylight.yangtools.yang.model.api.DeviateDefinition) DeviateKind(org.opendaylight.yangtools.yang.model.api.DeviateKind) Uint32TypeDefinition(org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Module(org.opendaylight.yangtools.yang.model.api.Module) Deviation(org.opendaylight.yangtools.yang.model.api.Deviation) Test(org.junit.Test)

Example 4 with Deviation

use of org.opendaylight.yangtools.yang.model.api.Deviation in project yangtools by opendaylight.

the class YangParserTest method testDeviation.

@Test
public void testDeviation() {
    final Collection<? extends Deviation> deviations = FOO.getDeviations();
    assertEquals(1, deviations.size());
    final Deviation dev = deviations.iterator().next();
    assertEquals(Optional.of("system/user ref"), dev.getReference());
    assertEquals(Absolute.of(barQName("interfaces"), barQName("ifEntry")), dev.getTargetPath());
    assertEquals(DeviateKind.ADD, dev.getDeviates().iterator().next().getDeviateType());
}
Also used : Deviation(org.opendaylight.yangtools.yang.model.api.Deviation) Test(org.junit.Test)

Example 5 with Deviation

use of org.opendaylight.yangtools.yang.model.api.Deviation in project yangtools by opendaylight.

the class YangParserWithContextTest method testDeviation.

@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 XMLNamespace expectedNS = XMLNamespace.of("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());
}
Also used : Revision(org.opendaylight.yangtools.yang.common.Revision) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Module(org.opendaylight.yangtools.yang.model.api.Module) Deviation(org.opendaylight.yangtools.yang.model.api.Deviation) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 Deviation (org.opendaylight.yangtools.yang.model.api.Deviation)6 Module (org.opendaylight.yangtools.yang.model.api.Module)5 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)4 Revision (org.opendaylight.yangtools.yang.common.Revision)3 QName (org.opendaylight.yangtools.yang.common.QName)2 DeviateDefinition (org.opendaylight.yangtools.yang.model.api.DeviateDefinition)2 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)1 XMLNamespace (org.opendaylight.yangtools.yang.common.XMLNamespace)1 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)1 DeviateKind (org.opendaylight.yangtools.yang.model.api.DeviateKind)1 FeatureDefinition (org.opendaylight.yangtools.yang.model.api.FeatureDefinition)1 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)1 ModuleImport (org.opendaylight.yangtools.yang.model.api.ModuleImport)1 Uint32TypeDefinition (org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition)1