Search in sources :

Example 31 with EventPayload

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

the class SeleniumJavaScriptTest method shouldSignalWhenOpeningPage.

@Test
public void shouldSignalWhenOpeningPage() throws Exception {
    doSetUp();
    Preconditions.checkState(null != server);
    final String location = gotoPage(BASIC);
    final EventPayload payload = server.waitForEvent();
    final DivolteEvent eventData = payload.event;
    final Boolean detectedDuplicate = payload.event.exchange.getAttachment(DUPLICATE_EVENT_KEY);
    assertFalse(eventData.corruptEvent);
    assertFalse(detectedDuplicate);
    assertFalse(Strings.isNullOrEmpty(eventData.partyId.value));
    assertTrue(eventData.newPartyId);
    assertFalse(Strings.isNullOrEmpty(eventData.sessionId.value));
    assertTrue(eventData.firstInSession);
    assertTrue(eventData.browserEventData.isPresent());
    final DivolteEvent.BrowserEventData browserEventData = eventData.browserEventData.get();
    assertFalse(Strings.isNullOrEmpty(browserEventData.pageViewId));
    assertFalse(Strings.isNullOrEmpty(eventData.eventId));
    assertTrue(eventData.eventType.isPresent());
    assertEquals("pageView", eventData.eventType.get());
    assertTrue(browserEventData.location.isPresent());
    assertEquals(location, browserEventData.location.get());
    /*
         * We don't really know anything about the clock on the executing browser,
         * but we'd expect it to be a reasonably accurate clock on the same planet.
         * So, if it is within +/- 12 hours of our clock, we think it's fine.
         */
    final Instant now = Instant.now();
    assertThat(eventData.clientTime, allOf(greaterThan(now.minus(12, ChronoUnit.HOURS)), lessThan(now.plus(12, ChronoUnit.HOURS))));
    /*
         * Doing true assertions against the viewport and window size
         * is problematic on different devices, as the number do not
         * always make sense on SauceLabs. Also, sometimes the window
         * is partially outside of the screen view port or other strange
         * things. It gets additionally complicated on mobile devices.
         *
         * Hence, we just check whether these are integers greater than 50.
         */
    assertTrue(browserEventData.viewportPixelWidth.isPresent());
    assertThat(browserEventData.viewportPixelWidth.get(), greaterThan(50));
    assertTrue(browserEventData.viewportPixelHeight.isPresent());
    assertThat(browserEventData.viewportPixelHeight.get(), greaterThan(50));
    assertTrue(browserEventData.screenPixelWidth.isPresent());
    assertThat(browserEventData.screenPixelWidth.get(), greaterThan(50));
    assertTrue(browserEventData.screenPixelHeight.isPresent());
    assertThat(browserEventData.screenPixelHeight.get(), greaterThan(50));
}
Also used : Instant(java.time.Instant) EventPayload(io.divolte.server.ServerTestUtils.EventPayload) Test(org.junit.Test)

Example 32 with EventPayload

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

the class SeleniumJavaScriptTest method shouldSupportCustomJavascriptName.

@Test
public void shouldSupportCustomJavascriptName() throws Exception {
    doSetUp("selenium-test-custom-javascript-name.conf");
    Preconditions.checkState(null != server);
    gotoPage(CUSTOM_JAVASCRIPT_NAME);
    final EventPayload payload = server.waitForEvent();
    final DivolteEvent eventData = payload.event;
    assertEquals(Optional.of("pageView"), eventData.eventType);
}
Also used : EventPayload(io.divolte.server.ServerTestUtils.EventPayload) Test(org.junit.Test)

Example 33 with EventPayload

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

the class DslRecordMapperTest method shouldStopWhenToldTo.

@Test
public void shouldStopWhenToldTo() throws IOException, InterruptedException {
    setupServer("basic-stop.groovy");
    final EventPayload event = request("http://www.example.com");
    assertEquals("happened", event.record.get("client"));
    assertNull(event.record.get("session"));
}
Also used : EventPayload(io.divolte.server.ServerTestUtils.EventPayload) Test(org.junit.Test)

Example 34 with EventPayload

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

the class DslRecordMapperTest method shouldParseUriComponentsRaw.

@Test
public void shouldParseUriComponentsRaw() throws IOException, InterruptedException {
    setupServer("uri-mapping-raw.groovy");
    final EventPayload event = request("http://example.com/path/to/resource%20and%20such/page.html?q=multiple+words+%24%23%25%26&p=42#/client/side/path?x=value&y=42&q=multiple+words+%24%23%25%26");
    assertEquals("/path/to/resource%20and%20such/page.html", event.record.get("uriPath"));
    assertEquals("q=multiple+words+%24%23%25%26&p=42", event.record.get("uriQueryString"));
    assertEquals("/client/side/path?x=value&y=42&q=multiple+words+%24%23%25%26", event.record.get("uriFragment"));
}
Also used : EventPayload(io.divolte.server.ServerTestUtils.EventPayload) Test(org.junit.Test)

Example 35 with EventPayload

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

the class DslRecordMapperTest method shouldMapAllEventParameters.

@Test
public void shouldMapAllEventParameters() throws IOException, InterruptedException {
    setupServer("event-param-all.groovy");
    final EventPayload event = request("http://www.example.com/", Collections.singletonList(HETEROGENOUS_EVENT_PARAMS));
    assertEquals("{\"foo\": \"string\", \"bar\": \"42\", \"items\": [{\"count\": 3, \"price\": 1.23}, {\"count\": 1, \"price\": 0.89}]}", GenericData.get().toString(event.record.get("paramRecord")));
}
Also used : 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