Bug 8002 - Fixing and cleanup of templates for binding2
[mdsal.git] / binding2 / mdsal-binding2-generator-util / src / test / java / org / opendaylight / mdsal / binding / javav2 / generator / util / YangSnippetCleanerTest.java
diff --git a/binding2/mdsal-binding2-generator-util/src/test/java/org/opendaylight/mdsal/binding/javav2/generator/util/YangSnippetCleanerTest.java b/binding2/mdsal-binding2-generator-util/src/test/java/org/opendaylight/mdsal/binding/javav2/generator/util/YangSnippetCleanerTest.java
new file mode 100644 (file)
index 0000000..fa48a33
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2017 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.javav2.generator.util;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class YangSnippetCleanerTest {
+
+    @Test
+    public void cleanerTest() throws Exception {
+        final String badWs = readFile(this.getClass().getResourceAsStream("/yangs/break_ws/bad-ws.yang"));
+        final String fixedBadWs = readFile(this.getClass().getResourceAsStream("/yangs/break_ws/fixed-bad-ws.yang"));
+        final String cleanBadWs = YangSnippetCleaner.clean(badWs);
+        Assert.assertEquals(fixedBadWs, cleanBadWs);
+    }
+
+    private String readFile(final InputStream inputStream) throws IOException {
+        final BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
+        try {
+            final StringBuilder sb = new StringBuilder();
+            String line = br.readLine();
+
+            while (line != null) {
+                if (!line.contains("//")) {
+                    sb.append(line);
+                }
+                sb.append("\n");
+                line = br.readLine();
+            }
+            return sb.toString();
+        } finally {
+            br.close();
+        }
+    }
+}