diff --git a/src/test/java/com/marklogic/developer/corb/PostBatchUpdateJsonFileTaskTest.java b/src/test/java/com/marklogic/developer/corb/PostBatchUpdateJsonFileTaskTest.java new file mode 100644 index 00000000..f4cd4290 --- /dev/null +++ b/src/test/java/com/marklogic/developer/corb/PostBatchUpdateJsonFileTaskTest.java @@ -0,0 +1,99 @@ +package com.marklogic.developer.corb; + +import org.junit.Test; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class PostBatchUpdateJsonFileTaskTest { + + /* + @Test + public void writeBottomContent() throws IOException { + File test = File.createTempFile("foo","txt"); + test.deleteOnExit(); + try ( + BufferedWriter writer = new BufferedWriter(new FileWriter(test, false))) { + String line; + writer.write("["); + writer.newLine(); + writer.write("{foo: 1},"); + writer.newLine(); + writer.write("{foo: 2}"); + writer.newLine(); + writer.flush(); + } + //System.out.println(TestUtils.readFile(test)); + System.setProperty("EXPORT-FILE-BOTTOM-CONTENT", "]"); + System.setProperty("EXPORT-FILE-NAME", test.getAbsolutePath()); + //System.setProperty("EXPORT-FILE-DIR", test.getParentFile().getAbsolutePath()); + PostBatchUpdateJsonFileTask puf = new PostBatchUpdateJsonFileTask(); + puf.writeBottomContent(); + + System.out.println(TestUtils.readFile(test)); + } + + @Test + public void parseFile() throws Exception { + File file = new File("/tmp/test.xml"); + + parseFile(file, "Product"); + } +*/ + public static void main(String args[]) throws ParserConfigurationException, IOException { + File file = new File("/tmp/test.xml"); + parseFile(file, "Product"); + } + + public static void parseFile(File file, String elementName) + throws ParserConfigurationException, IOException{ + List good = new ArrayList<>(); + List bad = new ArrayList<>(); + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder; + StringBuilder buffer = new StringBuilder(); + String line; + boolean append = false; + + try (Scanner scanner = new Scanner(file)){ + while (scanner.hasNextLine()) { + line = scanner.nextLine(); + if (line.startsWith('<' + elementName)) { + //start accumulating content + append = true; + } else if (line.startsWith("