Search in sources :

Example 1 with PinpointContext

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

the class AnalyticsEventTest method copyEvent_initializaer.

@Test
public void copyEvent_initializaer() {
    target.addAttribute("attr", "value");
    target.addMetric("metric", 1.0);
    PinpointContext mockContext = new AnalyticsContextBuilder().withSdkInfo(SDK_NAME, SDK_VERSION).withUniqueIdValue(UNIQUE_ID).withDeviceDetails(testDeviceDetails).withContext(RuntimeEnvironment.application.getApplicationContext()).build();
    AnalyticsEvent copiedTarget = AnalyticsEvent.createFromEvent(mockContext, SESSION_ID, System.currentTimeMillis(), target);
    assertEquals(EVENT_NAME, copiedTarget.getEventType());
    assertEquals(UNIQUE_ID, copiedTarget.getUniqueId());
    assertEquals(true, System.currentTimeMillis() - copiedTarget.getEventTimestamp() < 50);
    assertEquals(SDK_NAME, copiedTarget.getSdkName());
    assertEquals(SDK_VERSION, copiedTarget.getSdkVersion());
    assertEquals("value", copiedTarget.getAttribute("attr"));
    assertEquals(1.0, copiedTarget.getMetric("metric").doubleValue(), .01);
}
Also used : PinpointContext(com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext) AnalyticsContextBuilder(com.amazonaws.mobileconnectors.pinpoint.analytics.utils.AnalyticsContextBuilder) Test(org.junit.Test)

Example 2 with PinpointContext

use of com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext 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 3 with PinpointContext

use of com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext 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)

Example 4 with PinpointContext

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

the class GooglePlayMonetizationEventBuilderTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    when(mockConfiguration.optString("versionKey", "ver")).thenReturn("ver");
    when(mockConfiguration.optBoolean("isAnalyticsEnabled", true)).thenReturn(true);
    PinpointContext mockContext = new AnalyticsContextBuilder().withConfiguration(mockConfiguration).withContext(RuntimeEnvironment.application.getApplicationContext()).build();
    target = new AnalyticsClient(mockContext);
    AnalyticsEvent testEvent = target.createEvent(MonetizationEventBuilder.PURCHASE_EVENT_NAME);
    when(mockEventClient.createEvent(MonetizationEventBuilder.PURCHASE_EVENT_NAME)).thenReturn(testEvent);
}
Also used : AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent) PinpointContext(com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext) AnalyticsClient(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsClient) AnalyticsContextBuilder(com.amazonaws.mobileconnectors.pinpoint.analytics.utils.AnalyticsContextBuilder) Before(org.junit.Before)

Example 5 with PinpointContext

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

the class AnalyticsContextBuilder method build.

public PinpointContext build() {
    final SDKInfo mockSDKInfo = mock(SDKInfo.class);
    when(mockSDKInfo.getName()).thenReturn(sdkName);
    when(mockSDKInfo.getVersion()).thenReturn(sdkVersion);
    final MockUtil mockUtil = new MockUtil();
    if (mockUtil.isMock(mockSystem)) {
        when(mockSystem.getPreferences()).thenReturn(mockPreferences);
        when(mockSystem.getConnectivity()).thenReturn(mockConnectivity);
        final AndroidAppDetails mockAppDetails = new MockAppDetails();
        when(mockSystem.getAppDetails()).thenReturn(mockAppDetails);
        when(mockSystem.getDeviceDetails()).thenReturn(mockDeviceDetails);
    }
    final PinpointContext mockContext = mock(PinpointContext.class);
    when(mockContext.getSDKInfo()).thenReturn(mockSDKInfo);
    when(mockContext.getConfiguration()).thenReturn(mockConfig);
    when(mockContext.getUniqueId()).thenReturn(mockUniqueIdValue);
    when(mockContext.getAnalyticsServiceClient()).thenReturn(mockERS);
    when(mockContext.getPinpointServiceClient()).thenReturn(mockPinpointService);
    when(mockContext.getSystem()).thenReturn(mockSystem);
    // Notification client must be constructed after mock system is set
    mockNotificationClient = new NotificationClient(mockContext);
    when(mockContext.getNotificationClient()).thenReturn(mockNotificationClient);
    when(mockContext.getApplicationContext()).thenReturn(context);
    when(mockContext.getConfiguration()).thenReturn(mockConfig);
    when(mockContext.getNetworkType()).thenCallRealMethod();
    when(mockContext.getTargetingClient()).thenReturn(mockTargetingClient);
    when(mockContext.getPinpointConfiguration()).thenReturn(mockPinpointConfig);
    return mockContext;
}
Also used : MockAppDetails(com.amazonaws.mobileconnectors.pinpoint.internal.core.system.MockAppDetails) PinpointContext(com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext) AndroidAppDetails(com.amazonaws.mobileconnectors.pinpoint.internal.core.system.AndroidAppDetails) MockUtil(org.mockito.internal.util.MockUtil) SDKInfo(com.amazonaws.mobileconnectors.pinpoint.internal.core.util.SDKInfo) NotificationClient(com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient)

Aggregations

PinpointContext (com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext)11 AnalyticsContextBuilder (com.amazonaws.mobileconnectors.pinpoint.analytics.utils.AnalyticsContextBuilder)9 Before (org.junit.Before)7 AnalyticsClient (com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsClient)5 AnalyticsEvent (com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent)5 AndroidPreferencesConfiguration (com.amazonaws.mobileconnectors.pinpoint.internal.core.configuration.AndroidPreferencesConfiguration)2 Test (org.junit.Test)2 Cursor (android.database.Cursor)1 AndroidAppDetails (com.amazonaws.mobileconnectors.pinpoint.internal.core.system.AndroidAppDetails)1 AndroidDeviceDetails (com.amazonaws.mobileconnectors.pinpoint.internal.core.system.AndroidDeviceDetails)1 MockAppDetails (com.amazonaws.mobileconnectors.pinpoint.internal.core.system.MockAppDetails)1 MockDeviceDetails (com.amazonaws.mobileconnectors.pinpoint.internal.core.system.MockDeviceDetails)1 SDKInfo (com.amazonaws.mobileconnectors.pinpoint.internal.core.util.SDKInfo)1 NotificationClient (com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient)1 ExecutorService (java.util.concurrent.ExecutorService)1 JSONArray (org.json.JSONArray)1 MockUtil (org.mockito.internal.util.MockUtil)1