Skip to content

Commit f024837

Browse files
committed
More test coverage (#117)
1 parent 579c6de commit f024837

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

lib/src/main/java/com/imsweb/staging/engine/DecisionEngine.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,6 @@ public Result process(Schema schema, Map<String, String> context) {
621621

622622
// if value not supplied, use the default or defaultTable and set it back into the context; if not supplied and no default, set the input the blank
623623
if (value == null) {
624-
value = "";
625624
if (input.getDefault() != null)
626625
value = translateValue(input.getDefault(), context);
627626
else if (input.getDefaultTable() != null) {
@@ -652,7 +651,7 @@ else if (input.getDefaultTable() != null) {
652651

653652
}
654653

655-
context.put(input.getKey(), value);
654+
context.put(input.getKey(), value == null ? "" : value);
656655
}
657656

658657
// validate value against associated table, if supplied; if a value is not supplied, or blank, there is no need to validate it against the table

lib/src/test/java/com/imsweb/staging/engine/DecisionEngineTest.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1573,9 +1573,10 @@ void testDefaultTable() {
15731573
table.addColumnDefinition("input2", ColumnType.INPUT);
15741574
table.addColumnDefinition("output1", ColumnType.ENDPOINT);
15751575
table.addRawRow("000", "900", "VALUE:000-900");
1576+
table.addRawRow("000", "*", "VALUE:000-*");
15761577
table.addRawRow("001", "901", "VALUE:001-901");
1578+
table.addRawRow("001", "*", "VALUE:001-*");
15771579
table.addRawRow("002", "902", "VALUE:001-901");
1578-
table.addRawRow("*", "*", "VALUE:Other");
15791580
provider.addTable(table);
15801581

15811582
StagingSchema schema = new StagingSchema("test_default_table");
@@ -1594,6 +1595,7 @@ void testDefaultTable() {
15941595

15951596
DecisionEngine engine = new DecisionEngine(provider);
15961597

1598+
// test a case where the default_table make a successful lookup
15971599
Map<String, String> context = new HashMap<>();
15981600
context.put("input1", "000");
15991601
Result result = engine.process("test_default_table", context);
@@ -1602,6 +1604,37 @@ void testDefaultTable() {
16021604
assertFalse(result.hasErrors());
16031605
assertEquals(1, result.getContext().size());
16041606
assertEquals("000-900", result.getContext().get("output1"));
1607+
1608+
// test a case where there was a fallthrough match in the default table
1609+
context = new HashMap<>();
1610+
context.put("input1", "002");
1611+
result = engine.process("test_default_table", context);
1612+
1613+
assertEquals(Type.STAGED, result.getType());
1614+
assertFalse(result.hasErrors());
1615+
assertEquals(1, result.getContext().size());
1616+
1617+
// test a case where the default_table did not exist
1618+
schema.getInputs().stream().filter(i -> i.getDefaultTable() != null).forEach(i -> i.setDefaultTable("does_not_exist"));
1619+
context = new HashMap<>();
1620+
context.put("input1", "000");
1621+
result = engine.process("test_default_table", context);
1622+
assertEquals(Type.STAGED, result.getType());
1623+
assertEquals(1, result.getErrors().size());
1624+
assertEquals("input2", result.getErrors().get(0).getKey());
1625+
assertEquals("Default table does not exist: does_not_exist", result.getErrors().get(0).getMessage());
1626+
1627+
// test a case where the default table did not find a match
1628+
schema.getInputs().stream().filter(i -> i.getDefaultTable() != null).forEach(i -> i.setDefaultTable("table_input2_default"));
1629+
provider.getTable("table_input2_default").setRawRows(new ArrayList<>());
1630+
provider.initTable(provider.getTable("table_input2_default"));
1631+
context = new HashMap<>();
1632+
context.put("input1", "001");
1633+
result = engine.process("test_default_table", context);
1634+
assertEquals(Type.STAGED, result.getType());
1635+
assertEquals(1, result.getErrors().size());
1636+
assertEquals("input2", result.getErrors().get(0).getKey());
1637+
assertEquals("Default table table_input2_default did not find a match", result.getErrors().get(0).getMessage());
16051638
}
16061639

16071640
}

0 commit comments

Comments
 (0)