@Test public void testPerformMCRAP() throws JSONException { Map map = new HashMap(); map.put(CustomEvent.EVENT_NAME, "event name"); Bundle metadata = new Bundle(); metadata.putString(ActionArguments.RICH_PUSH_ID_METADATA, "message id"); ActionArguments args = ActionTestUtils.createArgs(Action.SITUATION_MANUAL_INVOCATION, map, metadata); ActionResult result = action.perform(args); assertEquals("Action should've completed", ActionResult.STATUS_COMPLETED, result.getStatus()); ArgumentCaptor<CustomEvent> argumentCaptor = ArgumentCaptor.forClass(CustomEvent.class); verify(analytics).addEvent(argumentCaptor.capture()); CustomEvent event = argumentCaptor.getValue(); EventTestUtils.validateEventValue(event, CustomEvent.EVENT_NAME, "event name"); EventTestUtils.validateEventValue(event, CustomEvent.INTERACTION_TYPE, "ua_mcrap"); EventTestUtils.validateEventValue(event, CustomEvent.INTERACTION_ID, "message id"); }
@NonNull @Override public ActionResult perform(@NonNull ActionArguments arguments) { JsonMap customEventMap = arguments.getValue().toJsonValue().optMap(); String eventName = customEventMap.opt(CustomEvent.EVENT_NAME).getString(); Checks.checkNotNull(eventName, "Missing event name"); String eventStringValue = customEventMap.opt(CustomEvent.EVENT_VALUE).getString(); double eventDoubleValue = customEventMap.opt(CustomEvent.EVENT_VALUE).getDouble(0); String transactionId = customEventMap.opt(CustomEvent.TRANSACTION_ID).getString(); String interactionType = customEventMap.opt(CustomEvent.INTERACTION_TYPE).getString(); String interactionId = customEventMap.opt(CustomEvent.INTERACTION_ID).getString(); JsonMap properties = customEventMap.opt(CustomEvent.PROPERTIES).getMap(); CustomEvent.Builder eventBuilder = CustomEvent.newBuilder(eventName) .setTransactionId(transactionId) .setAttribution((PushMessage) arguments.getMetadata().getParcelable(ActionArguments.PUSH_MESSAGE_METADATA)) .setInteraction(interactionType, interactionId); if (eventStringValue != null) { eventBuilder.setEventValue(eventStringValue); } else { eventBuilder.setEventValue(eventDoubleValue); } if (interactionId == null && interactionType == null) { String messageId = arguments.getMetadata().getString(ActionArguments.RICH_PUSH_ID_METADATA); if (messageId != null) { eventBuilder.setMessageCenterInteraction(messageId); } } if (properties != null) { eventBuilder.setProperties(properties); } CustomEvent event = eventBuilder.build(); event.track(); if (event.isValid()) { return ActionResult.newEmptyResult(); } else { return ActionResult.newErrorResult(new IllegalArgumentException("Unable to add custom event. Event is invalid.")); } }
AddCustomEventAction extends Action { @NonNull @Override public ActionResult perform(@NonNull ActionArguments arguments) { JsonMap customEventMap = arguments.getValue().toJsonValue().optMap(); String eventName = customEventMap.opt(CustomEvent.EVENT_NAME).getString(); Checks.checkNotNull(eventName, "Missing event name"); String eventStringValue = customEventMap.opt(CustomEvent.EVENT_VALUE).getString(); double eventDoubleValue = customEventMap.opt(CustomEvent.EVENT_VALUE).getDouble(0); String transactionId = customEventMap.opt(CustomEvent.TRANSACTION_ID).getString(); String interactionType = customEventMap.opt(CustomEvent.INTERACTION_TYPE).getString(); String interactionId = customEventMap.opt(CustomEvent.INTERACTION_ID).getString(); JsonMap properties = customEventMap.opt(CustomEvent.PROPERTIES).getMap(); CustomEvent.Builder eventBuilder = CustomEvent.newBuilder(eventName) .setTransactionId(transactionId) .setAttribution((PushMessage) arguments.getMetadata().getParcelable(ActionArguments.PUSH_MESSAGE_METADATA)) .setInteraction(interactionType, interactionId); if (eventStringValue != null) { eventBuilder.setEventValue(eventStringValue); } else { eventBuilder.setEventValue(eventDoubleValue); } if (interactionId == null && interactionType == null) { String messageId = arguments.getMetadata().getString(ActionArguments.RICH_PUSH_ID_METADATA); if (messageId != null) { eventBuilder.setMessageCenterInteraction(messageId); } } if (properties != null) { eventBuilder.setProperties(properties); } CustomEvent event = eventBuilder.build(); event.track(); if (event.isValid()) { return ActionResult.newEmptyResult(); } else { return ActionResult.newErrorResult(new IllegalArgumentException("Unable to add custom event. Event is invalid.")); } } }
AddCustomEventAction extends Action { @NonNull @Override public ActionResult perform(@NonNull ActionArguments arguments) { JsonMap customEventMap = arguments.getValue().toJsonValue().optMap(); String eventName = customEventMap.opt(CustomEvent.EVENT_NAME).getString(); Checks.checkNotNull(eventName, "Missing event name"); String eventStringValue = customEventMap.opt(CustomEvent.EVENT_VALUE).getString(); double eventDoubleValue = customEventMap.opt(CustomEvent.EVENT_VALUE).getDouble(0); String transactionId = customEventMap.opt(CustomEvent.TRANSACTION_ID).getString(); String interactionType = customEventMap.opt(CustomEvent.INTERACTION_TYPE).getString(); String interactionId = customEventMap.opt(CustomEvent.INTERACTION_ID).getString(); JsonMap properties = customEventMap.opt(CustomEvent.PROPERTIES).getMap(); CustomEvent.Builder eventBuilder = CustomEvent.newBuilder(eventName) .setTransactionId(transactionId) .setAttribution((PushMessage) arguments.getMetadata().getParcelable(ActionArguments.PUSH_MESSAGE_METADATA)) .setInteraction(interactionType, interactionId); if (eventStringValue != null) { eventBuilder.setEventValue(eventStringValue); } else { eventBuilder.setEventValue(eventDoubleValue); } if (interactionId == null && interactionType == null) { String messageId = arguments.getMetadata().getString(ActionArguments.RICH_PUSH_ID_METADATA); if (messageId != null) { eventBuilder.setMessageCenterInteraction(messageId); } } if (properties != null) { eventBuilder.setProperties(properties); } CustomEvent event = eventBuilder.build(); event.track(); if (event.isValid()) { return ActionResult.newEmptyResult(); } else { return ActionResult.newErrorResult(new IllegalArgumentException("Unable to add custom event. Event is invalid.")); } }  }
AddCustomEventAction extends Action { @NonNull @Override public ActionResult perform(@NonNull ActionArguments arguments) { JsonMap customEventMap = arguments.getValue().toJsonValue().optMap(); String eventName = customEventMap.opt(CustomEvent.EVENT_NAME).getString(); Checks.checkNotNull(eventName, "Missing event name"); String eventStringValue = customEventMap.opt(CustomEvent.EVENT_VALUE).getString(); double eventDoubleValue = customEventMap.opt(CustomEvent.EVENT_VALUE).getDouble(0); String transactionId = customEventMap.opt(CustomEvent.TRANSACTION_ID).getString(); String interactionType = customEventMap.opt(CustomEvent.INTERACTION_TYPE).getString(); String interactionId = customEventMap.opt(CustomEvent.INTERACTION_ID).getString(); JsonMap properties = customEventMap.opt(CustomEvent.PROPERTIES).getMap(); CustomEvent.Builder eventBuilder = CustomEvent.newBuilder(eventName) .setTransactionId(transactionId) .setAttribution((PushMessage) arguments.getMetadata().getParcelable(ActionArguments.PUSH_MESSAGE_METADATA)) .setInteraction(interactionType, interactionId); if (eventStringValue != null) { eventBuilder.setEventValue(eventStringValue); } else { eventBuilder.setEventValue(eventDoubleValue); } if (interactionId == null && interactionType == null) { String messageId = arguments.getMetadata().getString(ActionArguments.RICH_PUSH_ID_METADATA); if (messageId != null) { eventBuilder.setMessageCenterInteraction(messageId); } } if (properties != null) { eventBuilder.setProperties(properties); } CustomEvent event = eventBuilder.build(); event.track(); if (event.isValid()) { return ActionResult.newEmptyResult(); } else { return ActionResult.newErrorResult(new IllegalArgumentException("Unable to add custom event. Event is invalid.")); } }  @NonNull @Override ActionResult perform(@NonNull ActionArguments arguments); @Override boolean acceptsArguments(@NonNull ActionArguments arguments); }
AddCustomEventAction extends Action { @NonNull @Override public ActionResult perform(@NonNull ActionArguments arguments) { JsonMap customEventMap = arguments.getValue().toJsonValue().optMap(); String eventName = customEventMap.opt(CustomEvent.EVENT_NAME).getString(); Checks.checkNotNull(eventName, "Missing event name"); String eventStringValue = customEventMap.opt(CustomEvent.EVENT_VALUE).getString(); double eventDoubleValue = customEventMap.opt(CustomEvent.EVENT_VALUE).getDouble(0); String transactionId = customEventMap.opt(CustomEvent.TRANSACTION_ID).getString(); String interactionType = customEventMap.opt(CustomEvent.INTERACTION_TYPE).getString(); String interactionId = customEventMap.opt(CustomEvent.INTERACTION_ID).getString(); JsonMap properties = customEventMap.opt(CustomEvent.PROPERTIES).getMap(); CustomEvent.Builder eventBuilder = CustomEvent.newBuilder(eventName) .setTransactionId(transactionId) .setAttribution((PushMessage) arguments.getMetadata().getParcelable(ActionArguments.PUSH_MESSAGE_METADATA)) .setInteraction(interactionType, interactionId); if (eventStringValue != null) { eventBuilder.setEventValue(eventStringValue); } else { eventBuilder.setEventValue(eventDoubleValue); } if (interactionId == null && interactionType == null) { String messageId = arguments.getMetadata().getString(ActionArguments.RICH_PUSH_ID_METADATA); if (messageId != null) { eventBuilder.setMessageCenterInteraction(messageId); } } if (properties != null) { eventBuilder.setProperties(properties); } CustomEvent event = eventBuilder.build(); event.track(); if (event.isValid()) { return ActionResult.newEmptyResult(); } else { return ActionResult.newErrorResult(new IllegalArgumentException("Unable to add custom event. Event is invalid.")); } }  @NonNull @Override ActionResult perform(@NonNull ActionArguments arguments); @Override boolean acceptsArguments(@NonNull ActionArguments arguments); @NonNull
    static final String DEFAULT_REGISTRY_NAME; }