Fix leafref-to-enum encoding
[mdsal.git] / binding / mdsal-binding-generator-impl / src / test / java / org / opendaylight / mdsal / binding / generator / impl / GeneratedTypesStringTest.java
index 067ae8eb6ef47a7bf255a67c9dfca0a659da5b50..94dc87f77895956f1717f2e0db52f420d937df73 100644 (file)
@@ -10,41 +10,26 @@ package org.opendaylight.mdsal.binding.generator.impl;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import java.io.File;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
 import java.util.List;
-import org.junit.BeforeClass;
+import java.util.Map;
+import java.util.Map.Entry;
 import org.junit.Test;
 import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
-import org.opendaylight.mdsal.binding.generator.impl.BindingGeneratorImpl;
 import org.opendaylight.mdsal.binding.model.api.Constant;
 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
 import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
 import org.opendaylight.mdsal.binding.model.api.Type;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public class GeneratedTypesStringTest {
 
-    private final static List<File> testModels = new ArrayList<>();
-
-    @BeforeClass
-    public static void loadTestResources() throws URISyntaxException {
-        final File listModelFile = new File(GeneratedTypesStringTest.class.getResource("/simple-string-demo.yang")
-                .toURI());
-        testModels.add(listModelFile);
-    }
-
     @Test
-    public void constantGenerationTest() throws IOException, SourceException, ReactorException {
-        final SchemaContext context = YangParserTestUtils.parseYangSources(testModels);
+    public void constantGenerationTest() {
+        final SchemaContext context = YangParserTestUtils.parseYangResource("/simple-string-demo.yang");
 
         assertNotNull(context);
-        final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
+        final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
         boolean typedefStringFound = false;
@@ -68,17 +53,17 @@ public class GeneratedTypesStringTest {
                         } else {
                             break;
                         }
-                        ParameterizedType pType;
+                        ParameterizedType paramType;
                         if (con.getType() instanceof ParameterizedType) {
-                            pType = (ParameterizedType) con.getType();
+                            paramType = (ParameterizedType) con.getType();
                         } else {
                             break;
                         }
 
                         Type[] types;
-                        if (pType.getName().equals("List")) {
+                        if (paramType.getName().equals("List")) {
                             constantRegExListTypeContainer = true;
-                            types = pType.getActualTypeArguments();
+                            types = paramType.getActualTypeArguments();
                         } else {
                             break;
                         }
@@ -95,14 +80,14 @@ public class GeneratedTypesStringTest {
                             break;
                         }
 
-                        if (con.getValue() instanceof List) {
+                        if (con.getValue() instanceof Map) {
                             constantRegExListValueOK = true;
                         } else {
                             break;
                         }
 
-                        for (Object obj : (List<?>) con.getValue()) {
-                            if (!(obj instanceof String)) {
+                        for (Entry<?, ?> e : ((Map<?, ?>) con.getValue()).entrySet()) {
+                            if (!(e.getKey() instanceof String) || !(e.getKey() instanceof String)) {
                                 noStringInReqExListFound = true;
                                 break;
                             }