Promote SchemaSourceRepresentation
[yangtools.git] / parser / rfc6241-parser-support / src / test / java / org / opendaylight / yangtools / rfc6241 / parser / NetconfTest.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.rfc6241.parser;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
12 import static org.junit.jupiter.api.Assertions.assertTrue;
13
14 import org.junit.jupiter.api.Test;
15 import org.opendaylight.yangtools.rfc6241.model.api.GetFilterElementAttributesSchemaNode;
16 import org.opendaylight.yangtools.rfc6241.model.api.NetconfConstants;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
20 import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
21 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
22 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
23 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
25
26 class NetconfTest {
27     private static final QName FILTER = QName.create(NetconfConstants.RFC6241_MODULE, "filter");
28
29     @Test
30     void testResolution() throws Exception {
31         final var reactor = RFC7950Reactors.defaultReactorBuilder()
32             .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION,
33                 new GetFilterElementAttributesStatementSupport(YangParserConfiguration.DEFAULT))
34             .build();
35         final var context = reactor.newBuild()
36             .addLibSources(YangStatementStreamSource.create(
37                 YangTextSource.forResource(NetconfTest.class, "/ietf-inet-types@2013-07-15.yang")))
38             .addSource(YangStatementStreamSource.create(
39                 YangTextSource.forResource(NetconfTest.class, "/ietf-netconf@2011-06-01.yang")))
40             .buildEffective();
41
42         final var module = context.findModule(NetconfConstants.RFC6241_MODULE).orElseThrow();
43         final var rpcs = module.getRpcs();
44         assertEquals(13, rpcs.size());
45         final var it = module.getRpcs().iterator();
46         // get-config
47         assertExtension(true, it.next());
48         assertExtension(false, it.next());
49         assertExtension(false, it.next());
50         assertExtension(false, it.next());
51         assertExtension(false, it.next());
52         assertExtension(false, it.next());
53         // get
54         assertExtension(true, it.next());
55         it.forEachRemaining(def -> assertExtension(false, def));
56     }
57
58     private static void assertExtension(final boolean expected, final RpcDefinition def) {
59         final var optFilter = def.getInput().findDataTreeChild(FILTER);
60         assertEquals(expected, optFilter.isPresent());
61         optFilter.ifPresent(filter -> {
62             final var anyxmlFilter = assertInstanceOf(AnyxmlSchemaNode.class, filter);
63             assertTrue(GetFilterElementAttributesSchemaNode.findIn(anyxmlFilter).isPresent());
64         });
65     }
66 }