Search in sources :

Example 1 with AnalyticsClient

use of com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsClient in project aws-sdk-android by aws-amplify.

the class AWSErsLocaleTestBase method setupForRepeatedTestCase.

@Override
public void setupForRepeatedTestCase() {
    Context mockAndroidContext = new ContextWithPermissions(new Activity());
    AWSCredentialsProvider provider = new AWSCredentialsProvider() {

        AWSCredentials creds = new AnonymousAWSCredentials();

        @Override
        public AWSCredentials getCredentials() {
            return creds;
        }

        @Override
        public void refresh() {
        }
    };
    mockConfiguration = mock(AndroidPreferencesConfiguration.class);
    PinpointConfiguration options = new PinpointConfiguration(mockAndroidContext, UNIQUE_ID, Regions.US_EAST_1, ChannelType.GCM, provider);
    context = new AnalyticsContextBuilder().withSdkInfo(SDK_NAME, SDK_VERSION).withUniqueIdValue(UNIQUE_ID).withContext(RuntimeEnvironment.application.getApplicationContext()).withSystem(new MockSystem("HELLO.world")).withConfiguration(mockConfiguration).build();
    AnalyticsClient analyticsClient = new AnalyticsClient(context);
    TargetingClient targetingClient = new TargetingClient(context);
    context.setAnalyticsClient(analyticsClient);
    context.setTargetingClient(targetingClient);
    SessionClient isc = new SessionClient(context);
    PinpointConfiguration config = new PinpointConfiguration(mockAndroidContext, UNIQUE_ID, Regions.US_EAST_1, ChannelType.GCM, provider);
    instance = new PinpointManager(config);
}
Also used : Context(android.content.Context) PinpointContext(com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext) SessionClient(com.amazonaws.mobileconnectors.pinpoint.analytics.SessionClient) AnalyticsContextBuilder(com.amazonaws.mobileconnectors.pinpoint.analytics.utils.AnalyticsContextBuilder) ContextWithPermissions(com.amazonaws.mobileconnectors.pinpoint.analytics.utils.ContextWithPermissions) Activity(android.app.Activity) AnonymousAWSCredentials(com.amazonaws.auth.AnonymousAWSCredentials) MockSystem(com.amazonaws.mobileconnectors.pinpoint.internal.core.system.MockSystem) AnonymousAWSCredentials(com.amazonaws.auth.AnonymousAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) AnalyticsClient(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsClient) TargetingClient(com.amazonaws.mobileconnectors.pinpoint.targeting.TargetingClient) AndroidPreferencesConfiguration(com.amazonaws.mobileconnectors.pinpoint.internal.core.configuration.AndroidPreferencesConfiguration) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 2 with AnalyticsClient

use of com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsClient in project aws-sdk-android by aws-amplify.

the class EventLocaleTest method createEvent_verifyLocaleFormat.

@Test
public void createEvent_verifyLocaleFormat() throws JSONException {
    Map<String, Locale> locales = new HashMap<String, Locale>();
    locales.put("en_US", Locale.US);
    locales.put("en_CA", Locale.CANADA);
    locales.put("fr_CA", Locale.CANADA_FRENCH);
    locales.put("zh_CN", Locale.CHINA);
    locales.put("fr_FR", Locale.FRANCE);
    locales.put("de_DE", Locale.GERMANY);
    locales.put("it_IT", Locale.ITALY);
    locales.put("ja_JP", Locale.JAPAN);
    locales.put("ko_KR", Locale.KOREA);
    locales.put("zh_TW", Locale.TAIWAN);
    locales.put("en_GB", Locale.UK);
    locales.put("ar_SA", new Locale("ar", "SA"));
    locales.put("nl_NL", new Locale("nl", "NL"));
    locales.put("en_AU", new Locale("en", "AU"));
    locales.put("es_ES", new Locale("es", "ES"));
    locales.put("pt_BR", new Locale("pt", "BR"));
    locales.put("es_MX", new Locale("es", "MX"));
    for (String expectedLocaleName : locales.keySet()) {
        Locale expectedLocale = locales.get(expectedLocaleName);
        // create an event client
        AnalyticsClient target = new AnalyticsClient(createMockContext(expectedLocale));
        // create the event
        AnalyticsEvent event = target.createEvent("localeEvent");
        target.recordEvent(event);
        JSONObject jsonEvent = event.toJSONObject();
        assertThat(jsonEvent.getString("locale"), is(expectedLocaleName));
    }
}
Also used : Locale(java.util.Locale) AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent) AnalyticsClient(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsClient) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with AnalyticsClient

use of com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsClient in project aws-sdk-android by aws-amplify.

the class FCMNotificationClientTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    final Context roboContext = RuntimeEnvironment.application.getApplicationContext();
    spiedRoboContext = Mockito.spy(roboContext);
    mockPinpointContext = new AnalyticsContextBuilder().withSystem(new MockSystem("JIMMY_CRACKED_CORN.and")).withConfiguration(mockConfiguration).withContext(spiedRoboContext).build();
    analyticsClient = new AnalyticsClient(mockPinpointContext);
    Whitebox.setInternalState(analyticsClient, "eventRecorder", mockEventRecorder);
    when(mockConfiguration.optBoolean("isAnalyticsEnabled", true)).thenReturn(true);
    when(mockPinpointContext.getAnalyticsClient()).thenReturn(analyticsClient);
    // target.setSessionClient(new SessionClient(mockContext, mockEventClient, mockTargetingClient,
    // new TestSessionStore(), false));
    when(mockPinpointContext.getTargetingClient()).thenReturn(mockTargetingClient);
    when(mockPinpointContext.getConfiguration()).thenReturn(mockConfiguration);
    when(mockPinpointContext.getPinpointConfiguration()).thenReturn(mockPinpointConfiguration);
    target = NotificationClient.createClient(mockPinpointContext, ChannelType.GCM);
}
Also used : Context(android.content.Context) PinpointContext(com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext) AnalyticsClient(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsClient) AnalyticsContextBuilder(com.amazonaws.mobileconnectors.pinpoint.analytics.utils.AnalyticsContextBuilder) MockSystem(com.amazonaws.mobileconnectors.pinpoint.internal.core.system.MockSystem) Before(org.junit.Before)

