Search in sources :

Example 1 with AndroidPreferencesConfiguration

use of com.amazonaws.mobileconnectors.pinpoint.internal.core.configuration.AndroidPreferencesConfiguration in project aws-sdk-android by aws-amplify.

the class EventLocaleTest method createMockContext.

private static PinpointContext createMockContext(Locale localeToReturn) {
    AndroidPreferencesConfiguration mockConfiguration = Mockito.mock(AndroidPreferencesConfiguration.class);
    when(mockConfiguration.optString("versionKey", "ver")).thenReturn("ver");
    when(mockConfiguration.optBoolean("isAnalyticsEnabled", true)).thenReturn(true);
    AndroidDeviceDetails mockDeviceDetails = Mockito.mock(AndroidDeviceDetails.class);
    when(mockDeviceDetails.locale()).thenReturn(localeToReturn);
    PinpointContext mockContext = new AnalyticsContextBuilder().withSdkInfo(SDK_NAME, SDK_VERSION).withUniqueIdValue(UNIQUE_ID).withConfiguration(mockConfiguration).withDeviceDetails(mockDeviceDetails).withContext(RuntimeEnvironment.application.getApplicationContext()).build();
    return mockContext;
}
Also used : AndroidDeviceDetails(com.amazonaws.mobileconnectors.pinpoint.internal.core.system.AndroidDeviceDetails) PinpointContext(com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext) AndroidPreferencesConfiguration(com.amazonaws.mobileconnectors.pinpoint.internal.core.configuration.AndroidPreferencesConfiguration) AnalyticsContextBuilder(com.amazonaws.mobileconnectors.pinpoint.analytics.utils.AnalyticsContextBuilder)

Example 2 with AndroidPreferencesConfiguration

use of com.amazonaws.mobileconnectors.pinpoint.internal.core.configuration.AndroidPreferencesConfiguration in project aws-sdk-android by aws-amplify.

the class EventRecorderTest method testProcessEvent_eventCount100.

@Test
public void testProcessEvent_eventCount100() {
    PinpointDBUtil dbUtil = mock(PinpointDBUtil.class);
    PinpointContext pinpointContext = mock(PinpointContext.class);
    EventRecorder eventRecorder = new EventRecorder(pinpointContext, dbUtil, mock(ExecutorService.class));
    AndroidPreferencesConfiguration config = mock(AndroidPreferencesConfiguration.class);
    when(pinpointContext.getConfiguration()).thenReturn(config);
    when(config.optLong(any(String.class), any(Long.class))).thenReturn(5 * 1024 * 1024L);
    Cursor cursor = mock(Cursor.class);
    // Note: Due to API there are (numberOfEvents + 1) added
    int numberOfEvents = 150;
    Boolean[] falseArray = new Boolean[numberOfEvents];
    Arrays.fill(falseArray, false);
    int sharedIdForAllEvents = 1;
    Integer[] idArray = new Integer[numberOfEvents];
    Arrays.fill(idArray, sharedIdForAllEvents);
    int size = 2;
    Integer[] sizeArray = new Integer[numberOfEvents];
    Arrays.fill(sizeArray, size);
    String[] jsonStringArray = new String[numberOfEvents];
    String json = "{}";
    Arrays.fill(jsonStringArray, json);
    when(cursor.isNull(EventTable.COLUMN_INDEX.ID.getValue())).thenReturn(false, falseArray);
    when(cursor.getInt(EventTable.COLUMN_INDEX.ID.getValue())).thenReturn(sharedIdForAllEvents, idArray);
    when(cursor.isNull(EventTable.COLUMN_INDEX.SIZE.getValue())).thenReturn(false, falseArray);
    when(cursor.getInt(EventTable.COLUMN_INDEX.SIZE.getValue())).thenReturn(size, sizeArray);
    when(cursor.isNull(EventTable.COLUMN_INDEX.JSON.getValue())).thenReturn(false, falseArray);
    when(cursor.getString(EventTable.COLUMN_INDEX.JSON.getValue())).thenReturn(json, jsonStringArray);
    // Allows looping for next batch submit
    when(cursor.moveToNext()).thenReturn(true).thenReturn(true).thenReturn(true);
    JSONArray readArray = eventRecorder.getBatchOfEvents(cursor, new HashMap<Integer, Integer>());
    assertEquals(EventRecorder.SERVICE_DEFINED_MAX_EVENTS_PER_BATCH, readArray.length());
}
Also used : PinpointContext(com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext) JSONArray(org.json.JSONArray) Cursor(android.database.Cursor) AndroidPreferencesConfiguration(com.amazonaws.mobileconnectors.pinpoint.internal.core.configuration.AndroidPreferencesConfiguration) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Aggregations

PinpointContext (com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext)2 AndroidPreferencesConfiguration (com.amazonaws.mobileconnectors.pinpoint.internal.core.configuration.AndroidPreferencesConfiguration)2 Cursor (android.database.Cursor)1 AnalyticsContextBuilder (com.amazonaws.mobileconnectors.pinpoint.analytics.utils.AnalyticsContextBuilder)1 AndroidDeviceDetails (com.amazonaws.mobileconnectors.pinpoint.internal.core.system.AndroidDeviceDetails)1 ExecutorService (java.util.concurrent.ExecutorService)1 JSONArray (org.json.JSONArray)1 Test (org.junit.Test)1