Skip to content

Commit

Permalink
Use Constants from Core and add friendly name (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
prudrabhat authored Dec 16, 2022
1 parent afebb93 commit fd3214d
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.adobe.marketing.mobile.Event;
import com.adobe.marketing.mobile.EventSource;
import com.adobe.marketing.mobile.EventType;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.edge.identity.util.MonitorExtension;
import com.adobe.marketing.mobile.edge.identity.util.TestPersistenceHelper;
Expand Down Expand Up @@ -316,7 +318,7 @@ public void testGenericIdentityRequest_whenNoAdId_thenAllZerosAdIdTwice() throws
* APIs are properly dispatched. Verifies:
* 1. Event type and source
* 2. Event data/properties as required for proper ad ID functionality
* @param isGenericIdentityEventAdIdEvent true if the expected {@link com.adobe.marketing.mobile.edge.identity.IdentityConstants.EventType#GENERIC_IDENTITY}
* @param isGenericIdentityEventAdIdEvent true if the expected {@link EventType#GENERIC_IDENTITY}
* event should be an ad ID event, false otherwise
* @param expectedConsentValue the expected consent value in the format {@link IdentityConstants.XDMKeys.Consent#YES}
* or {@link IdentityConstants.XDMKeys.Consent#NO}; however, if consent event should not be dispatched, use null
Expand All @@ -326,18 +328,15 @@ private void verifyDispatchedEvents(boolean isGenericIdentityEventAdIdEvent, Str
throws Exception {
// Check the event type and source
List<Event> dispatchedGenericIdentityEvents = getDispatchedEventsWith(
IdentityConstants.EventType.GENERIC_IDENTITY,
IdentityConstants.EventSource.REQUEST_CONTENT
EventType.GENERIC_IDENTITY,
EventSource.REQUEST_CONTENT
);
// Verify Generic Identity event
assertEquals(1, dispatchedGenericIdentityEvents.size());
Event genericIdentityEvent = dispatchedGenericIdentityEvents.get(0);
assertEquals(isGenericIdentityEventAdIdEvent, EventUtils.isAdIdEvent(genericIdentityEvent));
// Verify Edge Consent event
List<Event> dispatchedConsentEvents = getDispatchedEventsWith(
IdentityConstants.EventType.EDGE_CONSENT,
IdentityConstants.EventSource.UPDATE_CONSENT
);
List<Event> dispatchedConsentEvents = getDispatchedEventsWith(EventType.CONSENT, EventSource.UPDATE_CONSENT);
assertEquals(StringUtils.isNullOrEmpty(expectedConsentValue) ? 0 : 1, dispatchedConsentEvents.size());
if (!StringUtils.isNullOrEmpty(expectedConsentValue)) {
Map<String, String> consentDataMap = flattenMap(dispatchedConsentEvents.get(0).getEventData());
Expand Down Expand Up @@ -372,17 +371,17 @@ private void verifyFlatIdentityMap(
}

/**
* Dispatches an event using the MobileCore dispatchEvent API. Event has type {@link com.adobe.marketing.mobile.edge.identity.IdentityConstants.EventType#GENERIC_IDENTITY}
* and source {@link com.adobe.marketing.mobile.edge.identity.IdentityConstants.EventSource#REQUEST_CONTENT}.
* Dispatches an event using the MobileCore dispatchEvent API. Event has type {@link EventType#GENERIC_IDENTITY}
* and source {@link EventSource#REQUEST_CONTENT}.
* This is the combination of event type and source that the ad ID listener will capture, and this
* method helps set up test cases that verify the ad ID is not modified if the advertisingIdentifier
* property is not present in the correct format
*/
private void dispatchGenericIdentityNonAdIdEvent() {
Event genericIdentityNonAdIdEvent = new Event.Builder(
"Test event",
IdentityConstants.EventType.GENERIC_IDENTITY,
IdentityConstants.EventSource.REQUEST_CONTENT
EventType.GENERIC_IDENTITY,
EventSource.REQUEST_CONTENT
)
.setEventData(
new HashMap<String, Object>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.adobe.marketing.mobile.Event;
import com.adobe.marketing.mobile.EventSource;
import com.adobe.marketing.mobile.EventType;
import com.adobe.marketing.mobile.edge.identity.util.IdentityTestConstants;
import com.adobe.marketing.mobile.edge.identity.util.MonitorExtension;
import com.adobe.marketing.mobile.edge.identity.util.TestPersistenceHelper;
Expand Down Expand Up @@ -112,10 +114,7 @@ public void testUpdateAPI_nullData() throws Exception {
waitForThreads(2000);

// verify no shares state change event dispatched
List<Event> dispatchedEvents = getDispatchedEventsWith(
IdentityConstants.EventType.HUB,
IdentityConstants.EventSource.SHARED_STATE
);
List<Event> dispatchedEvents = getDispatchedEventsWith(EventType.HUB, EventSource.SHARED_STATE);
assertEquals(0, dispatchedEvents.size());

// verify xdm shared state is not disturbed
Expand All @@ -131,10 +130,7 @@ public void testUpdateAPI_emptyData() throws Exception {
waitForThreads(2000);

// verify no shares state change event dispatched
List<Event> dispatchedEvents = getDispatchedEventsWith(
IdentityConstants.EventType.HUB,
IdentityConstants.EventSource.SHARED_STATE
);
List<Event> dispatchedEvents = getDispatchedEventsWith(EventType.HUB, EventSource.SHARED_STATE);
assertEquals(0, dispatchedEvents.size());

// verify xdm shared state is not disturbed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import static org.junit.Assert.*;

import com.adobe.marketing.mobile.Event;
import com.adobe.marketing.mobile.EventSource;
import com.adobe.marketing.mobile.EventType;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.edge.identity.util.MonitorExtension;
import com.adobe.marketing.mobile.edge.identity.util.TestPersistenceHelper;
Expand Down Expand Up @@ -67,10 +69,7 @@ public void testReset_ClearsAllIDAndDispatchesResetComplete() throws Exception {
assertNotEquals(beforeResetECID, newECID);

// verify edge reset complete event dispatched
List<Event> resetCompleteEvent = getDispatchedEventsWith(
IdentityConstants.EventType.EDGE_IDENTITY,
IdentityConstants.EventSource.RESET_COMPLETE
);
List<Event> resetCompleteEvent = getDispatchedEventsWith(EventType.EDGE_IDENTITY, EventSource.RESET_COMPLETE);
assertEquals(1, resetCompleteEvent.size());

// verify shared state is updated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.adobe.marketing.mobile.AdobeCallbackWithError;
import com.adobe.marketing.mobile.AdobeError;
import com.adobe.marketing.mobile.Event;
import com.adobe.marketing.mobile.EventSource;
import com.adobe.marketing.mobile.EventType;
import com.adobe.marketing.mobile.Extension;
import com.adobe.marketing.mobile.ExtensionError;
import com.adobe.marketing.mobile.ExtensionErrorCallback;
Expand Down Expand Up @@ -86,8 +88,8 @@ public static void getExperienceCloudId(final AdobeCallback<String> callback) {

final Event event = new Event.Builder(
IdentityConstants.EventNames.IDENTITY_REQUEST_IDENTITY_ECID,
IdentityConstants.EventType.EDGE_IDENTITY,
IdentityConstants.EventSource.REQUEST_IDENTITY
EventType.EDGE_IDENTITY,
EventSource.REQUEST_IDENTITY
)
.build();

Expand Down Expand Up @@ -169,8 +171,8 @@ public static void getUrlVariables(final AdobeCallback<String> callback) {

final Event event = new Event.Builder(
IdentityConstants.EventNames.IDENTITY_REQUEST_URL_VARIABLES,
IdentityConstants.EventType.EDGE_IDENTITY,
IdentityConstants.EventSource.REQUEST_IDENTITY
EventType.EDGE_IDENTITY,
EventSource.REQUEST_IDENTITY
)
.setEventData(
new HashMap<String, Object>() {
Expand Down Expand Up @@ -237,8 +239,8 @@ public static void updateIdentities(final IdentityMap identityMap) {

final Event updateIdentitiesEvent = new Event.Builder(
IdentityConstants.EventNames.UPDATE_IDENTITIES,
IdentityConstants.EventType.EDGE_IDENTITY,
IdentityConstants.EventSource.UPDATE_IDENTITY
EventType.EDGE_IDENTITY,
EventSource.UPDATE_IDENTITY
)
.setEventData(identityMap.asXDMMap(false))
.build();
Expand Down Expand Up @@ -269,8 +271,8 @@ public static void removeIdentity(final IdentityItem item, final String namespac

final Event removeIdentitiesEvent = new Event.Builder(
IdentityConstants.EventNames.REMOVE_IDENTITIES,
IdentityConstants.EventType.EDGE_IDENTITY,
IdentityConstants.EventSource.REMOVE_IDENTITY
EventType.EDGE_IDENTITY,
EventSource.REMOVE_IDENTITY
)
.setEventData(identityMap.asXDMMap(false))
.build();
Expand All @@ -296,8 +298,8 @@ public static void getIdentities(final AdobeCallback<IdentityMap> callback) {

final Event event = new Event.Builder(
IdentityConstants.EventNames.REQUEST_IDENTITIES,
IdentityConstants.EventType.EDGE_IDENTITY,
IdentityConstants.EventSource.REQUEST_IDENTITY
EventType.EDGE_IDENTITY,
EventSource.REQUEST_IDENTITY
)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ final class IdentityConstants {

static final String LOG_TAG = "EdgeIdentity";
static final String EXTENSION_NAME = "com.adobe.edge.identity";
static final String EXTENSION_FRIENDLY_NAME = "Edge Identity";
static final String EXTENSION_VERSION = "2.0.0";

static final class Default {
Expand All @@ -24,32 +25,6 @@ static final class Default {
private Default() {}
}

static final class EventSource {

static final String REMOVE_IDENTITY = "com.adobe.eventSource.removeIdentity";
static final String REQUEST_CONTENT = "com.adobe.eventSource.requestContent";
static final String REQUEST_IDENTITY = "com.adobe.eventSource.requestIdentity";
static final String REQUEST_RESET = "com.adobe.eventSource.requestReset";
static final String RESET_COMPLETE = "com.adobe.eventSource.resetComplete";
static final String RESPONSE_IDENTITY = "com.adobe.eventSource.responseIdentity";
static final String SHARED_STATE = "com.adobe.eventSource.sharedState";
static final String UPDATE_CONSENT = "com.adobe.eventSource.updateConsent";
static final String UPDATE_IDENTITY = "com.adobe.eventSource.updateIdentity";

private EventSource() {}
}

static final class EventType {

static final String EDGE_CONSENT = "com.adobe.eventType.edgeConsent";
static final String EDGE_IDENTITY = "com.adobe.eventType.edgeIdentity";
static final String GENERIC_IDENTITY = "com.adobe.eventType.generic.identity";
static final String HUB = "com.adobe.eventType.hub";
static final String IDENTITY = "com.adobe.eventType.identity";

private EventType() {}
}

static final class EventNames {

static final String CONSENT_UPDATE_REQUEST_AD_ID = "Consent Update Request for Ad ID";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.adobe.marketing.mobile.Event;
import com.adobe.marketing.mobile.EventSource;
import com.adobe.marketing.mobile.EventType;
import com.adobe.marketing.mobile.Extension;
import com.adobe.marketing.mobile.ExtensionApi;
import com.adobe.marketing.mobile.SharedStateResolution;
Expand Down Expand Up @@ -71,6 +73,11 @@ protected String getName() {
return IdentityConstants.EXTENSION_NAME;
}

@Override
protected String getFriendlyName() {
return IdentityConstants.EXTENSION_FRIENDLY_NAME;
}

@Override
protected String getVersion() {
return IdentityConstants.EXTENSION_VERSION;
Expand All @@ -82,13 +89,13 @@ protected String getVersion() {
* <p>
* The following listeners are registered during this extension's registration.
* <ul>
* <li> EventType {@link IdentityConstants.EventType#GENERIC_IDENTITY} and EventSource {@link IdentityConstants.EventSource#REQUEST_CONTENT}</li>
* <li> EventType {@link IdentityConstants.EventType#EDGE_IDENTITY} and EventSource {@link IdentityConstants.EventSource#REQUEST_IDENTITY}</li>
* <li> EventType {@link IdentityConstants.EventType#EDGE_IDENTITY} and EventSource {@link IdentityConstants.EventSource#UPDATE_IDENTITY}</li>
* <li> EventType {@link IdentityConstants.EventType#EDGE_IDENTITY} and EventSource {@link IdentityConstants.EventSource#REMOVE_IDENTITY}</li>
* <li> EventType {@link IdentityConstants.EventType#EDGE_IDENTITY} and EventSource {@link IdentityConstants.EventSource#REQUEST_CONTENT}</li>
* <li> EventType {@link IdentityConstants.EventType#GENERIC_IDENTITY} and EventSource {@link IdentityConstants.EventSource#REQUEST_RESET}</li>
* <li> EventType {@link IdentityConstants.EventType#HUB} and EventSource {@link IdentityConstants.EventSource#SHARED_STATE}</li>
* <li> EventType {@link EventType#GENERIC_IDENTITY} and EventSource {@link EventSource#REQUEST_CONTENT}</li>
* <li> EventType {@link EventType#EDGE_IDENTITY} and EventSource {@link EventSource#REQUEST_IDENTITY}</li>
* <li> EventType {@link EventType#EDGE_IDENTITY} and EventSource {@link EventSource#UPDATE_IDENTITY}</li>
* <li> EventType {@link EventType#EDGE_IDENTITY} and EventSource {@link EventSource#REMOVE_IDENTITY}</li>
* <li> EventType {@link EventType#EDGE_IDENTITY} and EventSource {@link EventSource#REQUEST_CONTENT}</li>
* <li> EventType {@link EventType#GENERIC_IDENTITY} and EventSource {@link EventSource#REQUEST_RESET}</li>
* <li> EventType {@link EventType#HUB} and EventSource {@link EventSource#SHARED_STATE}</li>
* </ul>
* </p>
*/
Expand All @@ -98,48 +105,22 @@ protected void onRegistered() {

// GENERIC_IDENTITY event listeners
getApi()
.registerEventListener(
IdentityConstants.EventType.GENERIC_IDENTITY,
IdentityConstants.EventSource.REQUEST_CONTENT,
this::handleRequestContent
);
.registerEventListener(EventType.GENERIC_IDENTITY, EventSource.REQUEST_CONTENT, this::handleRequestContent);

getApi()
.registerEventListener(
IdentityConstants.EventType.GENERIC_IDENTITY,
IdentityConstants.EventSource.REQUEST_RESET,
this::handleRequestReset
);
getApi().registerEventListener(EventType.GENERIC_IDENTITY, EventSource.REQUEST_RESET, this::handleRequestReset);

// EDGE_IDENTITY event listeners
getApi()
.registerEventListener(
IdentityConstants.EventType.EDGE_IDENTITY,
IdentityConstants.EventSource.REQUEST_IDENTITY,
this::handleRequestIdentity
);
.registerEventListener(EventType.EDGE_IDENTITY, EventSource.REQUEST_IDENTITY, this::handleRequestIdentity);

getApi()
.registerEventListener(
IdentityConstants.EventType.EDGE_IDENTITY,
IdentityConstants.EventSource.UPDATE_IDENTITY,
this::handleUpdateIdentities
);
.registerEventListener(EventType.EDGE_IDENTITY, EventSource.UPDATE_IDENTITY, this::handleUpdateIdentities);

getApi()
.registerEventListener(
IdentityConstants.EventType.EDGE_IDENTITY,
IdentityConstants.EventSource.REMOVE_IDENTITY,
this::handleRemoveIdentity
);
.registerEventListener(EventType.EDGE_IDENTITY, EventSource.REMOVE_IDENTITY, this::handleRemoveIdentity);

// HUB shared state event listener
getApi()
.registerEventListener(
IdentityConstants.EventType.HUB,
IdentityConstants.EventSource.SHARED_STATE,
this::handleIdentityDirectECIDUpdate
);
getApi().registerEventListener(EventType.HUB, EventSource.SHARED_STATE, this::handleIdentityDirectECIDUpdate);
}

@Override
Expand Down Expand Up @@ -243,8 +224,8 @@ private void handleUrlVariableResponse(
) {
Event responseEvent = new Event.Builder(
IdentityConstants.EventNames.IDENTITY_RESPONSE_URL_VARIABLES,
IdentityConstants.EventType.EDGE_IDENTITY,
IdentityConstants.EventSource.RESPONSE_IDENTITY
EventType.EDGE_IDENTITY,
EventSource.RESPONSE_IDENTITY
)
.setEventData(
new HashMap<String, Object>() {
Expand Down Expand Up @@ -328,8 +309,8 @@ private void handleGetIdentifiersRequest(@NonNull final Event event) {
final Map<String, Object> xdmData = state.getIdentityProperties().toXDMData(false);
final Event responseEvent = new Event.Builder(
IdentityConstants.EventNames.IDENTITY_RESPONSE_CONTENT_ONE_TIME,
IdentityConstants.EventType.EDGE_IDENTITY,
IdentityConstants.EventSource.RESPONSE_IDENTITY
EventType.EDGE_IDENTITY,
EventSource.RESPONSE_IDENTITY
)
.setEventData(xdmData)
.inResponseToEvent(event)
Expand All @@ -350,8 +331,8 @@ void handleRequestReset(@NonNull final Event event) {
// dispatch reset complete event
final Event responseEvent = new Event.Builder(
IdentityConstants.EventNames.RESET_IDENTITIES_COMPLETE,
IdentityConstants.EventType.EDGE_IDENTITY,
IdentityConstants.EventSource.RESET_COMPLETE
EventType.EDGE_IDENTITY,
EventSource.RESET_COMPLETE
)
.inResponseToEvent(event)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.adobe.marketing.mobile.Event;
import com.adobe.marketing.mobile.EventSource;
import com.adobe.marketing.mobile.EventType;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.SharedStateResult;
import com.adobe.marketing.mobile.SharedStateStatus;
Expand Down Expand Up @@ -326,8 +328,8 @@ private void dispatchAdIdConsentRequestEvent(final String consentVal) {

final Event consentEvent = new Event.Builder(
IdentityConstants.EventNames.CONSENT_UPDATE_REQUEST_AD_ID,
IdentityConstants.EventType.EDGE_CONSENT,
IdentityConstants.EventSource.UPDATE_CONSENT
EventType.CONSENT,
EventSource.UPDATE_CONSENT
)
.setEventData(consentData)
.build();
Expand Down
Loading

0 comments on commit fd3214d

Please sign in to comment.