Example 4 with AnalyticsClient

use of com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsClient in project aws-sdk-android by aws-amplify.

the class GCMNotificationClientTest method testGCMJourneyMessageReceivedDefaultDoNotPostNotificationInForeground.

@Test
public void testGCMJourneyMessageReceivedDefaultDoNotPostNotificationInForeground() throws JSONException {
    // Force the app to be in the background
    final AnalyticsEvent expectedEvent = new AnalyticsClient(mockPinpointContext).createEvent("_journey.received_background").withAttribute("journey_id", "fake_journey_id").withAttribute("journey_activity_id", "fake_journey_activity_id").withAttribute("journey_run_id", "fake_journey_run_id").withAttribute("feedback", "random_feedback").withAttribute("endpoint_id", "fake_endpoint_id").withAttribute("user_id", "fake_user_id").withAttribute("isOptedOut", "true").withAttribute("isAppInForeground", "false");
    final AppUtil appUtil = Mockito.mock(AppUtil.class);
    Whitebox.setInternalState(target.notificationClientBase, "appUtil", appUtil);
    Mockito.when(appUtil.isAppInForeground()).thenReturn(false);
    NotificationDetails.NotificationDetailsBuilder notificationDetailsBuilder = NotificationDetails.builder().from("12345").bundle(buildJourneyPushBundle()).serviceClass(Service.class).intentAction(GCM_INTENT_ACTION);
    NotificationClient.PushResult pushResult = target.handleNotificationReceived(notificationDetailsBuilder.build());
    assertEquals(NotificationClient.PushResult.OPTED_OUT, pushResult);
    ArgumentCaptor<AnalyticsEvent> eventCaptor = ArgumentCaptor.forClass(AnalyticsEvent.class);
    verify(mockEventRecorder, times(1)).recordEvent(eventCaptor.capture());
    final AnalyticsEvent receivedEvent = eventCaptor.getAllValues().get(0);
    assertTrue(receivedEvent.getEventTimestamp() > 0);
    assertEquals("_journey.received_background", receivedEvent.getEventType());
    assertEquals(expectedEvent.getAllAttributes(), receivedEvent.getAllAttributes());
}
Also used : AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent) AnalyticsClient(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsClient) Service(android.app.Service) Test(org.junit.Test)

Example 5 with AnalyticsClient

use of com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsClient in project aws-sdk-android by aws-amplify.

the class GCMNotificationClientTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    Context roboContext = ApplicationProvider.getApplicationContext();
    spiedRoboContext = Mockito.spy(roboContext);
    mockPinpointContext = new AnalyticsContextBuilder().withSystem(new MockSystem("JIMMY_CRACKED_CORN.and")).withConfiguration(mockConfiguration).withContext(spiedRoboContext).build();
    analyticsClient = new AnalyticsClient(mockPinpointContext);
    Whitebox.setInternalState(analyticsClient, "eventRecorder", mockEventRecorder);
    when(mockConfiguration.optBoolean("isAnalyticsEnabled", true)).thenReturn(true);
    when(mockPinpointContext.getAnalyticsClient()).thenReturn(analyticsClient);
    // target.setSessionClient(new SessionClient(mockContext, mockEventClient, mockTargetingClient,
    // new TestSessionStore(), false));
    when(mockPinpointContext.getTargetingClient()).thenReturn(mockTargetingClient);
    when(mockPinpointContext.getConfiguration()).thenReturn(mockConfiguration);
    when(mockPinpointContext.getPinpointConfiguration()).thenReturn(mockPinpointConfiguration);
    target = NotificationClient.createClient(mockPinpointContext, ChannelType.GCM);
}
Also used : Context(android.content.Context) PinpointContext(com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext) AnalyticsClient(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsClient) AnalyticsContextBuilder(com.amazonaws.mobileconnectors.pinpoint.analytics.utils.AnalyticsContextBuilder) MockSystem(com.amazonaws.mobileconnectors.pinpoint.internal.core.system.MockSystem) Before(org.junit.Before)

Aggregations

AnalyticsClient (com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsClient)13 AnalyticsContextBuilder (com.amazonaws.mobileconnectors.pinpoint.analytics.utils.AnalyticsContextBuilder)10 PinpointContext (com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext)10 Before (org.junit.Before)10 AnalyticsEvent (com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent)7 Context (android.content.Context)5 MockSystem (com.amazonaws.mobileconnectors.pinpoint.internal.core.system.MockSystem)5 SessionClient (com.amazonaws.mobileconnectors.pinpoint.analytics.SessionClient)2 Test (org.junit.Test)2 Activity (android.app.Activity)1 Service (android.app.Service)1 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)1 AnonymousAWSCredentials (com.amazonaws.auth.AnonymousAWSCredentials)1 ContextWithPermissions (com.amazonaws.mobileconnectors.pinpoint.analytics.utils.ContextWithPermissions)1 AndroidPreferencesConfiguration (com.amazonaws.mobileconnectors.pinpoint.internal.core.configuration.AndroidPreferencesConfiguration)1 TargetingClient (com.amazonaws.mobileconnectors.pinpoint.targeting.TargetingClient)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 JSONObject (org.json.JSONObject)1