Skip to content

Commit

Permalink
rename files and namespaces, clean test files
Browse files Browse the repository at this point in the history
  • Loading branch information
short000 committed Mar 26, 2018
1 parent c1bdcaa commit 4b298ed
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.null0.edi.debatcher.interfaces;
package org.null0.x12.debatcher;

import java.nio.file.Path;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.null0.edi.debatcher;
package org.null0.x12.debatcher;

import java.io.BufferedWriter;
import java.io.File;
Expand All @@ -15,14 +15,11 @@
import java.util.Stack;

import org.apache.commons.lang3.StringUtils;
import org.null0.edi.debatcher.DebatcherException.ERROR_LEVEL;
import org.null0.edi.debatcher.interfaces.EdiValidator;
import org.null0.edi.debatcher.interfaces.EdiValidator.CLAIM_TYPE;
import org.null0.edi.debatcher.interfaces.EdiValidator.ERROR;
import org.null0.edi.debatcher.interfaces.EdiValidator.X12_ELEMENT;
import org.null0.edi.debatcher.interfaces.Config;
import org.null0.edi.debatcher.interfaces.MetadataLogger;
import org.null0.edi.debatcher.EdiValidatorDefault;
import org.null0.x12.debatcher.DefaultValidator;
import org.null0.x12.debatcher.DebatcherException.ERROR_LEVEL;
import org.null0.x12.debatcher.Validator.CLAIM_TYPE;
import org.null0.x12.debatcher.Validator.ERROR;
import org.null0.x12.debatcher.Validator.X12_ELEMENT;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -36,8 +33,8 @@ public class Debatcher {
// Class Invariants (CTOR)
// -----------------------
private Config config; // injected by greedy CTOR
private EdiValidator ediValidator; // injected by greedy CTOR
private MetadataLogger metadataLogger; // injected by greedy CTOR
private Validator ediValidator; // injected by greedy CTOR
private Metadata metadataLogger; // injected by greedy CTOR
private Delimiters delimiters; // internal
private SegmentReader segmentReader; // internal

Expand Down Expand Up @@ -75,7 +72,7 @@ public class Debatcher {
private Set<String> segmentsBeforeRefD9ForI; // TODO: specific to claims (873). Decouple.
private CLAIM_TYPE claimType; // TODO: specific to claims (837). Decouple.

public Debatcher(Config config, EdiValidator ediValidator, MetadataLogger metadataLogger) {
public Debatcher(Config config, Validator ediValidator, Metadata metadataLogger) {
this.config = config;
this.ediValidator = ediValidator;
this.metadataLogger = metadataLogger;
Expand Down Expand Up @@ -135,7 +132,7 @@ private void readInterchangeControls() throws Exception {

/* TODO: we should probably delete this
if (segment == null || segment.equals("\r\n")) {
throw new DebatcherException ("Invalid Control Structure", EdiValidatorDefault.TA1_ERROR_ISAIEA, ERROR.TYPE_TA1, ERROR_LEVEL.Batch, batchIdMetadata);
throw new DebatcherException ("Invalid Control Structure", DefaultValidator.TA1_ERROR_ISAIEA, ERROR.TYPE_TA1, ERROR_LEVEL.Batch, batchIdMetadata);
}*/

isaSegment = segment.replaceAll("\\r|\\n", "");
Expand Down Expand Up @@ -178,7 +175,7 @@ private void readInterchangeControls() throws Exception {
if (!isa13.equals(iea02)) {
logger.error("ISA13 {} & IEA02 {} don't match", isa13, iea02);
throw new DebatcherException("ISA13 & IEA02 don't match",
EdiValidatorDefault.TA1_ERROR_ISA13,
DefaultValidator.TA1_ERROR_ISA13,
ERROR.TYPE_TA1,
ERROR_LEVEL.Batch,
batchIdMetadata);
Expand Down Expand Up @@ -236,7 +233,7 @@ private void readTransactionSets() throws Exception {
while (true) {
if (!"ST".equals(segmentReader.field(0))) {
throw new DebatcherException ("Missing ST segment",
EdiValidatorDefault.IK3_999_ERROR_MISS_SEG,
DefaultValidator.IK3_999_ERROR_MISS_SEG,
ERROR.TYPE_999,
ERROR_LEVEL.Batch,
batchIdMetadata);
Expand Down Expand Up @@ -360,9 +357,9 @@ private void readHierarchicalLevels() throws Exception {

if (segmentReader.isIeaFound()) {
// throw new DebatcherException("Missing CLM segment",
// EdiValidatorDefault.IK3_999_ERROR_MISS_SEG, ERROR.TYPE_999,
// DefaultValidator.IK3_999_ERROR_MISS_SEG, ERROR.TYPE_999,
// ERROR_LEVEL.Batch, batchIdMetadata, ERROR_OR_EXCEPTION.Exception);
ediValidator.logError(batchIdMetadata, EdiValidatorDefault.IK3_999_ERROR_MISS_SEG, ERROR.TYPE_999, "Missing CLM segment");
ediValidator.logError(batchIdMetadata, DefaultValidator.IK3_999_ERROR_MISS_SEG, ERROR.TYPE_999, "Missing CLM segment");
} else {
ediValidator.validate(batchIdMetadata, X12_ELEMENT.IEA01, null, null);
}
Expand Down Expand Up @@ -406,7 +403,7 @@ private void readClaim() throws Exception {
clm01 = segmentReader.field(1);
if (clm01 == null || clm01.isEmpty()) {
ediValidator.logError(batchIdMetadata,
EdiValidatorDefault.IK3_999_ERROR_MISS_DATA_ELEMENT, ERROR.TYPE_999,
DefaultValidator.IK3_999_ERROR_MISS_DATA_ELEMENT, ERROR.TYPE_999,
"Missing CLM01 value");
}
clm05 = segmentReader.field(5);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.null0.edi.debatcher;
import org.null0.edi.debatcher.interfaces.EdiValidator.ERROR;
package org.null0.x12.debatcher;
import org.null0.x12.debatcher.Validator.ERROR;

// TODO: This was migrated from something too complex; simplify
public class DebatcherException extends Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.null0.edi.debatcher;
package org.null0.x12.debatcher;

import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -12,7 +12,6 @@

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.null0.edi.debatcher.interfaces.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -22,7 +21,7 @@
*
*/
// TODO: define an interface for Config so that for unit testing we can use it instead without any file I/O dependencies
public class ConfigDefault implements Config {
public class DefaultConfig implements Config {
private static final String ENVAR_NAME = "edi_debatch_config_file"; // If this environment variable exists it must contain full valid path to properties file
private static final String FILE_NAME = "debatcher.properties"; // Default expected local properties file name if config_env_name environment variable does not exist
private static final Logger LOG = LoggerFactory.getLogger(Config.class); // Logger
Expand All @@ -37,7 +36,7 @@ public class ConfigDefault implements Config {
private String[] validSendersISA06;
private String[] validReceiversISA08;

public ConfigDefault() {
public DefaultConfig() {
if (!initFromEnvVar()) {
if (!initFromLocal()) {
initFromFailover();
Expand All @@ -51,7 +50,7 @@ public ConfigDefault() {
}
}

public ConfigDefault (String file) throws Exception {
public DefaultConfig (String file) throws Exception {
initFromFile(file);
setProperties();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.null0.edi.debatcher;
package org.null0.x12.debatcher;

import org.null0.edi.debatcher.interfaces.MetadataLogger;

// TODO from UCDetector: Class "MetadataLoggerDefault" is only called from tests
public class MetadataLoggerDefault implements MetadataLogger { // NO_UCD (test only)
// TODO from UCDetector: Class "DefaultMetadata" is only called from tests
public class DefaultMetadata implements Metadata { // NO_UCD (test only)

@Override
public long logBatchSubmissionData(String transactionId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.null0.edi.debatcher;
package org.null0.x12.debatcher;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.null0.edi.debatcher.interfaces.Config;
import org.null0.edi.debatcher.interfaces.EdiValidator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -20,12 +18,12 @@ then all the other code in this class could just be left here as a base (default

/* TODO: This class is a result of a serious lack of object-oriented design; smells horrible. */

public class EdiValidatorDefault implements EdiValidator {
private static final Logger logger = LoggerFactory.getLogger(EdiValidatorDefault.class);
public class DefaultValidator implements Validator {
private static final Logger logger = LoggerFactory.getLogger(DefaultValidator.class);
private Config config;
private List<String> isa13List = new ArrayList<String>();

public EdiValidatorDefault(Config config) {
public DefaultValidator(Config config) {
this.config = config;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.null0.edi.debatcher;
package org.null0.x12.debatcher;

class Delimiters {
private char dataElementSeparator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.null0.edi.debatcher;
package org.null0.x12.debatcher;

class HierarchicalLevel {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.null0.edi.debatcher.interfaces;
package org.null0.x12.debatcher;

// TODO: reverse-engineer metadata logger to decouple
public interface MetadataLogger {
public interface Metadata {

static enum METADATA_STATUS {Initial, InProcess, Accepted, Fail, Rejected, Analysis_Configuration, Analysis_Submission, Analysis_Internal};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.null0.edi.debatcher;
package org.null0.x12.debatcher;

import java.io.EOFException;
import java.io.InputStream;
import java.util.Arrays;

import org.null0.edi.debatcher.interfaces.Config;
import org.null0.edi.debatcher.DebatcherException.ERROR_LEVEL;
import org.null0.edi.debatcher.Delimiters.EdiWrapStyle;
import org.null0.edi.debatcher.interfaces.EdiValidator.ERROR;
import org.null0.x12.debatcher.DebatcherException.ERROR_LEVEL;
import org.null0.x12.debatcher.Delimiters.EdiWrapStyle;
import org.null0.x12.debatcher.Validator.ERROR;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -133,7 +132,7 @@ private void getDataChunk() throws Exception {
if (!"ISA".equals(data.substring(0, 3))) {
throw new DebatcherException(
"Not a valid Interchange Segment",
EdiValidatorDefault.TA1_ERROR_ISAIEA,
DefaultValidator.TA1_ERROR_ISAIEA,
ERROR.TYPE_TA1,
ERROR_LEVEL.Batch,
batchId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.null0.edi.debatcher.interfaces;
package org.null0.x12.debatcher;

import java.util.HashMap;
import java.util.Map;

// TODO: WTF? This thing imported itself before?
//import org.null0.edi.debatcher.validation.EncounterEdiValidator.ERROR;
//import org.null0.x12.debatcher.validation.EncounterEdiValidator.ERROR;

public interface EdiValidator {
public interface Validator {
static enum X12_ELEMENT {
ISA06, ISA07, ISA08, ISA11, ISA12, ISA13, ISA14, ISA15, ISA16, IEA01, IEA02, ISAEnd, DATA_SEPARATOR, GS, GS01, GS06, GS08, GE, GE01, ST01, ST02, ST03, SE, SE01
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package org.null0.edi.debatcher.test;
package org.null0.x12.debatcher.test;

import static org.junit.Assert.*;

import java.nio.file.Files;
import java.nio.file.Path;

import org.junit.Test;
import org.null0.edi.debatcher.ConfigDefault;
import org.null0.edi.debatcher.interfaces.Config;
import org.null0.x12.debatcher.Config;
import org.null0.x12.debatcher.DefaultConfig;

public class ConfigTest {


@Test
public void testLocalPropertiesFile() throws Exception {
Config config = testOutputDirectory();
Expand All @@ -20,7 +18,7 @@ public void testLocalPropertiesFile() throws Exception {
}

private Config testOutputDirectory() throws Exception {
Config config = new ConfigDefault();
Config config = new DefaultConfig();
Path path = config.getOutputDirectory();
assertTrue(Files.exists(path));
return config;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package org.null0.edi.debatcher.test;
package org.null0.x12.debatcher.test;

import java.io.InputStream;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.null0.x12.debatcher.Config;
import org.null0.x12.debatcher.DefaultConfig;
import org.null0.x12.debatcher.Debatcher;
import org.null0.x12.debatcher.DefaultValidator;
import org.null0.x12.debatcher.DefaultMetadata;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.null0.edi.debatcher.ConfigDefault;
import org.null0.edi.debatcher.Debatcher;
import org.null0.edi.debatcher.EdiValidatorDefault;
import org.null0.edi.debatcher.MetadataLoggerDefault;
import org.null0.edi.debatcher.interfaces.Config;

public class DebatcherTest {
private static final Logger logger = LoggerFactory.getLogger(DebatcherTest.class);
Expand All @@ -25,11 +26,16 @@ public static void setUpClass() {

@Before
public void setUp() throws Exception {
Config config = new ConfigDefault();
Config config = new DefaultConfig();
DebatcherTest.debatcher = new Debatcher(
config,
new EdiValidatorDefault(config),
new MetadataLoggerDefault());
new DefaultValidator(config),
new DefaultMetadata());
}

@After
public void tearDown() {
TestFileCleaner.clean(".edi.txt");
}

@Test(expected=NullPointerException.class)
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/org/null0/x12/debatcher/test/TestFileCleaner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.null0.x12.debatcher.test;

import java.io.File;

import org.null0.x12.debatcher.Config;
import org.null0.x12.debatcher.DefaultConfig;

public class TestFileCleaner {
public static synchronized boolean clean(String endsWith) {
try {
Config config = new DefaultConfig();
File dir = new File(config.getOutputDirectory().toString());
if (!dir.exists()) {
return false;
}

for (File f : dir.listFiles()) {
if (f.getName().endsWith(endsWith)) {
f.delete();
}
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.null0.edi.debatcher.test;
package org.null0.x12.debatcher.test;

import java.io.BufferedWriter;
import java.io.File;
Expand Down
Loading

0 comments on commit 4b298ed

Please sign in to comment.