Esempio n. 1
0
  @Test
  public void null_selector() {
    UrlFilter filter = new UrlFilter();

    RequestPathInfo testInfo = mock(RequestPathInfo.class);
    when(testInfo.getSelectorString()).thenReturn(null);

    assertTrue(filter.checkSelector(testInfo, null));
  }
Esempio n. 2
0
  @Test
  public void non_null_selector() {
    UrlFilter filter = new UrlFilter();

    RequestPathInfo testInfo = mock(RequestPathInfo.class);
    when(testInfo.getSelectorString()).thenReturn("sample");

    // null allowedSelectors = ok
    assertTrue(filter.checkSelector(testInfo, properties));

    // empty array allowedSelectors = fail
    properties.put(UrlFilter.PN_ALLOWED_SELECTORS, (Object) new String[0]);
    assertFalse(filter.checkSelector(testInfo, properties));

    // selector string in array = ok
    properties.put(UrlFilter.PN_ALLOWED_SELECTORS, (Object) new String[] {"sample", "sample2"});
    assertTrue(filter.checkSelector(testInfo, properties));

    // selector string not in array = fail
    properties.put(UrlFilter.PN_ALLOWED_SELECTORS, (Object) new String[] {"other"});
    assertFalse(filter.checkSelector(testInfo, properties));

    properties.clear();

    // matches regex
    properties.put(UrlFilter.PN_ALLOWED_SELECTOR_PATTERN, "^s[a-z]m.*$");
    assertTrue(filter.checkSelector(testInfo, properties));

    // doesn't match regex
    properties.put(UrlFilter.PN_ALLOWED_SELECTOR_PATTERN, "^s[1-2]m$");
    assertFalse(filter.checkSelector(testInfo, properties));

    properties.clear();

    // matches array or regex = ok
    properties.put(UrlFilter.PN_ALLOWED_SELECTORS, (Object) new String[] {"other"});
    properties.put(UrlFilter.PN_ALLOWED_SELECTOR_PATTERN, "^s[a-z]m.*$");
    assertTrue(filter.checkSelector(testInfo, properties));

    properties.put(UrlFilter.PN_ALLOWED_SELECTORS, (Object) new String[] {"sample"});
    properties.put(UrlFilter.PN_ALLOWED_SELECTOR_PATTERN, "^s[a-z]m$");
    assertTrue(filter.checkSelector(testInfo, properties));
  }