Adjust to yangtools-2.0.0 changes
[controller.git] / opendaylight / config / yang-jmx-generator / src / test / java / org / opendaylight / controller / config / yangjmxgenerator / ModuleMXBeanEntryNameConflictTest.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;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.fail;
12
13 import com.google.common.base.Preconditions;
14 import com.google.common.collect.ImmutableList;
15 import java.util.ArrayList;
16 import java.util.HashMap;
17 import java.util.List;
18 import java.util.Map;
19 import org.junit.Before;
20 import org.junit.Ignore;
21 import org.junit.Test;
22 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.NameConflictException;
23 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.YangModelSearchUtils;
24 import org.opendaylight.mdsal.binding.yang.types.TypeProviderImpl;
25 import org.opendaylight.yangtools.yang.common.YangConstants;
26 import org.opendaylight.yangtools.yang.model.api.Module;
27 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 public class ModuleMXBeanEntryNameConflictTest extends AbstractYangTest {
32
33     private static final Logger LOG = LoggerFactory.getLogger(ModuleMXBeanEntryNameConflictTest.class);
34
35     public static final String PACKAGE_NAME = "pack2";
36
37     private final List<String> testedModules = ImmutableList.of(
38         "config-test-duplicate-attribute-in-list",
39         "config-test-duplicate-attribute-in-runtime-and-mxbean",
40         "config-test-duplicate-attribute-runtime-bean",
41         "config-test-duplicate-attribute",
42         "config-test-generated-attributes-name-conflict",
43         "config-test-runtime-bean-list-name-conflict2",
44         "config-test-runtime-bean-list-name-conflict",
45         "config-test-runtime-bean-name-conflict2",
46         "config-test-runtime-bean-name-conflict");
47     private final Map<String, String> testedYangModulesToExpectedConflictingName = new HashMap<>();
48
49     @Before
50     public void setup() {
51         testedYangModulesToExpectedConflictingName.put("config-test-duplicate-attribute", "DtoA");
52         testedYangModulesToExpectedConflictingName.put("config-test-duplicate-attribute-in-list", "DtoA");
53         testedYangModulesToExpectedConflictingName.put("config-test-duplicate-attribute-runtime-bean", "DtoA");
54         testedYangModulesToExpectedConflictingName.put("config-test-generated-attributes-name-conflict", "StateB");
55         testedYangModulesToExpectedConflictingName.put("config-test-runtime-bean-list-name-conflict",
56                 "StateARuntimeMXBean");
57         testedYangModulesToExpectedConflictingName.put("config-test-runtime-bean-list-name-conflict2",
58                 "StateARuntimeMXBean");
59         testedYangModulesToExpectedConflictingName.put("config-test-runtime-bean-name-conflict",
60                 "StateARuntimeMXBean");
61         testedYangModulesToExpectedConflictingName.put("config-test-runtime-bean-name-conflict2",
62                 "StateARuntimeMXBean");
63         testedYangModulesToExpectedConflictingName.put("config-test-duplicate-attribute-in-runtime-and-mxbean", "port");
64     }
65
66     private Module loadYangs(final String testedModule, final String moduleName) {
67         final List<String> yangs = new ArrayList<>();
68         yangs.add("/ietf-inet-types.yang");
69         yangs.add("/duplicates/" + testedModule + YangConstants.RFC6020_YANG_FILE_EXTENSION);
70         yangs.addAll(getConfigApiYangs());
71
72         this.context =  YangParserTestUtils.parseYangResources(ModuleMXBeanEntryNameConflictTest.class, yangs);
73         this.namesToModules = YangModelSearchUtils.mapModulesByNames(this.context.getModules());
74         this.configModule = this.namesToModules.get(ConfigConstants.CONFIG_MODULE);
75         final Module module = this.namesToModules.get(moduleName);
76         Preconditions.checkNotNull(module, "Cannot get module %s from %s", moduleName, this.namesToModules.keySet());
77         return module;
78     }
79
80     @Ignore
81     @Test
82     public void testNameConflicts() {
83         for (final String moduleName : testedModules) {
84             final Module testedModule = loadYangs(moduleName, moduleName);
85
86             try {
87                 LOG.debug("Testing {}", moduleName);
88                 ModuleMXBeanEntry.create(testedModule, new HashMap<>(), this.context,
89                         new TypeProviderWrapper(new TypeProviderImpl(this.context)), PACKAGE_NAME);
90                 fail(moduleName + " did not cause a name conflict and should");
91             } catch (final NameConflictException e) {
92                 assertEquals(this.testedYangModulesToExpectedConflictingName.get(moduleName), e.getConflictingName());
93             }
94         }
95     }
96 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.