Skip to content
Snippets Groups Projects
Commit 1debd407 authored by felmer's avatar felmer
Browse files

SE-178 improve error messages in column header validation

SVN: 13981
parent 2ebeec7a
No related branches found
No related tags found
No related merge requests found
......@@ -224,7 +224,8 @@ class DataSetValidatorForTSV implements IDataSetValidator
{
if (definitions[i] == null)
{
definitions[i] = getDefinition(remainingDefinitions, columnHeaders, i);
ColumnDefinition orderedColumDefinitionOrNull = orderedDefinitions.get(i + 1);
definitions[i] = getDefinition(remainingDefinitions, orderedColumDefinitionOrNull, columnHeaders, i);
}
}
String list = createListOfMissingColumns(remainingDefinitions);
......@@ -290,7 +291,7 @@ class DataSetValidatorForTSV implements IDataSetValidator
}
private ColumnDefinition getDefinition(List<ColumnDefinition> definitions,
List<String> columnHeaders, int i)
ColumnDefinition orderedColumDefinitionOrNull, List<String> columnHeaders, int i)
{
String columnHeader = columnHeaders.get(i);
StringBuilder builder = new StringBuilder();
......@@ -307,12 +308,25 @@ class DataSetValidatorForTSV implements IDataSetValidator
return columnDefinition;
} else
{
builder.append("\nColumn Definition '").append(columnDefinition.getName());
builder.append("' does not match: Reason: ").append(result);
addMessage(builder, columnDefinition, result);
}
}
if (orderedColumDefinitionOrNull != null)
{
Result result = orderedColumDefinitionOrNull.validateHeader(columnHeader);
if (result.isValid() == false)
{
addMessage(builder, orderedColumDefinitionOrNull, result);
}
}
throw new UserFailureException("No column definition matches the header of the " + (i + 1)
+ ". column: " + columnHeader + builder);
}
private void addMessage(StringBuilder builder, ColumnDefinition columnDefinition, Result result)
{
builder.append("\nColumn Definition '").append(columnDefinition.getName());
builder.append("' does not match: Reason: ").append(result);
}
}
......@@ -203,6 +203,45 @@ public class DataSetValidatorForTSVTest extends AbstractFileSystemTestCase
MockValidatorFactory.assertSatisfied();
}
@Test
public void testNoColumnDefinitionFound2()
{
Properties properties = new Properties();
properties.setProperty(DataSetValidatorForTSV.PATH_PATTERNS_KEY, "*");
properties.setProperty(DataSetValidatorForTSV.COLUMNS_KEY, "id, a, b, c");
properties.setProperty("id." + ColumnDefinition.HEADER_PATTERN_KEY, "ID");
properties.setProperty("id." + ColumnDefinition.MANDATORY_KEY, "true");
properties.setProperty("id." + ColumnDefinition.ORDER_KEY, "1");
properties.setProperty("id." + ColumnDefinition.VALUE_VALIDATOR_KEY, MOCK_FACTORY);
properties.setProperty("a." + ColumnDefinition.HEADER_PATTERN_KEY, "A");
properties.setProperty("a." + ColumnDefinition.ORDER_KEY, "2");
properties.setProperty("a." + ColumnDefinition.VALUE_VALIDATOR_KEY, MOCK_FACTORY);
properties.setProperty("b." + ColumnDefinition.HEADER_PATTERN_KEY, "B");
properties.setProperty("b." + ColumnDefinition.ORDER_KEY, "3");
properties.setProperty("b." + ColumnDefinition.VALUE_VALIDATOR_KEY, MOCK_FACTORY);
properties.setProperty("c." + ColumnDefinition.HEADER_PATTERN_KEY, "C[0-9]*");
properties.setProperty("c." + ColumnDefinition.CAN_DEFINE_MULTIPLE_COLUMNS_KEY, "true");
properties.setProperty("c." + ColumnDefinition.VALUE_VALIDATOR_KEY, MOCK_FACTORY);
DataSetValidatorForTSV validator = new DataSetValidatorForTSV(properties);
FileUtilities.writeToFile(new File(workingDirectory, "a.txt"), "ID\ta\tC1\n");
try
{
validator.assertValidDataSet(null, workingDirectory);
fail("UserFailureException expected");
} catch (UserFailureException ex)
{
assertEquals("No column definition matches the header of the 2. column: a\n"
+ "Column Definition 'c' does not match: Reason: "
+ "Does not match the following regular expression: C[0-9]*\n"
+ "Column Definition 'a' does not match: Reason: "
+ "Does not match the following regular expression: A", ex.getMessage());
}
MockValidatorFactory.assertSatisfied();
}
@Test
public void testMissingMandatoryColumn()
{
......@@ -443,7 +482,9 @@ public class DataSetValidatorForTSVTest extends AbstractFileSystemTestCase
fail("UserFailureException expected");
} catch (UserFailureException ex)
{
assertEquals("No column definition matches the header of the 1. column: ID", ex.getMessage());
assertEquals("No column definition matches the header of the 1. column: ID\n"
+ "Column Definition 'c1' does not match: Reason: "
+ "Does not match the following regular expression: Name", ex.getMessage());
}
MockValidatorFactory.assertSatisfied();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment