Search in sources :

Example 16 with EventPayload

use of io.divolte.server.ServerTestUtils.EventPayload in project divolte-collector by divolte.

the class DslRecordMapperTest method shouldSupportPresenceTestingOfJsonPathExpressions.

@Test
public void shouldSupportPresenceTestingOfJsonPathExpressions() throws IOException, InterruptedException {
    setupServer("event-param-jsonpath-presence.groovy");
    final EventPayload event = request("http://www.example.com/", Collections.singletonList(HOMOGENOUS_EVENT_PARAMS));
    assertTrue((Boolean) event.record.get("flag1"));
    assertFalse((Boolean) event.record.get("flag2"));
}
Also used : EventPayload(io.divolte.server.ServerTestUtils.EventPayload) Test(org.junit.Test)

Example 17 with EventPayload

use of io.divolte.server.ServerTestUtils.EventPayload in project divolte-collector by divolte.

the class DslRecordMapperTest method shouldNotFailOnBrokenQueryString.

@Test
public void shouldNotFailOnBrokenQueryString() throws IOException, InterruptedException {
    setupServer("funky-querystring-mapping.groovy");
    final EventPayload event = request("http://example.com/path/?a=value&=42&b=&d=word&c&=bla");
    /*
         * Query string parsing semantics:
         * ?q=          =>   q == ""
         * ?q=foo       =>   q == "foo"
         * ?q&a=bar     =>   q == "" && a == "bar"
         * ?=42&q=foo   =>   q == "foo"
         */
    assertEquals("value", event.record.get("uriQueryStringValue"));
    assertEquals("", event.record.get("queryparam"));
    assertEquals("", event.record.get("client"));
    assertEquals("word", event.record.get("pageview"));
}
Also used : EventPayload(io.divolte.server.ServerTestUtils.EventPayload) Test(org.junit.Test)

Example 18 with EventPayload

use of io.divolte.server.ServerTestUtils.EventPayload in project divolte-collector by divolte.

the class DslRecordMapperTest method shouldPopulateFlatFields.

@Test
public void shouldPopulateFlatFields() throws InterruptedException, IOException {
    setupServer("flat-mapping.groovy");
    final EventPayload payload = request("https://example.com/", "http://example.com/");
    final GenericRecord record = payload.record;
    final DivolteEvent event = payload.event;
    assertEquals(true, record.get("sessionStart"));
    assertEquals(true, record.get("unreliable"));
    assertEquals(false, record.get("dupe"));
    assertEquals(event.requestStartTime.toEpochMilli(), record.get("ts"));
    assertEquals("https://example.com/", record.get("location"));
    assertEquals("http://example.com/", record.get("referer"));
    assertEquals(USER_AGENT, record.get("userAgentString"));
    assertEquals("Chrome", record.get("userAgentName"));
    assertEquals("Chrome", record.get("userAgentFamily"));
    assertEquals("Google Inc.", record.get("userAgentVendor"));
    assertEquals("Browser", record.get("userAgentType"));
    assertEquals("38.0.2125.122", record.get("userAgentVersion"));
    assertEquals("Personal computer", record.get("userAgentDeviceCategory"));
    assertEquals("OS X", record.get("userAgentOsFamily"));
    assertEquals("10.10.1", record.get("userAgentOsVersion"));
    assertEquals("Apple Computer, Inc.", record.get("userAgentOsVendor"));
    assertEquals(event.partyId.value, record.get("client"));
    assertEquals(event.sessionId.value, record.get("session"));
    assertEquals(event.browserEventData.map(bed -> bed.pageViewId), Optional.of(record.get("pageview")));
    assertEquals(event.eventId, record.get("event"));
    assertEquals(1018, record.get("viewportWidth"));
    assertEquals(1018, record.get("viewportHeight"));
    assertEquals(1024, record.get("screenWidth"));
    assertEquals(1024, record.get("screenHeight"));
    assertEquals(2, record.get("pixelRatio"));
    assertEquals("pageView", record.get("eventType"));
    Stream.of("sessionStart", "unreliable", "dupe", "ts", "location", "referer", "userAgentString", "userAgentName", "userAgentFamily", "userAgentVendor", "userAgentType", "userAgentVersion", "userAgentDeviceCategory", "userAgentOsFamily", "userAgentOsVersion", "userAgentOsVendor", "client", "session", "pageview", "event", "viewportWidth", "viewportHeight", "screenWidth", "screenHeight", "pixelRatio", "eventType").forEach((v) -> assertNotNull(record.get(v)));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Arrays(java.util.Arrays) InjectableValues(com.fasterxml.jackson.databind.InjectableValues) ClosedServiceException(io.divolte.server.ip2geo.LookupService.ClosedServiceException) URL(java.net.URL) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) EventPayload(io.divolte.server.ServerTestUtils.EventPayload) GenericData(org.apache.avro.generic.GenericData) ImmutableList(com.google.common.collect.ImmutableList) ValidatedConfiguration(io.divolte.server.config.ValidatedConfiguration) Map(java.util.Map) After(org.junit.After) ConfigFactory(com.typesafe.config.ConfigFactory) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Utf8(org.apache.avro.util.Utf8) GenericRecord(org.apache.avro.generic.GenericRecord) Schema(org.apache.avro.Schema) JsonParser(com.fasterxml.jackson.core.JsonParser) Files(java.nio.file.Files) Config(com.typesafe.config.Config) ImmutableMap(com.google.common.collect.ImmutableMap) Resources(com.google.common.io.Resources) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) SchemaMappingException(io.divolte.server.recordmapping.SchemaMappingException) StandardCharsets(java.nio.charset.StandardCharsets) TestServer(io.divolte.server.ServerTestUtils.TestServer) Mockito(org.mockito.Mockito) URLEncoder(java.net.URLEncoder) List(java.util.List) Stream(java.util.stream.Stream) java.io(java.io) LookupService(io.divolte.server.ip2geo.LookupService) CityResponse(com.maxmind.geoip2.model.CityResponse) Optional(java.util.Optional) DslRecordMapper(io.divolte.server.recordmapping.DslRecordMapper) Assert(org.junit.Assert) Collections(java.util.Collections) GenericRecord(org.apache.avro.generic.GenericRecord) EventPayload(io.divolte.server.ServerTestUtils.EventPayload) Test(org.junit.Test)

