use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent in project bender by Nextdoor.
the class RegexSubstitutionTest method testRegexMultipleSourcesNonMatch.
@Test
public void testRegexMultipleSourcesNonMatch() throws FieldNotFoundException {
List<RegexSubField> regexSubFields = Arrays.asList(new RegexSubField("q", RegexSubField.RegexSubFieldType.STRING, "q"));
String pattern = "(?<q>(\\d+))";
ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
substitutions.add(new RegexSubstitution(Arrays.asList("foo", "foo1"), Pattern.compile(pattern), regexSubFields, false, true, true));
DummpyMapEvent devent = new DummpyMapEvent();
devent.setField("foo", "aaa");
devent.setField("foo1", "123");
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
SubstitutionOperation op = new SubstitutionOperation(substitutions);
op.perform(ievent);
assertEquals(3, devent.payload.size());
assertEquals("123", devent.getField("q"));
}
use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent in project bender by Nextdoor.
the class RegexSubstitutionTest method testBasicRegex.
@Test
public void testBasicRegex() throws FieldNotFoundException {
List<RegexSubField> regexSubFields = Arrays.asList(new RegexSubField("protocol", RegexSubField.RegexSubFieldType.STRING, "http_protocol"), new RegexSubField("host", RegexSubField.RegexSubFieldType.STRING, "http_host"), new RegexSubField("port", RegexSubField.RegexSubFieldType.NUMBER, "http_port"), new RegexSubField("path", RegexSubField.RegexSubFieldType.STRING, "http_path"), new RegexSubField("page", RegexSubField.RegexSubFieldType.STRING, "http_page"), new RegexSubField("args", RegexSubField.RegexSubFieldType.STRING, "http_args"));
String pattern = "(?:(?<protocol>http[s]):\\/\\/)?" + "(?<host>((?:www.)?(?:[^\\W\\s]|\\.|-)+[\\.][^\\W\\s]{2,4}|localhost(?=\\/)|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}))" + "(?::(?<port>\\d*))?" + "(?<path>([\\/]?[^\\s\\?]*[\\/]{1})*)" + "(?<page>(?:\\/?([^\\s\\n\\?\\[\\]\\{\\}\\#]*(?:(?=\\.)){1}|[^\\s\\n\\?\\[\\]\\{\\}\\.\\#]*)?)([\\.]{1}[^\\s\\?\\#]*)?)?" + "(?<args>(?:\\?{1}([^\\s\\n\\#\\[\\]]*))?)";
ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
substitutions.add(new RegexSubstitution(Arrays.asList("url"), Pattern.compile(pattern), regexSubFields, false, true, true));
DummpyMapEvent devent = new DummpyMapEvent();
devent.setField("url", "https://www.example.com:443/p1/p2/index.html?q=abc");
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
SubstitutionOperation op = new SubstitutionOperation(substitutions);
op.perform(ievent);
assertEquals("https://www.example.com:443/p1/p2/index.html?q=abc", devent.getField("url"));
assertEquals("https", devent.getField("http_protocol"));
assertEquals("www.example.com", devent.getField("http_host"));
assertEquals(443, devent.getField("http_port"));
assertEquals("/p1/p2/", devent.getField("http_path"));
assertEquals("index.html", devent.getField("http_page"));
assertEquals("?q=abc", devent.getField("http_args"));
}
use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent in project bender by Nextdoor.
the class RegexSubstitutionTest method testRegexMultipleSources.
@Test
public void testRegexMultipleSources() throws FieldNotFoundException {
List<RegexSubField> regexSubFields = Arrays.asList(new RegexSubField("q", RegexSubField.RegexSubFieldType.STRING, "q"));
String pattern = "(?<q>(expectedstring))";
ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
substitutions.add(new RegexSubstitution(Arrays.asList("foo", "foo1", "foo2"), Pattern.compile(pattern), regexSubFields, false, true, true));
DummpyMapEvent devent = new DummpyMapEvent();
devent.setField("foo2", "expectedstring");
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
SubstitutionOperation op = new SubstitutionOperation(substitutions);
op.perform(ievent);
assertEquals(2, devent.payload.size());
assertEquals("expectedstring", devent.getField("foo2"));
assertEquals("expectedstring", devent.getField("q"));
}
use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent in project bender by Nextdoor.
the class RegexSubstitutionTest method testRegexFieldCoercionNoFail.
@Test
public void testRegexFieldCoercionNoFail() throws FieldNotFoundException {
List<RegexSubField> regexSubFields = Arrays.asList(new RegexSubField("q", RegexSubField.RegexSubFieldType.NUMBER, "q"));
String pattern = "(?<q>(expectedstring))";
ArrayList<Substitution> substitutions = new ArrayList<Substitution>();
substitutions.add(new RegexSubstitution(Arrays.asList("foo"), Pattern.compile(pattern), regexSubFields, false, false, true));
DummpyMapEvent devent = new DummpyMapEvent();
devent.setField("foo", "expectedstring");
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
SubstitutionOperation op = new SubstitutionOperation(substitutions);
op.perform(ievent);
assertEquals(1, devent.payload.size());
assertEquals("expectedstring", devent.getField("foo"));
}
use of com.nextdoor.bender.testutils.DummyDeserializerHelper.DummpyMapEvent in project bender by Nextdoor.
the class GeoIpOperationTest method testInvalidIp.
@Test
public void testInvalidIp() throws Throwable {
GeoIpOperation op = setup(Arrays.asList(GeoProperty.LOCATION), false);
DummpyMapEvent devent = new DummpyMapEvent();
devent.setField("ip_address", "noanip");
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
op.perform(ievent);
}
Aggregations