prepare the usage of dynamic validation messages

This commit is contained in:
Andreas Billmann
2015-12-17 21:15:37 +01:00
parent a67f793670
commit 5121b998c5
6 changed files with 124 additions and 49 deletions

View File

@@ -34,9 +34,11 @@ import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static ninja.javafx.smartcsv.validation.ConfigMock.headerSectionConfig;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
@@ -52,7 +54,7 @@ public class HeaderValidationTest {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private Config config;
private Boolean expectedResult;
private List<String> expectedErrors;
private List<ValidationMessage> expectedErrors;
private String[] headerNames;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -67,7 +69,7 @@ public class HeaderValidationTest {
public HeaderValidationTest(String[] configHeaderNames,
String[] headerNames,
Boolean expectedResult,
List<String> expectedErrors) {
List<ValidationMessage> expectedErrors) {
this.config = headerSectionConfig(configHeaderNames);
this.headerNames = headerNames;
this.expectedResult = expectedResult;
@@ -106,9 +108,9 @@ public class HeaderValidationTest {
return asList(new Object[][] {
{ new String[] {}, new String[] {}, true, null },
{ new String[] {"a"}, new String[] {"a"}, true, null },
{ new String[] {"a"}, new String[] {"b"}, false, Arrays.asList("header number 0 does not match \"a\" should be \"b\"") },
{ new String[] {"a"}, new String[] {"a","b"}, false, Arrays.asList("number of headers is not correct! there are 2 but there should be 1") },
{ new String[] {"a", "b"}, new String[] {"b", "a"}, false, Arrays.asList("header number 0 does not match \"a\" should be \"b\"", "header number 1 does not match \"b\" should be \"a\"") }
{ new String[] {"a"}, new String[] {"b"}, false, singletonList(new ValidationMessage("header number 0 does not match \"a\" should be \"b\""))},
{ new String[] {"a"}, new String[] {"a","b"}, false, singletonList(new ValidationMessage("number of headers is not correct! there are 2 but there should be 1"))},
{ new String[] {"a", "b"}, new String[] {"b", "a"}, false, asList(new ValidationMessage("header number 0 does not match \"a\" should be \"b\""), new ValidationMessage("header number 1 does not match \"b\" should be \"a\"")) }
});
}
}

View File

@@ -27,7 +27,7 @@ public class ValidatorTest {
private String column;
private String value;
private Boolean expectedResult;
private String expectedError;
private ValidationMessage expectedError;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -45,7 +45,7 @@ public class ValidatorTest {
String column,
String value,
Boolean expectedResult,
String expectedError) {
ValidationMessage expectedError) {
this.config = columnSectionConfig(configcolumn, configValidation, configValue);
this.column = column;
this.value = value;
@@ -85,22 +85,22 @@ public class ValidatorTest {
public static Collection validationConfigurations() {
return asList(new Object[][] {
{ "column", "not empty", true, "column", "value", true, null },
{ "column", "not empty", true, "column", "", false, "validation.message.not.empty" },
{ "column", "not empty", true, "column", null, false, "validation.message.not.empty" },
{ "column", "not empty", true, "column", "", false, new ValidationMessage("validation.message.not.empty") },
{ "column", "not empty", true, "column", null, false, new ValidationMessage("validation.message.not.empty") },
{ "column", "integer", true, "column", "999", true, null },
{ "column", "integer", true, "column", "a", false, "validation.message.integer" },
{ "column", "integer", true, "column", "a", false, new ValidationMessage("validation.message.integer") },
{ "column", "minlength", 2, "column", "12", true, null },
{ "column", "minlength", 2, "column", "1", false, "has not min length of 2" },
{ "column", "minlength", 2, "column", "1", false, new ValidationMessage("has not min length of 2") },
{ "column", "maxlength", 2, "column", "12", true, null },
{ "column", "maxlength", 2, "column", "123", false, "has not max length of 2" },
{ "column", "maxlength", 2, "column", "123", false, new ValidationMessage("has not max length of 2") },
{ "column", "date", "yyyyMMdd", "column", "20151127", true, null },
{ "column", "date", "yyyyMMdd", "column", "27.11.2015", false, "is not a date of format yyyyMMdd" },
{ "column", "date", "yyyyMMdd", "column", "27.11.2015", false, new ValidationMessage("is not a date of format yyyyMMdd") },
{ "column", "alphanumeric", true, "column", "abcABC123", true, null },
{ "column", "alphanumeric", true, "column", "-abcABC123", false, "validation.message.alphanumeric" },
{ "column", "alphanumeric", true, "column", "-abcABC123", false, new ValidationMessage("validation.message.alphanumeric") },
{ "column", "regexp", "[a-z]*", "column", "abc", true, null },
{ "column", "regexp", "[a-z]*", "column", "abcA", false, "does not match [a-z]*" },
{ "column", "regexp", "[a-z]*", "column", "abcA", false, new ValidationMessage("does not match [a-z]*") },
{ "column", "groovy", "value.contains('a')? 'true' : 'no a inside'", "column", "abcdef", true, null },
{ "column", "groovy", "value.contains('a')? 'true' : 'no a inside'", "column", "bcdefg", false, "no a inside" },
{ "column", "groovy", "value.contains('a')? 'true' : 'no a inside'", "column", "bcdefg", false, new ValidationMessage("no a inside") },
});
}