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