コード例 #1
0
  public void testSessions() {
    Context context = activity.getApplicationContext();

    // starting from a clean slate
    mockLogger.test(
        "Was AdjustActivityState deleted? " + ActivityHandler.deleteActivityState(context));

    // adjust the intervals for testing
    AdjustFactory.setSessionInterval(2000);
    AdjustFactory.setSubsessionInterval(100);

    ActivityHandler activityHandler = new ActivityHandler(activity);

    // start the first session
    activityHandler.trackSubsessionStart();

    // wait enough to be a new subsession, but not a new session
    SystemClock.sleep(1500);

    activityHandler.trackSubsessionStart();
    // wait enough to be a new session
    SystemClock.sleep(4000);
    activityHandler.trackSubsessionStart();
    // test the subsession end
    activityHandler.trackSubsessionEnd();
    SystemClock.sleep(1000);

    // check that a new subsession was created
    assertTrue(
        mockLogger.toString(),
        mockLogger.containsMessage(LogLevel.INFO, "Started subsession 2 of session 1"));

    // check that it's now on the 2nd session
    assertTrue(mockLogger.toString(), mockLogger.containsMessage(LogLevel.DEBUG, "Session 2"));

    // check that 2 packages were added to the package handler
    assertEquals(2, mockPackageHandler.queue.size());

    // get the second session package and its parameters
    ActivityPackage activityPackage = mockPackageHandler.queue.get(1);
    Map<String, String> parameters = activityPackage.getParameters();

    // the session and subsession count should be 2
    assertEquals(
        activityPackage.getExtendedString(), 2, Integer.parseInt(parameters.get("session_count")));
    assertEquals(
        activityPackage.getExtendedString(),
        2,
        Integer.parseInt(parameters.get("subsession_count")));

    // TODO test updated timeSpent and sessionLenght
    mockLogger.test("timeSpent " + parameters.get("time_spent"));
    mockLogger.test("sessionLength " + parameters.get("session_length"));

    // check that the package handler was paused
    assertTrue(
        mockLogger.toString(), mockLogger.containsTestMessage("PackageHandler pauseSending"));
  }
コード例 #2
0
  @Override
  protected void tearDown() throws Exception {
    super.tearDown();

    AdjustFactory.setPackageHandler(null);
    AdjustFactory.setLogger(null);
    AdjustFactory.setTimerInterval(-1);
    AdjustFactory.setSessionInterval(-1);
    AdjustFactory.setSubsessionInterval(-1);
  }
コード例 #3
0
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    mockLogger = new MockLogger();
    mockPackageHandler = new MockPackageHandler(mockLogger);

    AdjustFactory.setLogger(mockLogger);
    AdjustFactory.setPackageHandler(mockPackageHandler);

    activity = getActivity();
  }
コード例 #4
0
  public void testDisable() {
    Context context = activity.getApplicationContext();

    // starting from a clean slate
    mockLogger.test(
        "Was AdjustActivityState deleted? " + ActivityHandler.deleteActivityState(context));

    // set the timer for a shorter time for testing
    AdjustFactory.setTimerInterval(700);

    ActivityHandler activityHandler =
        new ActivityHandler(activity, "qwerty123456", "sandbox", "verbose", false);

    // verify the default value, when not started
    assertTrue(activityHandler.isEnabled());

    activityHandler.setEnabled(false);

    // verify the default value, when not started
    assertFalse(activityHandler.isEnabled());

    // start the first session
    activityHandler.trackSubsessionStart();
    activityHandler.trackEvent("123456", null);
    activityHandler.trackRevenue(0.1, null, null);
    activityHandler.trackSubsessionEnd();
    activityHandler.trackSubsessionStart();

    SystemClock.sleep(1000);

    // verify the changed value after the activity handler is started
    assertFalse(activityHandler.isEnabled());

    // making sure the first session was sent
    assertTrue(mockLogger.toString(), mockLogger.containsMessage(LogLevel.INFO, "First session"));

    // delete the first session package from the log
    assertTrue(
        mockLogger.toString(), mockLogger.containsTestMessage("PackageHandler sendFirstPackage"));

    // making sure the timer fired did not call the package handler
    assertFalse(
        mockLogger.toString(), mockLogger.containsTestMessage("PackageHandler sendFirstPackage"));

    // test if the event was not triggered
    assertFalse(mockLogger.toString(), mockLogger.containsMessage(LogLevel.DEBUG, "Event 1"));
    // test if the revenue was not triggered
    assertFalse(
        mockLogger.toString(), mockLogger.containsMessage(LogLevel.DEBUG, "Event 1 (revenue)"));

    // verify that the application was paused
    assertTrue(
        mockLogger.toString(), mockLogger.containsTestMessage("PackageHandler pauseSending"));
    // verify that it was not resumed
    assertFalse(
        mockLogger.toString(), mockLogger.containsTestMessage("PackageHandler resumeSending"));

    // enable again
    activityHandler.setEnabled(true);

    SystemClock.sleep(1000);

    // verify that the timer was able to resume sending
    assertTrue(
        mockLogger.toString(), mockLogger.containsTestMessage("PackageHandler resumeSending"));

    activityHandler.trackEvent("123456", null);
    activityHandler.trackRevenue(0.1, null, null);
    activityHandler.trackSubsessionEnd();
    activityHandler.trackSubsessionStart();
    SystemClock.sleep(1000);

    // verify the changed value, when the activity state is started
    assertTrue(activityHandler.isEnabled());

    // test that the event was triggered
    assertTrue(mockLogger.toString(), mockLogger.containsMessage(LogLevel.DEBUG, "Event 1"));
    // test that the revenue was triggered
    assertTrue(
        mockLogger.toString(), mockLogger.containsMessage(LogLevel.DEBUG, "Event 2 (revenue)"));

    // verify that the application was paused
    assertTrue(
        mockLogger.toString(), mockLogger.containsTestMessage("PackageHandler pauseSending"));
    // verify that it was also resumed
    assertTrue(
        mockLogger.toString(), mockLogger.containsTestMessage("PackageHandler resumeSending"));
    // */
  }