BUG-1902: reuse ConcreteTypeImpl instances
[yangtools.git] / code-generator / binding-generator-util / src / test / java / org / opendaylight / yangtools / binding / generator / util / BindingGeneratorUtilTest.java
index aa1c0c21952321e1817ebca7a283c4138a2ee032..ef268c7ed998cef2e10637677fe3828b351a8531 100644 (file)
@@ -13,15 +13,17 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 
 import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
-
 import org.junit.Test;
+import org.opendaylight.yangtools.yang.binding.BindingMapping;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
+import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser;
 import org.opendaylight.yangtools.yang.model.util.DataNodeIterator;
 import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
@@ -30,7 +32,12 @@ public class BindingGeneratorUtilTest {
 
     private static List<File> loadTestResources(String testFile) {
         final List<File> testModels = new ArrayList<File>();
-        final File listModelFile = new File(BindingGeneratorUtilTest.class.getResource(testFile).getPath());
+        File listModelFile;
+        try {
+            listModelFile = new File(BindingGeneratorUtilTest.class.getResource(testFile).toURI());
+        } catch (URISyntaxException e) {
+            throw new IllegalArgumentException("Failed to load sources from " + testFile);
+        }
         testModels.add(listModelFile);
         return testModels;
     }
@@ -47,10 +54,10 @@ public class BindingGeneratorUtilTest {
      * - without revision </ul>
      */
     @Test
-    public void testBindingGeneratorUtilMethods() {
+    public void testBindingGeneratorUtilMethods() throws IOException {
         List<File> testModels = loadTestResources("/module.yang");
-        final YangModelParser parser = new YangParserImpl();
-        final Set<Module> modules = parser.parseYangModels(testModels);
+        final YangContextParser parser = new YangParserImpl();
+        final Set<Module> modules = parser.parseFiles(testModels).getModules();
         String packageName = "";
         Module module = null;
         for (Module m : modules) {
@@ -93,7 +100,8 @@ public class BindingGeneratorUtilTest {
                 subPackageNameForTypeDefinition);
 
         // test of exception part of the method moduleNamespaceToPackageName()
-        ModuleBuilder moduleBuilder = new ModuleBuilder("module-withut-revision");
+        ModuleBuilder moduleBuilder = new ModuleBuilder("module-withut-revision", null);
+        moduleBuilder.setSource("");
         Module moduleWithoutRevision = moduleBuilder.build();
         boolean passedSuccesfully = false;
         try {
@@ -143,9 +151,9 @@ public class BindingGeneratorUtilTest {
     public void testParsingMethods() {
         // parseToClassName method testing
         assertEquals("Class name has incorrect format", "SomeTestingClassName",
-                BindingGeneratorUtil.parseToClassName("  some-testing_class name   "));
+                BindingMapping.getClassName("  some-testing_class name   "));
         assertEquals("Class name has incorrect format", "_0SomeTestingClassName",
-                BindingGeneratorUtil.parseToClassName("  0 some-testing_class name   "));
+                BindingMapping.getClassName("  0 some-testing_class name   "));
 
         // parseToValidParamName
         assertEquals("Parameter name has incorrect format", "someTestingParameterName",