Example 19 with EventPayload

use of io.divolte.server.ServerTestUtils.EventPayload in project divolte-collector by divolte.

the class DslRecordMapperTest method shouldMatchRegexAndExtractGroups.

@Test
public void shouldMatchRegexAndExtractGroups() throws IOException, InterruptedException {
    setupServer("regex-mapping.groovy");
    final EventPayload event = request("http://www.example.com/path/with/42/about.html", "http://www.example.com/path/with/13/contact.html");
    assertEquals(true, event.record.get("pathBoolean"));
    assertEquals("42", event.record.get("client"));
    assertEquals("about", event.record.get("pageview"));
}
Also used : EventPayload(io.divolte.server.ServerTestUtils.EventPayload) Test(org.junit.Test)

Example 20 with EventPayload

use of io.divolte.server.ServerTestUtils.EventPayload in project divolte-collector by divolte.

the class DslRecordMapperTest method shouldApplyActionsInClosureWhenEqualToConditionHolds.

@Test
public void shouldApplyActionsInClosureWhenEqualToConditionHolds() throws IOException, InterruptedException {
    setupServer("when-mapping.groovy");
    final EventPayload event = request("http://www.example.com/", "http://www.example.com/somepage.html");
    assertEquals("locationmatch", event.record.get("eventType"));
    assertEquals("referermatch", event.record.get("client"));
    assertEquals(new Utf8("not set"), event.record.get("queryparam"));
    assertEquals("absent", event.record.get("event"));
    assertEquals("present", event.record.get("pageview"));
}
Also used : Utf8(org.apache.avro.util.Utf8) EventPayload(io.divolte.server.ServerTestUtils.EventPayload) Test(org.junit.Test)

Aggregations

EventPayload (io.divolte.server.ServerTestUtils.EventPayload)46 Test (org.junit.Test)46 HttpURLConnection (java.net.HttpURLConnection)5 URL (java.net.URL)5 GenericRecord (org.apache.avro.generic.GenericRecord)3 Utf8 (org.apache.avro.util.Utf8)3 JsonParser (com.fasterxml.jackson.core.JsonParser)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 CityResponse (com.maxmind.geoip2.model.CityResponse)2 Config (com.typesafe.config.Config)2 ValidatedConfiguration (io.divolte.server.config.ValidatedConfiguration)2 LookupService (io.divolte.server.ip2geo.LookupService)2 DslRecordMapper (io.divolte.server.recordmapping.DslRecordMapper)2 Instant (java.time.Instant)2 Optional (java.util.Optional)2 Stream (java.util.stream.Stream)2 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)2 Assert (org.junit.Assert)2 WebElement (org.openqa.selenium.WebElement)2 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)2