2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.thirdparty.plugin;
10 import static org.hamcrest.MatcherAssert.assertThat;
11 import static org.hamcrest.Matchers.isA;
12 import static org.junit.Assert.assertEquals;
14 import java.io.IOException;
15 import java.net.URISyntaxException;
16 import java.util.Collection;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
23 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
25 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
26 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
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";
33 public void test() throws URISyntaxException, ReactorException, IOException, YangSyntaxErrorException {
34 final CrossSourceStatementReactor.BuildAction reactor = CustomInferencePipeline.CUSTOM_REACTOR.newBuild();
35 reactor.addSource(StmtTestUtils.sourceForResource("/plugin-test/foo.yang"));
37 final SchemaContext schema = reactor.buildEffective();
38 final DataSchemaNode dataChildByName = schema.getDataChildByName(QName.create(NS, REV, "root"));
39 assertThat(dataChildByName, isA(ContainerSchemaNode.class));
41 final ContainerSchemaNode root = (ContainerSchemaNode) dataChildByName;
43 final Collection<? extends UnknownSchemaNode> unknownSchemaNodes = root.getUnknownSchemaNodes();
44 assertEquals(1, unknownSchemaNodes.size());
46 final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.iterator().next();
47 assertThat(unknownSchemaNode, isA(ThirdPartyExtensionEffectiveStatement.class));
48 final ThirdPartyExtensionEffectiveStatement thirdPartyExtensionStmt =
49 (ThirdPartyExtensionEffectiveStatement) unknownSchemaNode;
50 assertEquals("Third-party namespace test.", thirdPartyExtensionStmt.getValueFromNamespace());
51 assertEquals("plugin test", thirdPartyExtensionStmt.argument());