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);
}
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;
}
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());
}
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);
}
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;
}
Aggregations