Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed test cases, XMLFormatter spacer and mvn resources structure #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
\.settings/
\.project
testresults/
edireader/target/
edireader/\.settings/
edireader/\.classpath
edireader/\.project

*.class

# Mobile Tools for Java (J2ME)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.berryworks.edireader.plugin;

import com.berryworks.edireader.Plugin;

public class ANSI_837 extends Plugin {

public ANSI_837() {
super("837", "Health Care Claim");
loops = new LoopDescriptor[]{
new LoopDescriptor("2300", "CLM", 2, "/2000/2300"),
new LoopDescriptor("2300", "CLM", 2, "/2000"),
new LoopDescriptor("2305", "CR7", 3, "/2000/2300/2305"),
new LoopDescriptor("2305", "CR7", 3, "/2000/2300"),
new LoopDescriptor("2000", "HL", 1, ANY_CONTEXT),
new LoopDescriptor("2440", "LQ", 4, "/2000/2300/2400/2440"),
new LoopDescriptor("2440", "LQ", 4, "/2000/2300/2400"),
new LoopDescriptor("2400", "LX", 3, "/2000/2300/2400"),
new LoopDescriptor("2400", "LX", 3, "/2000/2300"),
new LoopDescriptor("2330", "NM1", 4, "/2000/2300/2320/2330"),
new LoopDescriptor("2420", "NM1", 4, "/2000/2300/2400/2420"),
new LoopDescriptor("2310", "NM1", 3, "/2000/2300/2310"),
new LoopDescriptor("2330", "NM1", 4, "/2000/2300/2320"),
new LoopDescriptor("2420", "NM1", 4, "/2000/2300/2400"),
new LoopDescriptor("2010", "NM1", 2, "/2000/2010"),
new LoopDescriptor("2310", "NM1", 3, "/2000/2300"),
new LoopDescriptor("2010", "NM1", 2, "/2000"),
new LoopDescriptor("1000", "NM1", 1, ANY_CONTEXT),
new LoopDescriptor("2320", "SBR", 3, "/2000/2300/2320"),
new LoopDescriptor("2320", "SBR", 3, "/2000/2300"),
new LoopDescriptor(CURRENT, "SBR", 1, "/2000"),
new LoopDescriptor("2430", "SVD", 4, "/2000/2300/2400/2430"),
new LoopDescriptor("2430", "SVD", 4, "/2000/2300/2400")};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static String fileToString(String filename) throws IOException {
return StandardCharsets.UTF_8.decode(ByteBuffer.wrap(encoded)).toString();
}

public static void stringToFile(String data, String filename) throws IOException {
try (Writer writer = new FileWriter(filename)) {
public static void stringToFile(String data, String filename) throws IOException {
try(Writer writer = new FileWriter(filename)) {
writer.write(data);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@

public class XmlFormatter extends FilterWriter {
private final static String SEPARATOR = System.getProperty("line.separator");

private final static String INDENT = " ";
private final static String INDENT = "\t";
private char mostRecentCharOfInterest;
private String currentIndent = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,34 @@

package com.berryworks.edireader;

import com.berryworks.edireader.benchmark.EDITestData;
import com.berryworks.edireader.error.ErrorMessages;
import com.berryworks.edireader.util.BranchingWriter;
import com.berryworks.edireader.util.VerboseTestCase;
import org.junit.Before;
import org.junit.Test;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;

import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.xml.sax.ContentHandler;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;

import com.berryworks.edireader.benchmark.EDITestData;
import com.berryworks.edireader.error.ErrorMessages;
import com.berryworks.edireader.util.BranchingWriter;

public class EDIAbstractReaderTest extends VerboseTestCase {
public class EDIAbstractReaderTest {

EDIReader reader;

Expand Down Expand Up @@ -68,8 +79,6 @@ public void testSyntaxElements() throws Exception {
// We call them mainly for path coverage purposes.
reader.getSubSubDelimiter();
reader.getRepetitionSeparator();

if (verbose) System.out.println(reader.toString());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.berryworks.edireader.demo;

import com.berryworks.edireader.benchmark.EDITestData;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import com.berryworks.edireader.benchmark.EDITestData;
import com.berryworks.edireader.test.utils.TestResources;

public class EDItoXMLTest {

Expand Down Expand Up @@ -67,7 +72,7 @@ public void withLeadingSpacesInData() {
}

@Test
public void canIndent() {
public void canIndent() throws Exception {
StringReader reader = new StringReader(TINY_INTERCHANGE);
StringWriter writer = new StringWriter();
ediToXml.setInputReader(reader);
Expand All @@ -76,27 +81,10 @@ public void canIndent() {
ediToXml.run();

String xmlText = writer.toString();
Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<ediroot>\n" +
" <interchange Standard=\"ANSI X.12\" AuthorizationQual=\"00\" Authorization=\" \" SecurityQual=\"00\" Security=\" \" Date=\"040714\" Time=\"1003\" StandardsId=\"U\" Version=\"00204\" Control=\"000038449\" AckRequest=\"0\" TestIndicator=\"P\">\n" +
" <sender>\n" +
" <address Id=\"04000 \" Qual=\"ZZ\"/>\n" +
" </sender>\n" +
" <receiver>\n" +
" <address Id=\"58401 \" Qual=\"ZZ\"/>\n" +
" </receiver>\n" +
" <group GroupType=\"AG\" ApplSender=\"04000\" ApplReceiver=\"58401\" Date=\"040714\" Time=\"1003\" Control=\"38327\" StandardCode=\"X\" StandardVersion=\"002040CHRY\">\n" +
" <transaction DocType=\"824\" Name=\"Application Advice\" Control=\"000042460\">\n" +
" <segment Id=\"BGN\">\n" +
" <element Id=\"BGN01\">11</element>\n" +
" <element Id=\"BGN02\"> 07141005162 </element>\n" +
" <element Id=\"BGN03\">040714</element>\n" +
" <element Id=\"BGN04\">1003</element>\n" +
" </segment>\n" +
" </transaction>\n" +
" </group>\n" +
" </interchange>\n" +
"</ediroot>", xmlText);
String benchmark = TestResources.getAsString("EDItoXMLTest.canIndent.xml");

assertTrue(xmlText.length() == benchmark.length());
assertEquals(benchmark, xmlText);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.berryworks.edireader.test.utils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

public class TestResources {

public static String getAsString(String name) throws IOException, URISyntaxException {
URI uri = TestResources.class.getResource("/" + name).toURI();
return new String(Files.readAllBytes(Paths.get(uri)));
}

public static File getAsFile(String name) throws URISyntaxException {
return new File(TestResources.class.getResource("/" + name).toURI());
}

public static InputStream getAsStream(String name) throws FileNotFoundException {
return TestResources.class.getResourceAsStream("/" + name);
}

public static Document getAsDOM(String file) throws Exception {
DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
fac.setNamespaceAware(true);
DocumentBuilder parser = fac.newDocumentBuilder();
InputStream fis = getAsStream(file);
Document doc = parser.parse(fis);
fis.close();
return doc;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
import com.berryworks.edireader.splitter.ClosingDetails;
import com.berryworks.edireader.splitter.HandlerFactory;
import com.berryworks.edireader.splitter.SplittingHandler;
import com.berryworks.edireader.test.utils.TestResources;
import com.berryworks.edireader.util.dom.DocumentUtil;
import com.berryworks.edireader.util.sax.SAXObjectHandler;
import com.berryworks.edireader.util.sax.SAXObjectReader;
import org.custommonkey.xmlunit.Diff;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.*;
Expand All @@ -31,8 +34,10 @@

import static org.junit.Assert.*;

public class SplitterTest extends VerboseTestCase {
public class SplitterTest {

@Rule public TemporaryFolder tmp = new TemporaryFolder();

private Reader inputReader;

@Test
Expand Down Expand Up @@ -146,24 +151,25 @@ public void testTwoInterchangeTwoDocumentsEachIntoDOMs() throws Exception {

@Test
public void testMain() throws Exception {
File testFile = TestResources.getAsFile("SplitterTest.testMain.edi");
File outputFile = new File(testFile.getParentFile(), "split-0000.xml");
outputFile.deleteOnExit();

PrintStream systemOut = System.out;
final ByteArrayOutputStream redirectedOut = new ByteArrayOutputStream();
System.setOut(new PrintStream(redirectedOut));
System.setOut(new PrintStream(redirectedOut));


FileUtil.stringToFile(EDITestData.getAnsiInterchange(2), "toSplit.edi");

String args[] = new String[]{"toSplit.edi", "-o", getTestresultsPath() + "x12/split-0000.xml"};
String args[] = new String[]{testFile.getAbsolutePath(), "-o", outputFile.getAbsolutePath()};
EDISplitter.main(args);

System.setOut(systemOut);

assertEquals("\nEDI input parsed into 2 XML output files\n", redirectedOut.toString());

String sep = System.getProperty("line.separator");
assertEquals(sep + "EDI input parsed into 2 XML output files" + sep, redirectedOut.toString());

assertEquals(2, EDISplitter.getCount());

File file = new File(getTestresultsPath() + "x12/split-0002.xml");
File file = new File(outputFile.getParentFile(), "split-0002.xml");
assertNotNull(file);
assertTrue(file.exists());

Expand Down Expand Up @@ -312,7 +318,7 @@ public void run() {
} catch (IOException | SAXException e) {
System.err.println(getClass().getName() + " caught " + e);
}
if (verbose) trace(getClass().getName() + " run() complete");
System.out.println(getClass().getName() + " run() complete");
}

public int getSAXEventsWritten() {
Expand All @@ -334,18 +340,18 @@ public void run() {

try {
while (!shutdown) {
if (verbose) trace("available in transformer input stream: " + inputStream.available());
System.out.println("Available in transformer input stream: " + inputStream.available());
DOMResult domResult = new DOMResult();
SAXSource source = new SAXSource(reader, inputSource);
if (verbose) trace("calling transform");
System.out.println("Calling transform");
TransformerFactory.newInstance().newTransformer().transform(source, domResult);
if (verbose) trace("return from transform");
System.out.println("Return from transform");
if (document == null)
document = (Document) domResult.getNode();
}
} catch (Exception e) {
if (verbose) trace(getClass().getName() + " caught " + e);
if (verbose) trace(getClass().getName() + " run() complete");
System.out.println(getClass().getName() + " caught " + e);
System.out.println(getClass().getName() + " run() complete");
}
}

Expand Down

This file was deleted.

Loading