9c0ef54c9a183e55749b0d5855cbe4cc5c42faac
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / thirdparty / plugin / ThirdPartyExtensionPluginTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.yang.thirdparty.plugin;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12
13 import java.io.IOException;
14 import java.net.URISyntaxException;
15 import java.util.List;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
22 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
23 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
24 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
26 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
27
28 public class ThirdPartyExtensionPluginTest {
29     private static final String NS = "urn:opendaylight:yang:extension:third-party";
30     private static final String REV = "2016-06-09";
31
32     @Test
33     public void test() throws URISyntaxException, ReactorException, IOException, YangSyntaxErrorException {
34         final CrossSourceStatementReactor.BuildAction reactor = CustomInferencePipeline.CUSTOM_REACTOR.newBuild();
35         reactor.addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource("/plugin-test/foo.yang")));
36
37         final SchemaContext schema = reactor.buildEffective();
38         final DataSchemaNode dataChildByName = schema.getDataChildByName(QName.create(NS, REV, "root"));
39         assertTrue(dataChildByName instanceof ContainerSchemaNode);
40         final ContainerSchemaNode root = (ContainerSchemaNode) dataChildByName;
41
42         final List<UnknownSchemaNode> unknownSchemaNodes = root.getUnknownSchemaNodes();
43         assertEquals(1, unknownSchemaNodes.size());
44
45         final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.get(0);
46         assertTrue(unknownSchemaNode instanceof ThirdPartyExtensionEffectiveStatement);
47         final ThirdPartyExtensionEffectiveStatement thirdPartyExtensionStmt =
48                 (ThirdPartyExtensionEffectiveStatement) unknownSchemaNode;
49         assertEquals("Third-party namespace test.", thirdPartyExtensionStmt.getValueFromNamespace());
50         assertEquals("plugin test", thirdPartyExtensionStmt.argument());
51     }
52 }