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

The following examples show how to use org.opendaylight.yangtools.yang.model.api.Module#getRpcs() . 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: NetconfTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testResolution() throws ReactorException, IOException, YangSyntaxErrorException {
    final SchemaContext context = reactor.newBuild()
            .addLibSources(YangStatementStreamSource.create(
                YangTextSchemaSource.forResource("/[email protected]")))
            .addSource(YangStatementStreamSource.create(
                YangTextSchemaSource.forResource("/[email protected]")))
            .buildEffective();

    final Module module = context.findModule(NetconfConstants.RFC6241_MODULE).get();
    final Collection<? extends RpcDefinition> rpcs = module.getRpcs();
    assertEquals(13, rpcs.size());
    final Iterator<? extends RpcDefinition> it = module.getRpcs().iterator();
    // get-config
    assertExtension(true, it.next());
    assertExtension(false, it.next());
    assertExtension(false, it.next());
    assertExtension(false, it.next());
    assertExtension(false, it.next());
    assertExtension(false, it.next());
    // get
    assertExtension(true, it.next());
    it.forEachRemaining(def -> assertExtension(false, def));
}
 
Example 2
Source File: RpcStmtTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testImplicitInputAndOutput() throws Exception {
    final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rpc-stmt-test/bar.yang");
    assertNotNull(schemaContext);

    final Module barModule = schemaContext.findModule("bar", Revision.of("2016-11-25")).get();
    final Collection<? extends RpcDefinition> rpcs = barModule.getRpcs();
    assertEquals(1, rpcs.size());

    final RpcDefinition barRpc = rpcs.iterator().next();

    final ContainerSchemaNode input = barRpc.getInput();
    assertNotNull(input);
    assertEquals(2, input.getChildNodes().size());
    assertEquals(StatementSource.CONTEXT, ((EffectiveStatement<?, ?>) input).getStatementSource());

    final ContainerSchemaNode output = barRpc.getOutput();
    assertNotNull(output);
    assertEquals(2, output.getChildNodes().size());
    assertEquals(StatementSource.CONTEXT, ((EffectiveStatement<?, ?>) output).getStatementSource());
}
 
Example 3
Source File: SchemaContextUtilTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static RpcDefinition getRpcByName(final Module module, final String name) {
    for (final RpcDefinition rpc : module.getRpcs()) {
        if (rpc.getQName().getLocalName().equals(name)) {
            return rpc;
        }
    }
    return null;
}
 
Example 4
Source File: Bug6871Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testValidYang11Model() throws Exception {
    final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6871/foo.yang");
    assertNotNull(schemaContext);

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

    final Collection<? extends NotificationDefinition> notifications = foo.getNotifications();
    assertEquals(1, notifications.size());
    final NotificationDefinition myNotification = notifications.iterator().next();
    Collection<? extends MustDefinition> mustConstraints = myNotification.getMustConstraints();
    assertEquals(2, mustConstraints.size());

    final Collection<? extends RpcDefinition> rpcs = foo.getRpcs();
    assertEquals(1, rpcs.size());
    final RpcDefinition myRpc = rpcs.iterator().next();

    final ContainerSchemaNode input = myRpc.getInput();
    assertNotNull(input);
    mustConstraints = input.getMustConstraints();
    assertEquals(2, mustConstraints.size());

    final ContainerSchemaNode output = myRpc.getOutput();
    assertNotNull(output);
    mustConstraints = output.getMustConstraints();
    assertEquals(2, mustConstraints.size());
}
 
Example 5
Source File: YinFileRpcStmtTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testRpc() {
    Module testModule = TestUtils.findModule(context, "ietf-netconf-monitoring").get();

    Collection<? extends RpcDefinition> rpcs = testModule.getRpcs();
    assertEquals(1, rpcs.size());

    RpcDefinition rpc = rpcs.iterator().next();
    assertEquals("get-schema", rpc.getQName().getLocalName());
    assertEquals(Optional.of("This operation is used to retrieve a schema from the\n"
            + "NETCONF server.\n"
            + "\n"
            + "Positive Response:\n"
            + "The NETCONF server returns the requested schema.\n"
            + "\n"
            + "Negative Response:\n"
            + "If requested schema does not exist, the <error-tag> is\n"
            + "'invalid-value'.\n"
            + "\n"
            + "If more than one schema matches the requested parameters, the\n"
            + "<error-tag> is 'operation-failed', and <error-app-tag> is\n"
            + "'data-not-unique'."), rpc.getDescription());

    ContainerSchemaNode input = rpc.getInput();
    assertNotNull(input);
    assertEquals(3, input.getChildNodes().size());

    ContainerSchemaNode output = rpc.getOutput();
    assertNotNull(output);
    assertEquals(1, output.getChildNodes().size());
}
 
