Search in sources :

Example 1 with FeatureStatement

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

the class DeclaredStatementsTest method testDeclaredModule.

@Test
public void testDeclaredModule() throws ReactorException, ParseException {
    final StatementStreamSource rootModule = sourceForResource("/declared-statements-test/root-module-declared-test.yang");
    final StatementStreamSource importedModule = sourceForResource("/declared-statements-test/imported-module-declared-test.yang");
    final SchemaContext schemaContext = StmtTestUtils.parseYangSources(rootModule, importedModule);
    assertNotNull(schemaContext);
    final Revision revision = Revision.of("2016-09-28");
    final Module testModule = schemaContext.findModule("root-module-declared-test", revision).get();
    assertNotNull(testModule);
    final ModuleStatement moduleStatement = ((ModuleEffectiveStatement) testModule).getDeclared();
    assertEquals(1, moduleStatement.getImports().size());
    final ImportStatement importStatement = moduleStatement.getImports().iterator().next();
    assertEquals("imported-module-declared-test", importStatement.argument());
    assertEquals("imdt", importStatement.getPrefix().argument());
    assertEquals(revision, importStatement.getRevisionDate().argument());
    assertEquals("test description", moduleStatement.getDescription().get().argument());
    assertEquals("test reference", moduleStatement.getReference().get().argument());
    assertEquals("test organization", moduleStatement.getOrganization().get().argument());
    assertEquals("test contact", moduleStatement.getContact().get().argument());
    assertEquals(1, moduleStatement.getRevisions().size());
    final RevisionStatement revisionStatement = moduleStatement.getRevisions().iterator().next();
    assertEquals(revision, revisionStatement.argument());
    assertEquals("test description", revisionStatement.getDescription().get().argument());
    assertEquals("test reference", revisionStatement.getReference().get().argument());
    assertEquals(1, moduleStatement.getExtensions().size());
    final ExtensionStatement extensionStatement = moduleStatement.getExtensions().iterator().next();
    assertEquals(Status.CURRENT, extensionStatement.getStatus().get().argument());
    assertEquals("test description", extensionStatement.getDescription().get().argument());
    assertEquals("test reference", extensionStatement.getReference().get().argument());
    final ArgumentStatement argumentStatement = extensionStatement.getArgument();
    assertEquals("ext-argument", argumentStatement.argument().getLocalName());
    assertTrue(argumentStatement.getYinElement().argument());
    assertEquals(2, moduleStatement.getFeatures().size());
    final FeatureStatement featureStatement = moduleStatement.getFeatures().iterator().next();
    assertEquals(Status.CURRENT, featureStatement.getStatus().get().argument());
    assertEquals("test description", featureStatement.getDescription().get().argument());
    assertEquals("test reference", featureStatement.getReference().get().argument());
    assertEquals("test-feature", featureStatement.argument().getLocalName());
    assertEquals(1, featureStatement.getIfFeatures().size());
    assertEquals(2, moduleStatement.getIdentities().size());
    IdentityStatement identityStatement = null;
    for (final IdentityStatement identity : moduleStatement.getIdentities()) {
        if (identity.argument().getLocalName().equals("test-id")) {
            identityStatement = identity;
        }
    }
    assertEquals("test-base-id", identityStatement.getBases().iterator().next().argument().getLocalName());
    assertEquals(Status.CURRENT, identityStatement.getStatus().get().argument());
    assertEquals("test description", identityStatement.getDescription().get().argument());
    assertEquals("test reference", identityStatement.getReference().get().argument());
    assertEquals("test-id", identityStatement.argument().getLocalName());
    assertEquals(1, moduleStatement.getTypedefs().size());
    final TypedefStatement typedefStatement = moduleStatement.getTypedefs().iterator().next();
    assertEquals(Status.CURRENT, typedefStatement.getStatus().get().argument());
    assertEquals("test description", typedefStatement.getDescription().get().argument());
    assertEquals("test reference", typedefStatement.getReference().get().argument());
    assertEquals("test-typedef", typedefStatement.argument().getLocalName());
    assertEquals("int32", typedefStatement.getType().rawArgument());
    assertEquals("meter", typedefStatement.getUnits().get().argument());
}
Also used : ArgumentStatement(org.opendaylight.yangtools.yang.model.api.stmt.ArgumentStatement) StatementStreamSource(org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource) ModuleStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement) ImportStatement(org.opendaylight.yangtools.yang.model.api.stmt.ImportStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) ExtensionStatement(org.opendaylight.yangtools.yang.model.api.stmt.ExtensionStatement) TypedefStatement(org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement) Revision(org.opendaylight.yangtools.yang.common.Revision) IdentityStatement(org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Module(org.opendaylight.yangtools.yang.model.api.Module) RevisionStatement(org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement) FeatureStatement(org.opendaylight.yangtools.yang.model.api.stmt.FeatureStatement) IfFeatureStatement(org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 Revision (org.opendaylight.yangtools.yang.common.Revision)1 Module (org.opendaylight.yangtools.yang.model.api.Module)1 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)1 ArgumentStatement (org.opendaylight.yangtools.yang.model.api.stmt.ArgumentStatement)1 ExtensionStatement (org.opendaylight.yangtools.yang.model.api.stmt.ExtensionStatement)1 FeatureStatement (org.opendaylight.yangtools.yang.model.api.stmt.FeatureStatement)1 IdentityStatement (org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement)1 IfFeatureStatement (org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement)1 ImportStatement (org.opendaylight.yangtools.yang.model.api.stmt.ImportStatement)1 ModuleEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement)1 ModuleStatement (org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement)1 RevisionStatement (org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement)1 TypedefStatement (org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement)1 StatementStreamSource (org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource)1