try { data.put(NavigateToLinkInteraction.KEY_URL, interaction.getUrl()); data.put(NavigateToLinkInteraction.KEY_TARGET, interaction.getTarget().lowercaseName()); data.put(NavigateToLinkInteraction.EVENT_KEY_SUCCESS, success); } catch (Exception e) {
public static Target parse(String value) { if (value != null) { try { for (Target target : Target.values()) { // "new" is a reserved keyword, so perform a case-insensitive match. if (target.name().equalsIgnoreCase(value)) { return target; } } } catch (Exception e) { // Happens for values introduced after this version of the SDK. } } return New; } }
public String lowercaseName() { return name().toLowerCase(Locale.US); }
@Test public void navigateToLinkInteractionMissing() { String json = loadTextAssetAsString(TEST_DATA_DIR + "/testNavigateToLinkInteractionMissing.json"); Interaction interaction = Interaction.Factory.parseInteraction(json); assertTrue(interaction.getType().equals(Interaction.Type.NavigateToLink)); NavigateToLinkInteraction link = (NavigateToLinkInteraction) interaction; assertEquals("http://pages.ebay.com/link/?nav=item.view&id=221648890812", link.getUrl()); assertTrue(link.getTarget().equals(NavigateToLinkInteraction.Target.New)); } }
@Test public void navigateToLinkInteractionSelf() { String json = loadTextAssetAsString(TEST_DATA_DIR + "/testNavigateToLinkInteractionSelf.json"); Interaction interaction = Interaction.Factory.parseInteraction(json); assertTrue(interaction.getType().equals(Interaction.Type.NavigateToLink)); NavigateToLinkInteraction link = (NavigateToLinkInteraction) interaction; assertEquals("http://pages.ebay.com/link/?nav=item.view&id=221648890812", link.getUrl()); assertTrue(link.getTarget().equals(NavigateToLinkInteraction.Target.Self)); }
@Test public void navigateToLinkInteractionNew() { String json = loadTextAssetAsString(TEST_DATA_DIR + "/testNavigateToLinkInteractionNew.json"); Interaction interaction = Interaction.Factory.parseInteraction(json); assertTrue(interaction.getType().equals(Interaction.Type.NavigateToLink)); NavigateToLinkInteraction link = (NavigateToLinkInteraction) interaction; assertEquals("http://pages.ebay.com/link/?nav=item.view&id=221648890812", link.getUrl()); assertTrue(link.getTarget().equals(NavigateToLinkInteraction.Target.New)); }
public Target getTarget() { InteractionConfiguration configuration = getConfiguration(); if (configuration != null && !configuration.isNull(KEY_TARGET)) { return Target.parse(configuration.optString(KEY_TARGET, null)); } return Target.New; }