Example 6
Source File: Bug6410Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testTypedefsInRpc() throws ReactorException {
    final SchemaContext schemaContext = StmtTestUtils.parseYangSources(sourceForResource("/bugs/bug6410/foo.yang"));

    final Collection<? extends Module> modules = schemaContext.getModules();
    assertEquals(1, modules.size());
    final Module module = modules.iterator().next();

    final Collection<? extends RpcDefinition> rpcs = module.getRpcs();
    assertEquals(1, rpcs.size());
    final RpcDefinition rpc = rpcs.iterator().next();

    final Collection<? extends TypeDefinition<?>> typeDefs = rpc.getTypeDefinitions();
    assertEquals(2, typeDefs.size());
}
 
Example 7
Source File: SchemaContextUtil.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static RpcDefinition getRpcByName(final Module module, final QName name) {
    for (final RpcDefinition rpc : module.getRpcs()) {
        if (rpc.getQName().equals(name)) {
            return rpc;
        }
    }
    return null;
}
 
Example 8
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());
}
 
Example 9
Source File: RpcStmtTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void rpcTest() throws ReactorException {
    final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
            .addSource(sourceForResource("/model/baz.yang"))
            .addSource(sourceForResource("/model/bar.yang"))
            .addSource(sourceForResource("/rpc-stmt-test/foo.yang"))
            .buildEffective();
    assertNotNull(result);

    final Module testModule = result.findModules("baz").iterator().next();
    assertEquals(1, testModule.getRpcs().size());

    final RpcDefinition rpc = testModule.getRpcs().iterator().next();
    assertEquals("get-config", rpc.getQName().getLocalName());

    final ContainerSchemaNode input = rpc.getInput();
    assertNotNull(input);
    assertEquals(2, input.getChildNodes().size());

    final ContainerSchemaNode container = (ContainerSchemaNode) input.getDataChildByName(
        QName.create(testModule.getQNameModule(), "source"));
    assertNotNull(container);
    AnyxmlSchemaNode anyXml = (AnyxmlSchemaNode) input.getDataChildByName(
        QName.create(testModule.getQNameModule(), "filter"));
    assertNotNull(anyXml);

    final ContainerSchemaNode output = rpc.getOutput();
    assertNotNull(output);
    assertEquals(1, output.getChildNodes().size());

    anyXml = (AnyxmlSchemaNode) output.getDataChildByName(QName.create(testModule.getQNameModule(), "data"));
    assertNotNull(anyXml);

    final Module fooModule = result.findModule("foo", Revision.of("2016-09-23")).get();
    final Collection<? extends RpcDefinition> rpcs = fooModule.getRpcs();
    assertEquals(2, rpcs.size());

    RpcDefinition fooRpc1 = null;
    RpcDefinition fooRpc2 = null;

    for (RpcDefinition rpcDefinition : rpcs) {
        if ("foo-rpc-1".equals(rpcDefinition.getQName().getLocalName())) {
            fooRpc1 = rpcDefinition;
        } else if ("foo-rpc-2".equals(rpcDefinition.getQName().getLocalName())) {
            fooRpc2 = rpcDefinition;
        }
    }

    assertFalse(fooRpc1.equals(null));
    assertFalse(fooRpc1.equals("str"));
    assertFalse(fooRpc1.equals(fooRpc2));

    assertNotEquals(fooRpc1.getInput().hashCode(), fooRpc2.getInput().hashCode());
    assertNotEquals(fooRpc1.getOutput().hashCode(), fooRpc2.getOutput().hashCode());

    assertTrue(fooRpc1.getInput().equals(fooRpc1.getInput()));
    assertFalse(fooRpc1.getInput().equals(null));
    assertFalse(fooRpc1.getInput().equals("str"));
    assertFalse(fooRpc1.getInput().equals(fooRpc2.getInput()));

    assertTrue(fooRpc1.getOutput().equals(fooRpc1.getOutput()));
    assertFalse(fooRpc1.getOutput().equals(null));
    assertFalse(fooRpc1.getOutput().equals("str"));
    assertFalse(fooRpc1.getOutput().equals(fooRpc2.getOutput()));
}