Search in sources :

Example 6 with EndpointProfile

use of com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfile in project aws-sdk-android by aws-amplify.

the class TargetingClientTest method updateEndpointCallNullSetters.

@Test
public void updateEndpointCallNullSetters() {
    // Verify null checks on setters should not throw a null pointer exception
    EndpointProfile profile = new EndpointProfile(mockContext);
    profile.getDemographic().setLocale(null);
    profile.getDemographic().setAppVersion(null);
    profile.getDemographic().setMake(null);
    profile.getDemographic().setModel(null);
    profile.getDemographic().setPlatform(null);
    profile.getDemographic().setPlatformVersion(null);
    profile.getDemographic().setTimezone(null);
    profile.getLocation().setCountry(null);
    profile.getLocation().setCity(null);
    profile.getLocation().setLatitude(null);
    profile.getLocation().setLongitude(null);
    profile.getLocation().setPostalCode(null);
    profile.getLocation().setRegion(null);
    targetingClient.updateEndpointProfile(profile);
}
Also used : EndpointProfile(com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfile) Test(org.junit.Test)

Example 7 with EndpointProfile

use of com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfile in project aws-sdk-android by aws-amplify.

the class EventRecorderTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    testDeviceDetails = new MockDeviceDetails();
    mockContext = new AnalyticsContextBuilder().withSdkInfo(SDK_NAME, SDK_VERSION).withUniqueIdValue(UNIQUE_ID).withDeviceDetails(testDeviceDetails).withContext(RuntimeEnvironment.application.getApplicationContext()).build();
    analyticsEvent = AnalyticsEvent.newInstance(mockContext, SESSION_ID, SESSION_START, SESSION_END, SESSION_DURATION, TIME_STAMP, EVENT_NAME);
    analyticsEvent.addAttribute("key1", "value1");
    analyticsEvent.addAttribute("key2", "value2");
    endpointProfile = new EndpointProfile(mockContext);
    dbUtil = new PinpointDBUtil(RuntimeEnvironment.application.getApplicationContext());
    eventRecorder = new EventRecorder(mockContext, dbUtil, submissionRunnable);
}
Also used : MockDeviceDetails(com.amazonaws.mobileconnectors.pinpoint.internal.core.system.MockDeviceDetails) EndpointProfile(com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfile) AnalyticsContextBuilder(com.amazonaws.mobileconnectors.pinpoint.analytics.utils.AnalyticsContextBuilder) Before(org.junit.Before)

Example 8 with EndpointProfile

use of com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfile in project aws-sdk-android by aws-amplify.

the class EndpointProfileTest method testEndpointSerialization.

@Test
public void testEndpointSerialization() throws JSONException {
    target = new EndpointProfile(mockContext);
    long date = DateUtil.getCorrectedDate().getTime();
    target.setEffectiveDate(date);
    target.addMetric("key1", 0.0);
    target.addAttribute("key1", Arrays.asList(new String[] { "attr1", "attr2" }));
    assertFalse(target.getAllMetrics().isEmpty());
    assertFalse(target.getAllAttributes().isEmpty());
    assertNotNull(target.getEffectiveDate());
    JSONObject jsonEndpoint = target.toJSONObject();
    assertTrue(jsonEndpoint.getString("ApplicationId").equalsIgnoreCase(target.getApplicationId()));
    assertTrue(jsonEndpoint.getString("EndpointId").equalsIgnoreCase(target.getEndpointId()));
    assertTrue(jsonEndpoint.getString("ChannelType").equalsIgnoreCase(target.getChannelType()));
    assertTrue(jsonEndpoint.getString("EffectiveDate").equalsIgnoreCase(DateUtil.isoDateFromMillis(date)));
    assertTrue(jsonEndpoint.getString("OptOut").equalsIgnoreCase(target.getOptOut()));
    JSONObject metrics = jsonEndpoint.getJSONObject("Metrics");
    assertEquals(metrics.getDouble("key1"), 0.0, 0.0);
    JSONObject attributes = jsonEndpoint.getJSONObject("Attributes");
    JSONArray attrValues = attributes.getJSONArray("key1");
    assertTrue(attrValues.getString(0).equalsIgnoreCase("attr1"));
    assertTrue(attrValues.getString(1).equalsIgnoreCase("attr2"));
    JSONObject location = jsonEndpoint.getJSONObject("Location");
    assertTrue(location.getString("PostalCode").equalsIgnoreCase(target.getLocation().getPostalCode()));
    assertTrue(location.getString("Region").equalsIgnoreCase(target.getLocation().getRegion()));
    assertTrue(location.getString("Country").equalsIgnoreCase(target.getLocation().getCountry()));
    assertTrue(location.getString("City").equalsIgnoreCase(target.getLocation().getCity()));
    JSONObject demographic = jsonEndpoint.getJSONObject("Demographic");
    assertTrue(demographic.getString("Timezone").equalsIgnoreCase(target.getDemographic().getTimezone()));
    assertTrue(demographic.getString("Locale").equalsIgnoreCase(target.getDemographic().getLocale().toString()));
    assertTrue(demographic.getString("AppVersion").equalsIgnoreCase(target.getDemographic().getAppVersion()));
    assertTrue(demographic.getString("PlatformVersion").equalsIgnoreCase(target.getDemographic().getPlatformVersion()));
    assertTrue(demographic.getString("Platform").equalsIgnoreCase(target.getDemographic().getPlatform()));
    assertTrue(demographic.getString("Model").equalsIgnoreCase(target.getDemographic().getModel()));
    assertTrue(demographic.getString("Make").equalsIgnoreCase(target.getDemographic().getMake()));
}
Also used : EndpointProfile(com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfile) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Test(org.junit.Test)

