Get rid of old Yang Parser in Controller
[controller.git] / opendaylight / config / yang-jmx-generator / src / test / java / org / opendaylight / controller / config / yangjmxgenerator / unknownextension / UnknownExtensionTest.java
1 /*
2  * Copyright (c) 2013 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.controller.config.yangjmxgenerator.unknownextension;
9
10 import static org.junit.Assert.assertTrue;
11 import static org.junit.Assert.fail;
12
13 import com.google.common.collect.Lists;
14 import java.io.InputStream;
15 import java.util.List;
16 import org.junit.Test;
17 import org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants;
18 import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntryTest;
19 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.YangModelSearchUtils;
20 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
22
23 public class UnknownExtensionTest extends ServiceInterfaceEntryTest {
24
25     @Test
26     public void testStopOnUnknownLanguageExtension() throws Exception {
27         List<InputStream> yangISs = Lists.newArrayList(getClass()
28                 .getResourceAsStream("test-ifcWithUnknownExtension.yang"));
29         yangISs.addAll(getConfigApiYangInputStreams());
30         try {
31             final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
32             context = reactor.buildEffective(yangISs);
33             namesToModules = YangModelSearchUtils.mapModulesByNames(context
34                     .getModules());
35             configModule = namesToModules.get(ConfigConstants.CONFIG_MODULE);
36             threadsModule = namesToModules
37                     .get(ConfigConstants.CONFIG_THREADS_MODULE);
38             try {
39                 super.testCreateFromIdentities();
40                 fail();
41             } catch (IllegalStateException e) {
42                 assertTrue(
43                         e.getMessage(),
44                         e.getMessage().startsWith(
45                                 "Unexpected unknown schema node."));
46             }
47         } finally {
48             for (InputStream is : yangISs) {
49                 is.close();
50             }
51         }
52     }
53
54 }