import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-
+import com.google.common.base.Preconditions;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
-
import org.junit.Ignore;
import org.junit.Test;
import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.NameConflictException;
import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.YangModelSearchUtils;
-import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl;
-import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.mdsal.binding.yang.types.TypeProviderImpl;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Preconditions;
-
public class ModuleMXBeanEntryNameConflictTest extends AbstractYangTest {
- private static final Logger logger = LoggerFactory
+ private static final Logger LOG = LoggerFactory
.getLogger(ModuleMXBeanEntryNameConflictTest.class);
public static final String PACKAGE_NAME = "pack2";
prepareSamples();
prepareExceptionAssertions();
- for (Map.Entry<File, String> currentTestEntry : testedFilesToYangModules
+ for (final Map.Entry<File, String> currentTestEntry : this.testedFilesToYangModules
.entrySet()) {
final String moduleName = currentTestEntry.getValue();
final File yangFile = currentTestEntry.getKey();
- Module testedModule = loadYangs(yangFile, moduleName);
+ final Module testedModule = loadYangs(yangFile, moduleName);
try {
- logger.debug("Testing {}", yangFile);
+ LOG.debug("Testing {}", yangFile);
ModuleMXBeanEntry.create(testedModule,
- new HashMap<QName, ServiceInterfaceEntry>(), context,
- new TypeProviderWrapper(new TypeProviderImpl(context)),
+ new HashMap<>(), this.context,
+ new TypeProviderWrapper(new TypeProviderImpl(this.context)),
PACKAGE_NAME);
fail(yangFile.toString()
+ " did not cause a name conflict and should");
- } catch (NameConflictException e) {
+ } catch (final NameConflictException e) {
assertEquals(
- testedYangModulesToExpectedConflictingName
+ this.testedYangModulesToExpectedConflictingName
.get(moduleName),
e.getConflictingName());
}
}
private void prepareSamples() {
- File first = new File(getClass().getResource(
+ final File first = new File(getClass().getResource(
"/duplicates/config-test-duplicate-attribute-in-list.yang")
.getFile());
- File dir = first.getParentFile();
+ final File dir = first.getParentFile();
- for (File testYang : dir.listFiles()) {
- String moduleName = getYangModuleName(testYang.getName());
- testedFilesToYangModules.put(testYang, moduleName);
+ for (final File testYang : dir.listFiles()) {
+ final String moduleName = getYangModuleName(testYang.getName());
+ this.testedFilesToYangModules.put(testYang, moduleName);
}
}
private void prepareExceptionAssertions() {
- testedYangModulesToExpectedConflictingName.put(
+ this.testedYangModulesToExpectedConflictingName.put(
"config-test-duplicate-attribute", "DtoA");
- testedYangModulesToExpectedConflictingName.put(
+ this.testedYangModulesToExpectedConflictingName.put(
"config-test-duplicate-attribute-in-list", "DtoA");
- testedYangModulesToExpectedConflictingName.put(
+ this.testedYangModulesToExpectedConflictingName.put(
"config-test-duplicate-attribute-runtime-bean", "DtoA");
- testedYangModulesToExpectedConflictingName.put(
+ this.testedYangModulesToExpectedConflictingName.put(
"config-test-generated-attributes-name-conflict", "StateB");
- testedYangModulesToExpectedConflictingName.put(
+ this.testedYangModulesToExpectedConflictingName.put(
"config-test-runtime-bean-list-name-conflict",
"StateARuntimeMXBean");
- testedYangModulesToExpectedConflictingName.put(
+ this.testedYangModulesToExpectedConflictingName.put(
"config-test-runtime-bean-list-name-conflict2",
"StateARuntimeMXBean");
- testedYangModulesToExpectedConflictingName
+ this.testedYangModulesToExpectedConflictingName
.put("config-test-runtime-bean-name-conflict", "StateARuntimeMXBean");
- testedYangModulesToExpectedConflictingName.put(
+ this.testedYangModulesToExpectedConflictingName.put(
"config-test-runtime-bean-name-conflict2",
"StateARuntimeMXBean");
- testedYangModulesToExpectedConflictingName.put(
+ this.testedYangModulesToExpectedConflictingName.put(
"config-test-duplicate-attribute-in-runtime-and-mxbean",
"port");
}
- private String getYangModuleName(String name) {
- int startIndex = 0;
- int endIndex = name.indexOf(".yang");
+ private static String getYangModuleName(final String name) {
+ final int startIndex = 0;
+ final int endIndex = name.indexOf(".yang");
return name.substring(startIndex, endIndex);
}
- private Module loadYangs(File testedModule, String moduleName)
+ private Module loadYangs(final File testedModule, final String moduleName)
throws Exception {
- List<InputStream> yangISs = new ArrayList<>();
+ final List<InputStream> yangISs = new ArrayList<>();
yangISs.addAll(getStreams("/ietf-inet-types.yang"));
yangISs.add(new FileInputStream(testedModule));
yangISs.addAll(getConfigApiYangInputStreams());
- YangParserImpl parser = new YangParserImpl();
- Set<Module> modulesToBuild = parser.parseYangModelsFromStreams(yangISs);
+ this.context = YangParserTestUtils.parseYangStreams(yangISs);
// close ISs
- for (InputStream is : yangISs) {
+ for (final InputStream is : yangISs) {
is.close();
}
- context = parser.resolveSchemaContext(modulesToBuild);
- namesToModules = YangModelSearchUtils.mapModulesByNames(context
+ this.namesToModules = YangModelSearchUtils.mapModulesByNames(this.context
.getModules());
- configModule = namesToModules.get(ConfigConstants.CONFIG_MODULE);
- final Module module = namesToModules.get(moduleName);
+ this.configModule = this.namesToModules.get(ConfigConstants.CONFIG_MODULE);
+ final Module module = this.namesToModules.get(moduleName);
Preconditions.checkNotNull(module, "Cannot get module %s from %s",
- moduleName, namesToModules.keySet());
+ moduleName, this.namesToModules.keySet());
return module;
}