Skip to content

Commit

Permalink
fix java class name validation (#1084)
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Avdeev <[email protected]>
  • Loading branch information
oavdeev authored Oct 22, 2020
1 parent eee9a9a commit 6b07a4a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/java/feast/core/validators/Matchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Matchers {
private static Pattern BIGQUERY_TABLE_REF_REGEX =
Pattern.compile("[a-zA-Z0-9-]+[:]+[a-zA-Z0-9_]+[.]+[a-zA-Z0-9_]*");
private static Pattern CLASS_PATH_REGEX =
Pattern.compile("[a-zA-Z_$][a-zA-Z0-9_$]*(\\.[a-zA-Z_$][a-zA-Z0-9_$]*)");
Pattern.compile("[a-zA-Z_][a-zA-Z0-9_]*(\\.[a-zA-Z_][a-zA-Z0-9_]*)*$");
private static Pattern UPPER_SNAKE_CASE_REGEX = Pattern.compile("^[A-Z0-9]+(_[A-Z0-9]+)*$");
private static Pattern LOWER_SNAKE_CASE_REGEX = Pattern.compile("^[a-z0-9]+(_[a-z0-9]+)*$");
private static Pattern VALID_CHARACTERS_REGEX = Pattern.compile("^[a-zA-Z_][a-zA-Z0-9_]*$");
Expand Down
19 changes: 19 additions & 0 deletions core/src/test/java/feast/core/validators/MatchersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static feast.core.validators.Matchers.checkLowerSnakeCase;
import static feast.core.validators.Matchers.checkUpperSnakeCase;
import static feast.core.validators.Matchers.checkValidClassPath;

import com.google.common.base.Strings;
import org.junit.Rule;
Expand Down Expand Up @@ -70,4 +71,22 @@ public void checkLowerSnakeCaseShouldThrowIllegalArgumentExceptionWithFieldForIn
String in = "Invalid_feature name";
checkLowerSnakeCase(in, "feature");
}

@Test
public void checkValidClassPathSuccess() {
checkValidClassPath("com.example.foo", "FeatureTable");
checkValidClassPath("com.example", "FeatureTable");
}

@Test
public void checkValidClassPathEmpty() {
exception.expect(IllegalArgumentException.class);
checkValidClassPath("", "FeatureTable");
}

@Test
public void checkValidClassPathDigits() {
exception.expect(IllegalArgumentException.class);
checkValidClassPath("123", "FeatureTable");
}
}

0 comments on commit 6b07a4a

Please sign in to comment.