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.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
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.UnknownSchemaNode;
21 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
22 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
23 import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource;
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.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
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(YangStatementStreamSource.create(YangTextSchemaSource.forResource("/plugin-test/foo.yang")));
37 final EffectiveSchemaContext 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;
42 final List<UnknownSchemaNode> unknownSchemaNodes = root.getUnknownSchemaNodes();
43 assertEquals(1, unknownSchemaNodes.size());
45 final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.get(0);
46 assertTrue(unknownSchemaNode instanceof ThirdPartyExtensionEffectiveStatementImpl);
48 final ThirdPartyExtensionEffectiveStatementImpl thirdPartyExtensionStmt = (ThirdPartyExtensionEffectiveStatementImpl) unknownSchemaNode;
49 assertEquals("Third-party namespace test.", thirdPartyExtensionStmt.getValueFromNamespace());
50 assertEquals("plugin test", thirdPartyExtensionStmt.argument());