Fix of failing tests in yang-data-json 75/5775/2
authorJozef Gloncak <jgloncak@cisco.com>
Wed, 26 Mar 2014 14:36:07 +0000 (15:36 +0100)
committerJozef Gloncak <jgloncak@cisco.com>
Wed, 26 Mar 2014 14:43:21 +0000 (15:43 +0100)
Method loadModules in TestUtils was changed to accept URI type input parameter
instead String type.

Change-Id: I27edf31788880d50cdca8deba754bcffd14da0b8
Signed-off-by: Jozef Gloncak <jgloncak@cisco.com>
yang/yang-data-json/src/test/java/org/opendaylight/yangtools/yang/data/json/schema/TestUtils.java
yang/yang-data-json/src/test/java/org/opendaylight/yangtools/yang/data/json/schema/cnsn/parser/ParseCnSnStructToNormalizedStructTest.java
yang/yang-data-json/src/test/java/org/opendaylight/yangtools/yang/data/json/schema/cnsn/serializer/SerializeNormalizedStructToCnSnStructTest.java

index 99af5cd88ece4c0aaf17ac81123458e8f652798d..a27a465b139f0bc7ce83c8ea925dcea11149a924 100644 (file)
@@ -53,8 +53,6 @@ public class TestUtils {
 
     private static final Logger LOG = LoggerFactory.getLogger(TestUtils.class);
 
-    private final static YangModelParser parser = new YangParserImpl();
-
     private static final String NAMESPACE_BASE = "simple:container:yang";
     private static final String NAMESPACE_AUGMENT = "augment:container:yang";
     private static Date revision_base;
@@ -69,25 +67,23 @@ public class TestUtils {
         }
     }
 
-    private static Set<Module> loadModules(String resourceDirectory) throws FileNotFoundException {
-        final File testDir = new File(resourceDirectory);
+    public static Set<Module> loadModules(URI resourceURI) throws FileNotFoundException {
+        final YangModelParser parser = new YangParserImpl();
+        final File testDir = new File(resourceURI);
         final String[] fileList = testDir.list();
-        final List<File> testFiles = new ArrayList<File>();
+        final List<File> testFiles = new ArrayList<>();
         if (fileList == null) {
-            throw new FileNotFoundException(resourceDirectory);
+            throw new FileNotFoundException(resourceURI.toString());
         }
-        for (int i = 0; i < fileList.length; i++) {
-            String fileName = fileList[i];
-            if (new File(testDir, fileName).isDirectory() == false) {
-                testFiles.add(new File(testDir, fileName));
-            }
+        for (String fileName : fileList) {
+            testFiles.add(new File(testDir, fileName));
         }
         return parser.parseYangModels(testFiles);
     }
 
-    public static Set<Module> loadModulesFrom(String yangPath) {
+    public static Set<Module> loadModulesFrom(String yangPath) throws URISyntaxException {
         try {
-            return loadModules(TestUtils.class.getResource(yangPath).getPath());
+            return loadModules(TestUtils.class.getResource(yangPath).toURI());
         } catch (FileNotFoundException e) {
             LOG.error("Yang files at path: " + yangPath + " weren't loaded.");
         }
@@ -209,7 +205,6 @@ public class TestUtils {
                         Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("lf21"))
                                 .withValue("value in cont2/lf21").build()).build());
 
-
         CollectionNodeBuilder<MapEntryNode, MapNode> lst1 = Builders.mapBuilder().withNodeIdentifier(
                 getNodeIdentifier("lst1"));
         lst1.withChild(Builders.mapEntryBuilder()
@@ -271,7 +266,6 @@ public class TestUtils {
                                                         getNodeIdentifier("lf31", NAMESPACE_AUGMENT, revision_augment))
                                                 .withValue("value in leaf in augment").build()).build()).build());
 
-
         ContainerNode build = containerBuilder.build();
         return build;
     }
index d1f9f82f78545f81174eb8f6c2a45c5b8e8e8bef..223278c78c6df0df68afd6780163ee5bfe9eac6c 100644 (file)
@@ -29,7 +29,7 @@ public class ParseCnSnStructToNormalizedStructTest {
     private static DataSchemaNode resolvedDataSchemaNode;
 
     @BeforeClass
-    public static void loadData() {
+    public static void loadData() throws URISyntaxException {
         Set<Module> modules = TestUtils.loadModulesFrom("/cnsn-to-normalized-node/yang");
         Module resolvedModule = TestUtils.resolveModule("simple-container-yang", modules);
         resolvedDataSchemaNode = TestUtils.resolveDataSchemaNode("cont", resolvedModule);
index 54efb158bf366982889327dd5a50894e214041f8..635c18b377772451d3ea3ce45add96f27582ecf1 100644 (file)
@@ -28,7 +28,7 @@ public class SerializeNormalizedStructToCnSnStructTest {
     private static DataSchemaNode resolvedDataSchemaNode;
 
     @BeforeClass
-    public static void loadData() {
+    public static void loadData() throws URISyntaxException {
         Set<Module> modules = TestUtils.loadModulesFrom("/cnsn-to-normalized-node/yang");
         Module resolvedModule = TestUtils.resolveModule("simple-container-yang", modules);
         resolvedDataSchemaNode = TestUtils.resolveDataSchemaNode("cont", resolvedModule);