Example 9 with EndpointProfile

use of com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfile in project aws-sdk-android by aws-amplify.

the class EndpointProfileTest method testLocaleWithInvalidISO3Code.

@Test
public void testLocaleWithInvalidISO3Code() {
    final TargetingClient targetingClient = new TargetingClient(mockContext, mock(ThreadPoolExecutor.class));
    final EndpointProfile endpointProfile = targetingClient.currentEndpoint();
    final EndpointProfileDemographic demographic = endpointProfile.getDemographic();
    // Old country code for Serbia and Montenegro that has no ISO3 equivalent.
    // See https://en.wikipedia.org/wiki/ISO_3166-2:CS  for more info
    Locale locale = new Locale("en", "CS");
    demographic.setLocale(locale);
    assertTrue(demographic.getLocale().toString().equalsIgnoreCase(locale.toString()));
    targetingClient.updateEndpointProfile(endpointProfile);
}
Also used : Locale(java.util.Locale) EndpointProfile(com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfile) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) EndpointProfileDemographic(com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfileDemographic) Test(org.junit.Test)

Example 10 with EndpointProfile

use of com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfile in project aws-sdk-android by aws-amplify.

the class EndpointProfileTest method testCountryWithInvalidISO3Code.

@Test
public void testCountryWithInvalidISO3Code() {
    Context mockApplicationContext = mock(Context.class);
    android.content.res.Resources mockResources = mock(android.content.res.Resources.class);
    android.content.res.Configuration mockConfiguration = mock(android.content.res.Configuration.class);
    mockConfiguration.locale = new Locale("en", "CS");
    Context mockedContext = mockContext.getApplicationContext().getApplicationContext();
    when(mockResources.getConfiguration()).thenReturn(mockConfiguration);
    when(mockApplicationContext.getResources()).thenReturn(mockResources);
    when(mockApplicationContext.getApplicationContext()).thenReturn(mockedContext);
    NotificationManager notificationManager = mock(NotificationManager.class);
    when(mockApplicationContext.getSystemService(Context.NOTIFICATION_SERVICE)).thenReturn(notificationManager);
    when(notificationManager.areNotificationsEnabled()).thenReturn(true);
    when(mockContext.getApplicationContext()).thenReturn(mockApplicationContext);
    final TargetingClient targetingClient = new TargetingClient(mockContext, mock(ThreadPoolExecutor.class));
    final EndpointProfile endpointProfile = targetingClient.currentEndpoint();
    String localeCountry;
    try {
        localeCountry = mockContext.getApplicationContext().getResources().getConfiguration().locale.getISO3Country();
    } catch (final MissingResourceException exception) {
        localeCountry = mockContext.getApplicationContext().getResources().getConfiguration().locale.getCountry();
    }
    final EndpointProfileLocation location = endpointProfile.getLocation();
    assertTrue(location.getCountry().equalsIgnoreCase(localeCountry));
    targetingClient.updateEndpointProfile(endpointProfile);
}
Also used : Context(android.content.Context) PinpointContext(com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext) Locale(java.util.Locale) EndpointProfile(com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfile) NotificationManager(android.app.NotificationManager) EndpointProfileLocation(com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfileLocation) MissingResourceException(java.util.MissingResourceException) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Test(org.junit.Test)

Aggregations

EndpointProfile (com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfile)13 Test (org.junit.Test)10 EndpointProfileUser (com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfileUser)3 AWSPinpointUserProfile (com.amplifyframework.analytics.pinpoint.models.AWSPinpointUserProfile)3 AnalyticsContextBuilder (com.amazonaws.mobileconnectors.pinpoint.analytics.utils.AnalyticsContextBuilder)2 MockDeviceDetails (com.amazonaws.mobileconnectors.pinpoint.internal.core.system.MockDeviceDetails)2 AnalyticsProperties (com.amplifyframework.analytics.AnalyticsProperties)2 UserProfile (com.amplifyframework.analytics.UserProfile)2 List (java.util.List)2 Locale (java.util.Locale)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 Before (org.junit.Before)2 NotificationManager (android.app.NotificationManager)1 Context (android.content.Context)1 PinpointContext (com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext)1 TargetingClient (com.amazonaws.mobileconnectors.pinpoint.targeting.TargetingClient)1 EndpointProfileDemographic (com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfileDemographic)1 EndpointProfileLocation (com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfileLocation)1 UpdateEndpointRequest (com.amazonaws.services.pinpoint.model.UpdateEndpointRequest)1 MissingResourceException (java.util.MissingResourceException)1