Search in sources :

Example 1 with ZpeMatchAll

use of com.yahoo.athenz.zpe.match.impl.ZpeMatchAll 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;
}
Also used : ZpeMatchRegex(com.yahoo.athenz.zpe.match.impl.ZpeMatchRegex) ZpeMatchStartsWith(com.yahoo.athenz.zpe.match.impl.ZpeMatchStartsWith) ZpeMatchEqual(com.yahoo.athenz.zpe.match.impl.ZpeMatchEqual) ZpeMatch(com.yahoo.athenz.zpe.match.ZpeMatch) ZpeMatchAll(com.yahoo.athenz.zpe.match.impl.ZpeMatchAll)

Example 2 with ZpeMatchAll

use of com.yahoo.athenz.zpe.match.impl.ZpeMatchAll in project athenz by yahoo.

the class TestZpeMatch method testGetMatchAll.

@Test
public void testGetMatchAll() {
    try (ZpeUpdPolLoader loader = new ZpeUpdPolLoader(null)) {
        ZpeMatch matchObject = loader.getMatchObject("*");
        assertTrue(matchObject instanceof ZpeMatchAll);
        assertTrue(matchObject.matches("abc"));
        assertTrue(matchObject.matches("false"));
        assertTrue(matchObject.matches("whatever"));
    }
}
Also used : ZpeUpdPolLoader(com.yahoo.athenz.zpe.ZpeUpdPolLoader) ZpeMatch(com.yahoo.athenz.zpe.match.ZpeMatch) ZpeMatchAll(com.yahoo.athenz.zpe.match.impl.ZpeMatchAll) Test(org.testng.annotations.Test)

Example 3 with ZpeMatchAll

use of com.yahoo.athenz.zpe.match.impl.ZpeMatchAll 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);
    }
}
Also used : ZpeMatchRegex(com.yahoo.athenz.zpe.match.impl.ZpeMatchRegex) ZpeMatchStartsWith(com.yahoo.athenz.zpe.match.impl.ZpeMatchStartsWith) ZpeMatchEqual(com.yahoo.athenz.zpe.match.impl.ZpeMatchEqual) ZpeMatch(com.yahoo.athenz.zpe.match.ZpeMatch) ZpeMatchAll(com.yahoo.athenz.zpe.match.impl.ZpeMatchAll) Test(org.testng.annotations.Test)

Aggregations

ZpeMatch (com.yahoo.athenz.zpe.match.ZpeMatch)3 ZpeMatchAll (com.yahoo.athenz.zpe.match.impl.ZpeMatchAll)3 ZpeMatchEqual (com.yahoo.athenz.zpe.match.impl.ZpeMatchEqual)2 ZpeMatchRegex (com.yahoo.athenz.zpe.match.impl.ZpeMatchRegex)2 ZpeMatchStartsWith (com.yahoo.athenz.zpe.match.impl.ZpeMatchStartsWith)2 Test (org.testng.annotations.Test)2 ZpeUpdPolLoader (com.yahoo.athenz.zpe.ZpeUpdPolLoader)1