@Test public void testCommerceCustomMapping() throws Exception { String cmEventName = "test_content_view"; String cmQuantityName = "test_quantity"; String cmProductName = "test_content_quantity"; String cmCurrencyName = "test_currency"; String cmStaticCurrency = "USD"; Map<String, String> customAttributes = new HashMap<>(); customAttributes.put("customAttribute1", "value1"); customAttributes.put("customAttribute2", "value2"); String name = "product_1"; String sku = "sku_12345"; float quantity = 3; KitConfiguration kitConfiguration = MockKitConfiguration.createKitConfiguration(new JSONObject("{ \"id\":92, \"as\":{ \"devKey\":\"HXpL4jHPTkUzwmcrJJFV9k\", \"appleAppId\":null }, \"hs\":{ }, \"pr\":[ { \"id\":166, \"behavior\":{ \"append_unmapped_as_is\":true, \"is_default\":true }, \"action\":{ \"projected_event_name\":\"\", \"attribute_maps\":[ ], \"outbound_message_type\":4 }, \"matches\":[ { \"message_type\":4, \"event_match_type\":\"\", \"event\":\"\" } ] }, { \"id\":157, \"pmid\":540, \"behavior\":{ \"append_unmapped_as_is\":true }, \"action\":{ \"projected_event_name\":\"" + cmEventName + "\", \"attribute_maps\":[ { \"projected_attribute_name\":\"" + cmProductName + "\", \"match_type\":\"Hash\", \"value\":\"1455148719\", \"data_type\":\"String\", \"property\":\"ProductField\" }, { \"projected_attribute_name\":\"" + cmQuantityName + "\", \"match_type\":\"Hash\", \"value\":\"1817448224\", \"data_type\":\"Float\", \"property\":\"ProductField\" }, { \"projected_attribute_name\":\"" + cmCurrencyName + "\", \"match_type\":\"Static\", \"value\":\"" + cmStaticCurrency + "\", \"data_type\":\"String\" } ], \"outbound_message_type\":4 }, \"matches\":[ { \"message_type\":16, \"event_match_type\":\"Hash\", \"event\":\"1572\" } ] } ] }")); Product product = new Product.Builder(name, sku, quantity) .build(); CommerceEvent commerceEvent = new CommerceEvent.Builder(Product.DETAIL, product) .customAttributes(customAttributes) .build(); List<CustomMapping.ProjectionResult> results = CustomMapping.projectEvents(commerceEvent, kitConfiguration.getCustomMappingList(), null); Map<String, String> expectedInfo = new HashMap<>(); expectedInfo.put(cmQuantityName, String.valueOf(quantity)); expectedInfo.put(cmProductName, name); expectedInfo.put(cmCurrencyName, cmStaticCurrency); expectedInfo.putAll(customAttributes); MPEvent expectedMappedEvent = new MPEvent.Builder(cmEventName) .customAttributes(expectedInfo) .build(); assertEquals(1, results.size()); MPEvent result = results.get(0).getMPEvent(); assertEquals(expectedMappedEvent.getEventName(), result.getEventName()); assertEquals(expectedMappedEvent.getCustomAttributes().keySet().size(), result.getCustomAttributes().size()); for (String key: expectedMappedEvent.getCustomAttributes().keySet()) { String val = result.getCustomAttributes().get(key); assertTrue(val != null); assertEquals(expectedMappedEvent.getCustomAttributes().get(key), val); } }
public static List<CustomMapping.ProjectionResult> projectEvents(MPEvent event, List<CustomMapping> customMappingList, CustomMapping defaultCustomMapping) { return projectEvents(event, false, customMappingList, defaultCustomMapping, null); }
CustomMapping { public static List<CustomMapping.ProjectionResult> projectEvents(MPEvent event, List<CustomMapping> customMappingList, CustomMapping defaultCustomMapping) { return projectEvents(event, false, customMappingList, defaultCustomMapping, null); } }
CustomMapping { public static List<CustomMapping.ProjectionResult> projectEvents(MPEvent event, List<CustomMapping> customMappingList, CustomMapping defaultCustomMapping) { return projectEvents(event, false, customMappingList, defaultCustomMapping, null); } CustomMapping(JSONObject projectionJson); }
CustomMapping { public static List<CustomMapping.ProjectionResult> projectEvents(MPEvent event, List<CustomMapping> customMappingList, CustomMapping defaultCustomMapping) { return projectEvents(event, false, customMappingList, defaultCustomMapping, null); } CustomMapping(JSONObject projectionJson); List<CustomMappingMatch> getMatchList(); boolean isDefault(); List<ProjectionResult> project(EventWrapper.CommerceEventWrapper commerceEventWrapper); List<ProjectionResult> project(EventWrapper.MPEventWrapper event); int getMessageType(); static List<CustomMapping.ProjectionResult> projectEvents(MPEvent event, List<CustomMapping> customMappingList, CustomMapping defaultCustomMapping); static List<CustomMapping.ProjectionResult> projectEvents(CommerceEvent event, List<CustomMapping> customMappingList, CustomMapping defaultCommerceCustomMapping); static List<CustomMapping.ProjectionResult> projectEvents(MPEvent event, boolean isScreenEvent, List<CustomMapping> customMappingList, CustomMapping defaultCustomMapping, CustomMapping defaultScreenCustomMapping); }
CustomMapping { public static List<CustomMapping.ProjectionResult> projectEvents(MPEvent event, List<CustomMapping> customMappingList, CustomMapping defaultCustomMapping) { return projectEvents(event, false, customMappingList, defaultCustomMapping, null); } CustomMapping(JSONObject projectionJson); List<CustomMappingMatch> getMatchList(); boolean isDefault(); List<ProjectionResult> project(EventWrapper.CommerceEventWrapper commerceEventWrapper); List<ProjectionResult> project(EventWrapper.MPEventWrapper event); int getMessageType(); static List<CustomMapping.ProjectionResult> projectEvents(MPEvent event, List<CustomMapping> customMappingList, CustomMapping defaultCustomMapping); static List<CustomMapping.ProjectionResult> projectEvents(CommerceEvent event, List<CustomMapping> customMappingList, CustomMapping defaultCommerceCustomMapping); static List<CustomMapping.ProjectionResult> projectEvents(MPEvent event, boolean isScreenEvent, List<CustomMapping> customMappingList, CustomMapping defaultCustomMapping, CustomMapping defaultScreenCustomMapping); final static String PROPERTY_LOCATION_EVENT_FIELD; final static String PROPERTY_LOCATION_EVENT_ATTRIBUTE; final static String PROPERTY_LOCATION_PRODUCT_FIELD; final static String PROPERTY_LOCATION_PRODUCT_ATTRIBUTE; final static String PROPERTY_LOCATION_PROMOTION_FIELD; }