Search in sources :

Example 1 with Settings

use of io.hops.hopsworks.common.util.Settings in project hopsworks by logicalclocks.

the class FolderNameValidatorTest method testProjectNameRegexForUnderscoreFeaturestore.

@Test
public void testProjectNameRegexForUnderscoreFeaturestore() {
    Settings settings = new Settings();
    StringTokenizer tokenizer = new StringTokenizer(settings.getProjectNameReservedWordsTest(), ",");
    HashSet<String> tokens = new HashSet<>(tokenizer.countTokens());
    while (tokenizer.hasMoreTokens()) {
        tokens.add(tokenizer.nextToken().trim());
    }
    Pattern projectNameRegexValidator = Pattern.compile(FolderNameValidator.getProjectNameRegexStr(tokens), Pattern.CASE_INSENSITIVE);
    Matcher m = projectNameRegexValidator.matcher("a_FeaturestoreFoo");
    boolean isValid = m.find();
    Assert.assertFalse(isValid);
    m = projectNameRegexValidator.matcher("a_FEATURESTORE");
    isValid = m.find();
    Assert.assertFalse(isValid);
    m = projectNameRegexValidator.matcher("a_featurestore");
    isValid = m.find();
    Assert.assertFalse(isValid);
    m = projectNameRegexValidator.matcher("featurestore_a");
    isValid = m.find();
    Assert.assertTrue(isValid);
}
Also used : Pattern(java.util.regex.Pattern) StringTokenizer(java.util.StringTokenizer) Matcher(java.util.regex.Matcher) Settings(io.hops.hopsworks.common.util.Settings) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with Settings

use of io.hops.hopsworks.common.util.Settings in project hopsworks by logicalclocks.

the class FolderNameValidatorTest method testProjectNameRegex.

@Test
public void testProjectNameRegex() {
    Settings settings = new Settings();
    StringTokenizer tokenizer = new StringTokenizer(settings.getProjectNameReservedWordsTest(), ",");
    HashSet<String> tokens = new HashSet<>(tokenizer.countTokens());
    while (tokenizer.hasMoreTokens()) {
        tokens.add(tokenizer.nextToken().trim());
    }
    Pattern projectNameRegexValidator = Pattern.compile(FolderNameValidator.getProjectNameRegexStr(tokens), Pattern.CASE_INSENSITIVE);
    Matcher m = projectNameRegexValidator.matcher("VIEWS");
    boolean isValid = m.find();
    Assert.assertFalse(isValid);
    m = projectNameRegexValidator.matcher("views");
    isValid = m.find();
    Assert.assertFalse(isValid);
    m = projectNameRegexValidator.matcher("viewss");
    isValid = m.find();
    Assert.assertTrue(isValid);
}
Also used : Pattern(java.util.regex.Pattern) StringTokenizer(java.util.StringTokenizer) Matcher(java.util.regex.Matcher) Settings(io.hops.hopsworks.common.util.Settings) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Settings (io.hops.hopsworks.common.util.Settings)2 HashSet (java.util.HashSet)2 StringTokenizer (java.util.StringTokenizer)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Test (org.junit.Test)2