diff --git a/code/app/src/main/java/com/adobe/marketing/edge/identity/app/ui/CustomIdentityFragment.kt b/code/app/src/main/java/com/adobe/marketing/edge/identity/app/ui/CustomIdentityFragment.kt index 5a3cfebb..b651095f 100644 --- a/code/app/src/main/java/com/adobe/marketing/edge/identity/app/ui/CustomIdentityFragment.kt +++ b/code/app/src/main/java/com/adobe/marketing/edge/identity/app/ui/CustomIdentityFragment.kt @@ -107,7 +107,9 @@ class CustomIdentityFragment : Fragment() { val isPrimary: Boolean = sharedViewModel.isPrimary.value ?: false val item = IdentityItem(identifier, authenticatedState, isPrimary) - Identity.removeIdentity(item, namespace) + if (namespace != null) { + Identity.removeIdentity(item, namespace) + } } // Advertising identifier features diff --git a/code/edgeidentity/src/androidTest/java/com/adobe/marketing/mobile/edge/identity/IdentityPublicAPITest.java b/code/edgeidentity/src/androidTest/java/com/adobe/marketing/mobile/edge/identity/IdentityPublicAPITest.java index 590296fa..d9e9620a 100644 --- a/code/edgeidentity/src/androidTest/java/com/adobe/marketing/mobile/edge/identity/IdentityPublicAPITest.java +++ b/code/edgeidentity/src/androidTest/java/com/adobe/marketing/mobile/edge/identity/IdentityPublicAPITest.java @@ -27,7 +27,6 @@ import java.util.List; import java.util.Map; import org.json.JSONObject; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestRule; @@ -39,15 +38,6 @@ public class IdentityPublicAPITest { @Rule public TestRule rule = new SetupCoreRule(); - // -------------------------------------------------------------------------------------------- - // Setup - // -------------------------------------------------------------------------------------------- - - @Before - public void setup() throws Exception { - registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); - } - // -------------------------------------------------------------------------------------------- // Tests for GetExtensionVersion API // -------------------------------------------------------------------------------------------- @@ -60,11 +50,29 @@ public void testGetExtensionVersionAPI() { // -------------------------------------------------------------------------------------------- // Tests for Register extension API // -------------------------------------------------------------------------------------------- - @Test public void testRegisterExtensionAPI() throws InterruptedException { // test - // Identity.registerExtension() is called in the setup method + //noinspection deprecation + Identity.registerExtension(); + + // now register monitor extension and start the hub + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION), null); + + // verify that the extension is registered with the correct version details + Map sharedStateMap = flattenMap( + getSharedStateFor(IdentityTestConstants.SharedStateName.EVENT_HUB, 5000) + ); + assertEquals( + IdentityConstants.EXTENSION_VERSION, + sharedStateMap.get("extensions.com.adobe.edge.identity.version") + ); + } + + @Test + public void testRegisterExtension_withClass() throws InterruptedException { + // test + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); // verify that the extension is registered with the correct version details Map sharedStateMap = flattenMap( @@ -82,6 +90,8 @@ public void testRegisterExtensionAPI() throws InterruptedException { @Test public void testUpdateIdentitiesAPI() throws Exception { + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); + // test Identity.updateIdentities( createIdentityMap("Email", "example@email.com", AuthenticatedState.AUTHENTICATED, true) @@ -109,6 +119,8 @@ public void testUpdateIdentitiesAPI() throws Exception { @Test public void testUpdateAPI_nullData() throws Exception { + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); + // test Identity.updateIdentities(null); waitForThreads(2000); @@ -125,6 +137,8 @@ public void testUpdateAPI_nullData() throws Exception { @Test public void testUpdateAPI_emptyData() throws Exception { + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); + // test Identity.updateIdentities(new IdentityMap()); waitForThreads(2000); @@ -141,6 +155,8 @@ public void testUpdateAPI_emptyData() throws Exception { @Test public void testUpdateAPI_shouldReplaceExistingIdentities() throws Exception { + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); + // test Identity.updateIdentities(createIdentityMap("Email", "example@email.com")); Identity.updateIdentities( @@ -172,6 +188,8 @@ public void testUpdateAPI_shouldReplaceExistingIdentities() throws Exception { @Test public void testUpdateAPI_withReservedNamespaces() throws Exception { + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); + // test Identity.updateIdentities(createIdentityMap("ECID", "newECID")); Identity.updateIdentities(createIdentityMap("GAID", "")); @@ -199,6 +217,8 @@ public void testUpdateAPI_withReservedNamespaces() throws Exception { @Test public void testUpdateAPI_multipleNamespaceMap() throws Exception { + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); + // test IdentityMap map = new IdentityMap(); map.addItem(new IdentityItem("primary@email.com"), "Email"); @@ -231,6 +251,8 @@ public void testUpdateAPI_multipleNamespaceMap() throws Exception { @Test public void testUpdateAPI_caseSensitiveNamespacesForCustomIdentifiers() throws Exception { + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); + // test IdentityMap map = new IdentityMap(); map.addItem(new IdentityItem("primary@email.com"), "Email"); @@ -261,6 +283,8 @@ public void testUpdateAPI_caseSensitiveNamespacesForCustomIdentifiers() throws E @Test public void testGetECID() { + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); + // test String ecid = getExperienceCloudIdSync(); @@ -270,6 +294,8 @@ public void testGetECID() { @Test public void testGetExperienceCloudId_nullCallback() { + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); + // test try { Identity.getExperienceCloudId(null); // should not crash @@ -284,6 +310,8 @@ public void testGetExperienceCloudId_nullCallback() { @Test public void testGetUrlVariables() throws Exception { + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); + // test setupConfiguration(); String urlVariables = getUrlVariablesSync(); @@ -293,6 +321,8 @@ public void testGetUrlVariables() throws Exception { @Test public void testGetUrlVariables_nullCallback() { + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); + // test try { Identity.getUrlVariables(null); // should not crash @@ -307,6 +337,8 @@ public void testGetUrlVariables_nullCallback() { @Test public void testGetIdentities() { + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); + // setup // update Identities through API IdentityMap map = new IdentityMap(); @@ -333,6 +365,8 @@ public void testGetIdentities() { @Test public void testGetIdentities_nullCallback() { + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); + // test try { Identity.getIdentities(null); // should not crash @@ -347,6 +381,8 @@ public void testGetIdentities_nullCallback() { @Test public void testRemoveIdentity() throws Exception { + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); + // setup // update Identities through API IdentityMap map = new IdentityMap(); @@ -382,6 +418,8 @@ public void testRemoveIdentity() throws Exception { @Test public void testRemoveIdentity_nonExistentNamespace() throws Exception { + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); + // test Identity.removeIdentity(new IdentityItem("primary@email.com"), "Email"); waitForThreads(2000); @@ -402,6 +440,8 @@ public void testRemoveIdentity_nonExistentNamespace() throws Exception { @Test public void testRemoveIdentity_nameSpaceCaseSensitive() throws Exception { + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); + // setup // update Identities through API Identity.updateIdentities(createIdentityMap("Email", "example@email.com")); @@ -426,6 +466,8 @@ public void testRemoveIdentity_nameSpaceCaseSensitive() throws Exception { @Test public void testRemoveIdentity_nonExistentItem() throws Exception { + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); + // setup // update Identities through API Identity.updateIdentities(createIdentityMap("Email", "example@email.com")); @@ -450,6 +492,8 @@ public void testRemoveIdentity_nonExistentItem() throws Exception { @Test public void testRemoveIdentity_doesNotRemoveECID() throws Exception { + registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); + // test String currentECID = getExperienceCloudIdSync(); diff --git a/code/edgeidentity/src/androidTest/java/com/adobe/marketing/mobile/edge/identity/util/IdentityFunctionalTestUtil.java b/code/edgeidentity/src/androidTest/java/com/adobe/marketing/mobile/edge/identity/util/IdentityFunctionalTestUtil.java index 793c369a..f6db0e5f 100644 --- a/code/edgeidentity/src/androidTest/java/com/adobe/marketing/mobile/edge/identity/util/IdentityFunctionalTestUtil.java +++ b/code/edgeidentity/src/androidTest/java/com/adobe/marketing/mobile/edge/identity/util/IdentityFunctionalTestUtil.java @@ -15,6 +15,7 @@ import static com.adobe.marketing.mobile.edge.identity.util.TestHelper.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; import androidx.annotation.Nullable; import com.adobe.marketing.mobile.AdobeCallback; @@ -53,12 +54,11 @@ public class IdentityFunctionalTestUtil { * core. * @param extensions the extensions that need to be registered * @param configuration the initial configuration update that needs to be applied - * @throws InterruptedException if the wait time for extension registration has elapsed */ public static void registerExtensions( final List> extensions, @Nullable final Map configuration - ) throws InterruptedException { + ) { if (configuration != null) { MobileCore.updateConfiguration(configuration); } @@ -66,7 +66,11 @@ public static void registerExtensions( final ADBCountDownLatch latch = new ADBCountDownLatch(1); MobileCore.registerExtensions(extensions, o -> latch.countDown()); - latch.await(REGISTRATION_TIMEOUT_MS, TimeUnit.MILLISECONDS); + try { + latch.await(REGISTRATION_TIMEOUT_MS, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + fail("Failed to register extensions"); + } TestHelper.waitForThreads(2000); resetTestExpectations(); } diff --git a/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/Identity.java b/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/Identity.java index 7e87f61b..2184bfd4 100644 --- a/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/Identity.java +++ b/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/Identity.java @@ -13,6 +13,7 @@ import static com.adobe.marketing.mobile.edge.identity.IdentityConstants.LOG_TAG; +import androidx.annotation.NonNull; import com.adobe.marketing.mobile.AdobeCallback; import com.adobe.marketing.mobile.AdobeCallbackWithError; import com.adobe.marketing.mobile.AdobeError; @@ -20,8 +21,6 @@ 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; import com.adobe.marketing.mobile.MobileCore; import com.adobe.marketing.mobile.services.Log; import com.adobe.marketing.mobile.util.DataReader; @@ -47,6 +46,7 @@ private Identity() {} * * @return The version as {@code String} */ + @NonNull public static String extensionVersion() { return IdentityConstants.EXTENSION_VERSION; } @@ -54,22 +54,19 @@ public static String extensionVersion() { /** * Registers the extension with the Mobile SDK. This method should be called only once in your application class. * - * @deprecated Use {@link MobileCore#registerExtensions(List, AdobeCallback)} with {@link Identity#EXTENSION} instead. + * @deprecated as of 2.0.0, use {@link MobileCore#registerExtensions(List, AdobeCallback)} with {@link Identity#EXTENSION} instead. */ @Deprecated + @SuppressWarnings("deprecation") public static void registerExtension() { MobileCore.registerExtension( IdentityExtension.class, - new ExtensionErrorCallback() { - @Override - public void error(ExtensionError extensionError) { - Log.error( - LOG_TAG, - LOG_SOURCE, - "There was an error registering the Edge Identity extension: " + extensionError.getErrorName() - ); - } - } + extensionError -> + Log.error( + LOG_TAG, + LOG_SOURCE, + "There was an error registering the Edge Identity extension: " + extensionError.getErrorName() + ) ); } @@ -80,7 +77,7 @@ public void error(ExtensionError extensionError) { * If an {@link AdobeCallbackWithError} is provided, an {@link AdobeError} can be returned in the * eventuality of any error that occurred while getting the Experience Cloud ID */ - public static void getExperienceCloudId(final AdobeCallback callback) { + public static void getExperienceCloudId(@NonNull final AdobeCallback callback) { if (callback == null) { Log.debug(LOG_TAG, LOG_SOURCE, "Unexpected null callback, provide a callback to retrieve current ECID."); return; @@ -95,7 +92,7 @@ public static void getExperienceCloudId(final AdobeCallback callback) { final AdobeCallbackWithError callbackWithError = new AdobeCallbackWithError() { @Override - public void call(Event responseEvent) { + public void call(final Event responseEvent) { if (responseEvent == null || responseEvent.getEventData() == null) { returnError(callback, AdobeError.UNEXPECTED_ERROR); return; @@ -125,7 +122,7 @@ public void call(Event responseEvent) { } @Override - public void fail(AdobeError adobeError) { + public void fail(final AdobeError adobeError) { returnError(callback, adobeError); Log.debug( LOG_TAG, @@ -159,7 +156,7 @@ public void fail(AdobeError adobeError) { * If an {@link AdobeCallbackWithError} is provided, an {@link AdobeError} can be returned in the * eventuality of any error that occurred while getting the identifiers query string */ - public static void getUrlVariables(final AdobeCallback callback) { + public static void getUrlVariables(@NonNull final AdobeCallback callback) { if (callback == null) { Log.debug( LOG_TAG, @@ -231,7 +228,7 @@ public void fail(final AdobeError adobeError) { * * @param identityMap The identifiers to add or update. */ - public static void updateIdentities(final IdentityMap identityMap) { + public static void updateIdentities(@NonNull final IdentityMap identityMap) { if (identityMap == null || identityMap.isEmpty()) { Log.debug(LOG_TAG, LOG_SOURCE, "Unable to updateIdentities, IdentityMap is null or empty"); return; @@ -255,7 +252,7 @@ public static void updateIdentities(final IdentityMap identityMap) { * @param item the {@link IdentityItem} to remove. * @param namespace The namespace of the identity to remove. */ - public static void removeIdentity(final IdentityItem item, final String namespace) { + public static void removeIdentity(@NonNull final IdentityItem item, @NonNull final String namespace) { if (StringUtils.isNullOrEmpty(namespace)) { Log.debug(LOG_TAG, LOG_SOURCE, "Unable to removeIdentity, namespace is null or empty"); return; @@ -286,7 +283,7 @@ public static void removeIdentity(final IdentityItem item, final String namespac * If an {@link AdobeCallbackWithError} is provided, an {@link AdobeError} can be returned in the * eventuality of any error that occurred while getting the stored identities. */ - public static void getIdentities(final AdobeCallback callback) { + public static void getIdentities(@NonNull final AdobeCallback callback) { if (callback == null) { Log.debug( LOG_TAG, diff --git a/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityExtension.java b/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityExtension.java index 81c7243f..56e1a362 100644 --- a/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityExtension.java +++ b/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityExtension.java @@ -73,11 +73,13 @@ protected String getName() { return IdentityConstants.EXTENSION_NAME; } + @NonNull @Override protected String getFriendlyName() { return IdentityConstants.EXTENSION_FRIENDLY_NAME; } + @NonNull @Override protected String getVersion() { return IdentityConstants.EXTENSION_VERSION; @@ -90,11 +92,10 @@ protected String getVersion() { * The following listeners are registered during this extension's registration. *
    *
  • EventType {@link EventType#GENERIC_IDENTITY} and EventSource {@link EventSource#REQUEST_CONTENT}
  • + *
  • EventType {@link EventType#GENERIC_IDENTITY} and EventSource {@link EventSource#REQUEST_RESET}
  • *
  • EventType {@link EventType#EDGE_IDENTITY} and EventSource {@link EventSource#REQUEST_IDENTITY}
  • *
  • EventType {@link EventType#EDGE_IDENTITY} and EventSource {@link EventSource#UPDATE_IDENTITY}
  • *
  • EventType {@link EventType#EDGE_IDENTITY} and EventSource {@link EventSource#REMOVE_IDENTITY}
  • - *
  • EventType {@link EventType#EDGE_IDENTITY} and EventSource {@link EventSource#REQUEST_CONTENT}
  • - *
  • EventType {@link EventType#GENERIC_IDENTITY} and EventSource {@link EventSource#REQUEST_RESET}
  • *
  • EventType {@link EventType#HUB} and EventSource {@link EventSource#SHARED_STATE}
  • *
*