use of com.yahoo.athenz.zpe.match.impl.ZpeMatchRegex in project athenz by yahoo.
the class ZpeUpdPolLoader method getMatchObject.
ZpeMatch getMatchObject(String value) {
ZpeMatch match = null;
if ("*".equals(value)) {
match = new ZpeMatchAll();
} else {
int anyCharMatch = value.indexOf('*');
int singleCharMatch = value.indexOf('?');
if (anyCharMatch == -1 && singleCharMatch == -1) {
match = new ZpeMatchEqual(value);
} else if (anyCharMatch == value.length() - 1 && singleCharMatch == -1) {
match = new ZpeMatchStartsWith(value.substring(0, value.length() - 1));
} else {
match = new ZpeMatchRegex(value);
}
}
return match;
}
use of com.yahoo.athenz.zpe.match.impl.ZpeMatchRegex in project athenz by yahoo.
the class TestZpeMatch method testGetMatchRegex.
@Test
public void testGetMatchRegex() {
try (ZpeUpdPolLoader loader = new ZpeUpdPolLoader(null)) {
ZpeMatch matchObject = loader.getMatchObject("coretech?test*");
assertTrue(matchObject instanceof ZpeMatchRegex);
assertTrue(matchObject.matches("coretechAtest"));
assertTrue(matchObject.matches("coretechbtestgreat"));
// failures
// random data
assertFalse(matchObject.matches("whatever"));
// missing ?
assertFalse(matchObject.matches("coretechtestgreat"));
}
}
use of com.yahoo.athenz.zpe.match.impl.ZpeMatchRegex in project athenz by yahoo.
the class TestZpeUpdPolLoader method testGetMatchObject.
@Test
public void testGetMatchObject() {
try (ZpeUpdPolLoader loader = new ZpeUpdPolLoader(null)) {
ZpeMatch matchObject = loader.getMatchObject("*");
assertTrue(matchObject instanceof ZpeMatchAll);
matchObject = loader.getMatchObject("**");
assertTrue(matchObject instanceof ZpeMatchRegex);
matchObject = loader.getMatchObject("?*");
assertTrue(matchObject instanceof ZpeMatchRegex);
matchObject = loader.getMatchObject("?");
assertTrue(matchObject instanceof ZpeMatchRegex);
matchObject = loader.getMatchObject("test?again*");
assertTrue(matchObject instanceof ZpeMatchRegex);
matchObject = loader.getMatchObject("*test");
assertTrue(matchObject instanceof ZpeMatchRegex);
matchObject = loader.getMatchObject("test");
assertTrue(matchObject instanceof ZpeMatchEqual);
matchObject = loader.getMatchObject("(test|again)");
assertTrue(matchObject instanceof ZpeMatchEqual);
matchObject = loader.getMatchObject("test*");
assertTrue(matchObject instanceof ZpeMatchStartsWith);
}
}
Aggregations