91e92f70e0ac437bca1bf52d7016fb87e91fd008
[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 java.io.InputStream;
14 import java.util.List;
15 import java.util.Set;
16
17 import org.junit.Test;
18 import org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants;
19 import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntryTest;
20 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.YangModelSearchUtils;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
23
24 import com.google.common.collect.Lists;
25
26 public class UnknownExtensionTest extends ServiceInterfaceEntryTest {
27
28     @Test
29     public void testStopOnUnknownLanguageExtension() throws Exception {
30         List<InputStream> yangISs = Lists.newArrayList(getClass()
31                 .getResourceAsStream("test-ifcWithUnknownExtension.yang"));
32         yangISs.addAll(getConfigApiYangInputStreams());
33         try {
34             YangParserImpl parser = new YangParserImpl();
35             Set<Module> modulesToBuild = parser
36                     .parseYangModelsFromStreams(yangISs);
37             context = parser.resolveSchemaContext(modulesToBuild);
38             namesToModules = YangModelSearchUtils.mapModulesByNames(context
39                     .getModules());
40             configModule = namesToModules.get(ConfigConstants.CONFIG_MODULE);
41             threadsModule = namesToModules
42                     .get(ConfigConstants.CONFIG_THREADS_MODULE);
43             try {
44                 super.testCreateFromIdentities();
45                 fail();
46             } catch (IllegalStateException e) {
47                 assertTrue(
48                         e.getMessage(),
49                         e.getMessage().startsWith(
50                                 "Unexpected unknown schema node."));
51             }
52         } finally {
53             for (InputStream is : yangISs) {
54                 is.close();
55             }
56         }
57     }
58
59 }