use of com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent in project aws-sdk-android by aws-amplify.
the class AmazonMonetizationEventBuilderTest method verifyMonetizationEvent.
private static void verifyMonetizationEvent(AmazonMonetizationEventBuilder builder, boolean successfulBuild, String productId, String formattedPrice, Double quantity, String currency, Double itemPrice) {
if (productId != null) {
builder.setProductId(productId);
}
if (formattedPrice != null) {
builder.setFormattedItemPrice(formattedPrice);
}
if (quantity != null) {
builder.setQuantity(quantity);
}
if (currency != null) {
builder.setCurrency(currency);
}
if (itemPrice != null) {
builder.setItemPrice(itemPrice);
}
AnalyticsEvent purchaseEvent = builder.build();
if (successfulBuild) {
assertThat(purchaseEvent, is(not(nullValue())));
assertThat(purchaseEvent.getEventType(), is(MonetizationEventBuilder.PURCHASE_EVENT_NAME));
Map<String, String> attributes = purchaseEvent.getAllAttributes();
assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_PRODUCT_ID_ATTR), is(productId));
assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_TRANSACTION_ID_ATTR), is(nullValue()));
assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_STORE_ATTR), is(MonetizationEventBuilder.AMAZON_STORE));
Map<String, Double> metrics = purchaseEvent.getAllMetrics();
assertThat(metrics.get(MonetizationEventBuilder.PURCHASE_EVENT_QUANTITY_METRIC).doubleValue(), is(quantity));
if (currency == null || itemPrice == null) {
assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_PRICE_FORMATTED_ATTR), is(formattedPrice));
}
} else {
assertThat(purchaseEvent, is(nullValue()));
}
}
use of com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent in project aws-sdk-android by aws-amplify.
the class CustomMonetizationEventBuilderTest method verifyMonetizationEvent.
private static void verifyMonetizationEvent(CustomMonetizationEventBuilder builder, boolean successfulBuild, String store, String productId, Double quantity, String formattedPrice, Double itemPrice, String currency, String transactionId) {
if (store != null) {
builder.setStore(store);
}
if (productId != null) {
builder.setProductId(productId);
}
if (quantity != null) {
builder.setQuantity(quantity);
}
if (formattedPrice != null) {
builder.setFormattedItemPrice(formattedPrice);
}
if (itemPrice != null) {
builder.setItemPrice(itemPrice);
}
if (currency != null) {
builder.setCurrency(currency);
}
if (transactionId != null) {
builder.setTransactionId(transactionId);
}
AnalyticsEvent purchaseEvent = builder.build();
if (successfulBuild) {
assertThat(purchaseEvent, is(not(nullValue())));
assertThat(purchaseEvent.getEventType(), is(MonetizationEventBuilder.PURCHASE_EVENT_NAME));
Map<String, String> attributes = purchaseEvent.getAllAttributes();
assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_STORE_ATTR), is(store));
assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_PRODUCT_ID_ATTR), is(productId));
if (currency != null) {
assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_CURRENCY_ATTR), is(currency));
} else {
assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_CURRENCY_ATTR), is(nullValue()));
}
if (formattedPrice != null) {
assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_PRICE_FORMATTED_ATTR), is(formattedPrice));
} else {
assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_PRICE_FORMATTED_ATTR), is(nullValue()));
}
if (transactionId != null) {
assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_TRANSACTION_ID_ATTR), is(transactionId));
} else {
assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_TRANSACTION_ID_ATTR), is(nullValue()));
}
Map<String, Double> metrics = purchaseEvent.getAllMetrics();
assertThat(metrics.get(MonetizationEventBuilder.PURCHASE_EVENT_QUANTITY_METRIC).doubleValue(), is(quantity));
if (itemPrice != null) {
assertThat(metrics.get(MonetizationEventBuilder.PURCHASE_EVENT_ITEM_PRICE_METRIC).doubleValue(), is(itemPrice));
} else {
assertThat(metrics.get(MonetizationEventBuilder.PURCHASE_EVENT_ITEM_PRICE_METRIC), is(nullValue()));
}
} else {
assertThat(purchaseEvent, is(nullValue()));
}
}
use of com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent in project aws-sdk-android by aws-amplify.
the class GooglePlayMonetizationEventBuilderTest method verifyMonetizationEvent.
private static void verifyMonetizationEvent(GooglePlayMonetizationEventBuilder builder, boolean successfulBuild, String productId, String currency, Double quantity, String transactionId, Double itemPrice) {
if (productId != null) {
builder.setProductId(productId);
}
if (currency != null) {
builder.setCurrency(currency);
}
if (quantity != null) {
builder.setQuantity(quantity);
}
if (itemPrice != null) {
builder.setItemPrice(itemPrice);
}
if (transactionId != null) {
builder.setTransactionId(transactionId);
}
AnalyticsEvent purchaseEvent = builder.build();
if (successfulBuild) {
assertThat(purchaseEvent, is(not(nullValue())));
assertThat(purchaseEvent.getEventType(), is(MonetizationEventBuilder.PURCHASE_EVENT_NAME));
Map<String, String> attributes = purchaseEvent.getAllAttributes();
assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_PRODUCT_ID_ATTR), is(productId));
assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_TRANSACTION_ID_ATTR), is(transactionId));
assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_STORE_ATTR), is(MonetizationEventBuilder.GOOGLE_PLAY_STORE));
assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_CURRENCY_ATTR), is(not(nullValue())));
Map<String, Double> metrics = purchaseEvent.getAllMetrics();
assertThat(metrics.get(MonetizationEventBuilder.PURCHASE_EVENT_QUANTITY_METRIC).doubleValue(), is(quantity));
assertThat(metrics.get(MonetizationEventBuilder.PURCHASE_EVENT_ITEM_PRICE_METRIC), is(not(nullValue())));
} else {
assertThat(purchaseEvent, is(nullValue()));
}
}
use of com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent 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.analytics.AnalyticsEvent in project aws-sdk-android by aws-amplify.
the class MonetizationEventBuilder method build.
/**
* Builds a monetization event.
*
* @return A monetization event that can be recorded. If the builder is in
* an invalid state, this method returns null.
*/
public AnalyticsEvent build() {
AnalyticsEvent purchaseEvent = null;
if (isValid() && doBaseValidation()) {
purchaseEvent = analyticsClient.createEvent(PURCHASE_EVENT_NAME);
purchaseEvent.addAttribute(PURCHASE_EVENT_PRODUCT_ID_ATTR, productId);
purchaseEvent.addAttribute(PURCHASE_EVENT_STORE_ATTR, store);
purchaseEvent.addMetric(PURCHASE_EVENT_QUANTITY_METRIC, quantity);
if (formattedItemPrice != null) {
purchaseEvent.addAttribute(PURCHASE_EVENT_PRICE_FORMATTED_ATTR, formattedItemPrice);
}
if (itemPrice != null) {
purchaseEvent.addMetric(PURCHASE_EVENT_ITEM_PRICE_METRIC, itemPrice);
}
if (transactionId != null) {
purchaseEvent.addAttribute(PURCHASE_EVENT_TRANSACTION_ID_ATTR, transactionId);
}
if (currency != null) {
purchaseEvent.addAttribute(PURCHASE_EVENT_CURRENCY_ATTR, currency);
}
}
return purchaseEvent;
}
Aggregations