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;
14 import java.io.FileInputStream;
15 import java.io.FileNotFoundException;
16 import java.net.URISyntaxException;
17 import java.util.List;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
24 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
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 FileNotFoundException, URISyntaxException, ReactorException {
34 final CrossSourceStatementReactor.BuildAction reactor = CustomInferencePipeline.CUSTOM_REACTOR.newBuild();
35 final FileInputStream yangFile = new FileInputStream(new File(getClass().getResource("/plugin-test/foo.yang")
37 reactor.addSource(new YangStatementSourceImpl(yangFile));
39 final EffectiveSchemaContext schema = reactor.buildEffective();
40 final DataSchemaNode dataChildByName = schema.getDataChildByName(QName.create(NS, REV, "root"));
41 assertTrue(dataChildByName instanceof ContainerSchemaNode);
42 final ContainerSchemaNode root = (ContainerSchemaNode) dataChildByName;
44 final List<UnknownSchemaNode> unknownSchemaNodes = root.getUnknownSchemaNodes();
45 assertEquals(1, unknownSchemaNodes.size());
47 final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.get(0);
48 assertTrue(unknownSchemaNode instanceof ThirdPartyExtensionEffectiveStatementImpl);
50 final ThirdPartyExtensionEffectiveStatementImpl thirdPartyExtensionStmt = (ThirdPartyExtensionEffectiveStatementImpl) unknownSchemaNode;
51 assertEquals("Third-party namespace test.", thirdPartyExtensionStmt.getValueFromNamespace());
52 assertEquals("plugin test", thirdPartyExtensionStmt.argument());