From 86ae5a2b6089c7438b8786652490adafbf59dd26 Mon Sep 17 00:00:00 2001 From: Emilia Dobrin <33132425+emdobrin@users.noreply.github.com> Date: Thu, 12 Jan 2023 16:42:53 -0800 Subject: [PATCH 1/2] java 11 for release workflow (#85) --- .github/workflows/maven-release.yml | 2 +- .github/workflows/maven-snapshot.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven-release.yml b/.github/workflows/maven-release.yml index fbff1c77..627da1b4 100644 --- a/.github/workflows/maven-release.yml +++ b/.github/workflows/maven-release.yml @@ -11,7 +11,7 @@ jobs: - name: Set up Java uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 11 - name: Cache Gradle packages uses: actions/cache@v2 with: diff --git a/.github/workflows/maven-snapshot.yml b/.github/workflows/maven-snapshot.yml index 748479fb..aa38ba6c 100644 --- a/.github/workflows/maven-snapshot.yml +++ b/.github/workflows/maven-snapshot.yml @@ -11,7 +11,7 @@ jobs: - name: Set up Java uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 11 - name: Cache Gradle packages uses: actions/cache@v2 with: From e12492dddbf0292f957a1657030ce7f2804199ea Mon Sep 17 00:00:00 2001 From: Kevin Lind <40409666+kevinlind@users.noreply.github.com> Date: Thu, 12 Jan 2023 17:23:09 -0800 Subject: [PATCH 2/2] Fix use of 'allowEmpty' parameter in IdentityProperties.toXDMData() (#86) --- .../identity/IdentityECIDHandlingTest.java | 4 ++-- .../edge/identity/IdentityExtension.java | 18 +++++++------- .../mobile/edge/identity/IdentityMap.java | 16 +++---------- .../edge/identity/IdentityProperties.java | 16 +++++++++++-- .../mobile/edge/identity/IdentityState.java | 4 ++-- .../edge/identity/IdentityStorageManager.java | 2 +- .../edge/identity/IdentityExtensionTests.java | 2 +- .../edge/identity/IdentityMapTests.java | 18 +++++++------- .../identity/IdentityPropertiesTests.java | 24 ++++++++++++++++++- .../mobile/edge/identity/IdentityTests.java | 4 ++-- 10 files changed, 66 insertions(+), 42 deletions(-) diff --git a/code/edgeidentity/src/androidTest/java/com/adobe/marketing/mobile/edge/identity/IdentityECIDHandlingTest.java b/code/edgeidentity/src/androidTest/java/com/adobe/marketing/mobile/edge/identity/IdentityECIDHandlingTest.java index d17e1f9e..8cf9a9a7 100644 --- a/code/edgeidentity/src/androidTest/java/com/adobe/marketing/mobile/edge/identity/IdentityECIDHandlingTest.java +++ b/code/edgeidentity/src/androidTest/java/com/adobe/marketing/mobile/edge/identity/IdentityECIDHandlingTest.java @@ -66,7 +66,7 @@ public void testECID_loadedFromPersistence() throws Exception { public void testECID_edgePersistenceTakesPreferenceOverDirectExtension() throws Exception { // setup setIdentityDirectPersistedECID("legacyECID"); - setEdgeIdentityPersistence(createIdentityMap("ECID", "edgeECID").asXDMMap()); + setEdgeIdentityPersistence(createIdentityMap("ECID", "edgeECID").asXDMMap(false)); registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null); // verify @@ -217,7 +217,7 @@ public void testECID_AreDifferentAfterResetIdentitiesAndPrivacyChange() throws E public void testECID_DirectEcidIsRemovedOnPrivacyOptOut() throws Exception { // setup setIdentityDirectPersistedECID("legacyECID"); - setEdgeIdentityPersistence(createIdentityMap("ECID", "edgeECID").asXDMMap()); + setEdgeIdentityPersistence(createIdentityMap("ECID", "edgeECID").asXDMMap(false)); registerExtensions( Arrays.asList( 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 fc5ab4d2..07169b30 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 @@ -259,7 +259,7 @@ void handleUpdateIdentities(@NonNull final Event event) { if (eventData == null) { Log.trace(LOG_TAG, LOG_SOURCE, "Cannot update identifiers, event data is null."); - resolver.resolve(state.getIdentityProperties().toXDMData(false)); + resolver.resolve(state.getIdentityProperties().toXDMData()); return; } @@ -271,12 +271,12 @@ void handleUpdateIdentities(@NonNull final Event event) { LOG_SOURCE, "Failed to update identifiers as no identifiers were found in the event data." ); - resolver.resolve(state.getIdentityProperties().toXDMData(false)); + resolver.resolve(state.getIdentityProperties().toXDMData()); return; } state.updateCustomerIdentifiers(map); - resolver.resolve(state.getIdentityProperties().toXDMData(false)); + resolver.resolve(state.getIdentityProperties().toXDMData()); } /** @@ -292,7 +292,7 @@ void handleRemoveIdentity(@NonNull final Event event) { if (eventData == null) { Log.trace(LOG_TAG, LOG_SOURCE, "Cannot remove identifiers, event data is null."); - resolver.resolve(state.getIdentityProperties().toXDMData(false)); + resolver.resolve(state.getIdentityProperties().toXDMData()); return; } @@ -304,12 +304,12 @@ void handleRemoveIdentity(@NonNull final Event event) { LOG_SOURCE, "Failed to remove identifiers as no identifiers were found in the event data." ); - resolver.resolve(state.getIdentityProperties().toXDMData(false)); + resolver.resolve(state.getIdentityProperties().toXDMData()); return; } state.removeCustomerIdentifiers(map); - resolver.resolve(state.getIdentityProperties().toXDMData(false)); + resolver.resolve(state.getIdentityProperties().toXDMData()); } /** @@ -318,7 +318,7 @@ void handleRemoveIdentity(@NonNull final Event event) { * @param event the identity request {@link Event} */ private void handleGetIdentifiersRequest(@NonNull final Event event) { - final Map xdmData = state.getIdentityProperties().toXDMData(false); + final Map xdmData = state.getIdentityProperties().toXDMData(true); final Event responseEvent = new Event.Builder( IdentityConstants.EventNames.IDENTITY_RESPONSE_CONTENT_ONE_TIME, EventType.EDGE_IDENTITY, @@ -340,7 +340,7 @@ void handleRequestReset(@NonNull final Event event) { // Add pending shared state to avoid race condition between updating and reading identity map final SharedStateResolver resolver = getApi().createPendingXDMSharedState(event); state.resetIdentifiers(); - resolver.resolve(state.getIdentityProperties().toXDMData(false)); + resolver.resolve(state.getIdentityProperties().toXDMData()); // dispatch reset complete event final Event responseEvent = new Event.Builder( @@ -403,6 +403,6 @@ void handleRequestContent(@NonNull final Event event) { * @param event the {@link Event} that triggered the XDM shared state change */ private void shareIdentityXDMSharedState(final Event event) { - sharedStateHandle.createXDMSharedState(state.getIdentityProperties().toXDMData(false), event); + sharedStateHandle.createXDMSharedState(state.getIdentityProperties().toXDMData(), event); } } diff --git a/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityMap.java b/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityMap.java index 4db3ee9b..710bbc31 100644 --- a/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityMap.java +++ b/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityMap.java @@ -229,21 +229,11 @@ boolean clearItemsForNamespace(final String namespace) { return isRemoved; } - /** - * Use this method to cast the {@link IdentityMap} as {@code Map} to be passed as EventData for an SDK Event. - * This method returns an empty map if the {@code IdentityMap} contains no data - * - * @return {@code Map} representation of xdm formatted IdentityMap - */ - Map asXDMMap() { - return asXDMMap(true); - } - /** * Use this method to cast the {@link IdentityMap} as {@code Map} to be passed as EventData for an SDK Event. * - * @param allowEmpty If false and if this {@code IdentityMap} contains no data, then returns a map with empty xdmFormatted Identity Map. - * If true and if this {@code IdentityMap} contains no data, then returns an empty map + * @param allowEmpty If true and if this {@code IdentityMap} contains no data, then returns a map with empty xdmFormatted Identity Map. + * If false and if this {@code IdentityMap} contains no data, then returns an empty map * @return {@code Map} representation of xdm formatted IdentityMap */ Map asXDMMap(final boolean allowEmpty) { @@ -260,7 +250,7 @@ Map asXDMMap(final boolean allowEmpty) { identityMap.put(namespace, namespaceIds); } - if (!identityMap.isEmpty() || !allowEmpty) { + if (!identityMap.isEmpty() || allowEmpty) { xdmMap.put(IdentityConstants.XDMKeys.IDENTITY_MAP, identityMap); } diff --git a/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityProperties.java b/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityProperties.java index 36c79dec..f1ba370d 100644 --- a/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityProperties.java +++ b/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityProperties.java @@ -224,9 +224,21 @@ void removeCustomerIdentifiers(final IdentityMap map) { } /** - * Converts this into an event data representation in XDM format + * Converts this {@code IdentityProperties} into an event data representation in XDM format + * Use this method to cast the {@link IdentityMap} as {@code Map} to be passed as EventData for an SDK Event. + * This method returns an empty map if the {@code IdentityMap} contains no data * - * @param allowEmpty If this {@link IdentityProperties} contains no data, return a dictionary with a single {@link IdentityMap} key + * @return A {@link Map} representing this in XDM format, or an empty {@link Map} if this contains no data. + */ + Map toXDMData() { + return toXDMData(false); + } + + /** + * Converts this {@code IdentityProperties} into an event data representation in XDM format + * + * @param allowEmpty If this {@link IdentityProperties} contains no data, return a dictionary with a single {@link IdentityMap} key, + * otherwise an empty map is returned. * @return A {@link Map} representing this in XDM format */ Map toXDMData(final boolean allowEmpty) { diff --git a/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityState.java b/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityState.java index cfecc251..2cc44e91 100644 --- a/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityState.java +++ b/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityState.java @@ -137,7 +137,7 @@ else if (isIdentityDirectRegistered(eventHubStateResult.getValue())) { hasBooted = true; Log.debug(LOG_TAG, LOG_SOURCE, "Edge Identity has successfully booted up"); - callback.createXDMSharedState(identityProperties.toXDMData(false), null); + callback.createXDMSharedState(identityProperties.toXDMData(), null); return hasBooted; } @@ -209,7 +209,7 @@ void updateAdvertisingIdentifier(final Event event, final SharedStateCallback ca // Save to persistence identityStorageManager.savePropertiesToPersistence(identityProperties); - callback.createXDMSharedState(identityProperties.toXDMData(false), event); + callback.createXDMSharedState(identityProperties.toXDMData(), event); } /** diff --git a/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityStorageManager.java b/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityStorageManager.java index 62092e10..07525550 100644 --- a/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityStorageManager.java +++ b/code/edgeidentity/src/main/java/com/adobe/marketing/mobile/edge/identity/IdentityStorageManager.java @@ -99,7 +99,7 @@ void savePropertiesToPersistence(final IdentityProperties properties) { return; } - final JSONObject jsonObject = new JSONObject(properties.toXDMData(false)); + final JSONObject jsonObject = new JSONObject(properties.toXDMData()); final String jsonString = jsonObject.toString(); edgeIdentityStore.setString(IdentityConstants.DataStoreKey.IDENTITY_PROPERTIES, jsonString); } diff --git a/code/edgeidentity/src/test/java/com/adobe/marketing/mobile/edge/identity/IdentityExtensionTests.java b/code/edgeidentity/src/test/java/com/adobe/marketing/mobile/edge/identity/IdentityExtensionTests.java index cd018e6f..abae0e61 100644 --- a/code/edgeidentity/src/test/java/com/adobe/marketing/mobile/edge/identity/IdentityExtensionTests.java +++ b/code/edgeidentity/src/test/java/com/adobe/marketing/mobile/edge/identity/IdentityExtensionTests.java @@ -685,7 +685,7 @@ public void test_handleUpdateIdentities_whenValidData_updatesCustomerIdentifiers // verify identifiers updated final ArgumentCaptor identityMapCaptor = ArgumentCaptor.forClass(IdentityMap.class); verify(mockIdentityState).updateCustomerIdentifiers(identityMapCaptor.capture()); - assertEquals(identityXDM, identityMapCaptor.getValue().asXDMMap()); + assertEquals(identityXDM, identityMapCaptor.getValue().asXDMMap(false)); // verify pending state is created and resolved verify(mockExtensionApi).createPendingXDMSharedState(eq(updateIdentityEvent)); diff --git a/code/edgeidentity/src/test/java/com/adobe/marketing/mobile/edge/identity/IdentityMapTests.java b/code/edgeidentity/src/test/java/com/adobe/marketing/mobile/edge/identity/IdentityMapTests.java index 331f48ad..06ff453b 100644 --- a/code/edgeidentity/src/test/java/com/adobe/marketing/mobile/edge/identity/IdentityMapTests.java +++ b/code/edgeidentity/src/test/java/com/adobe/marketing/mobile/edge/identity/IdentityMapTests.java @@ -31,7 +31,7 @@ public void test_AddItem() { map.addItem(new IdentityItem("California"), "location"); // verify - IdentityTestUtil.flattenMap(map.asXDMMap()).get("identityMap.location[0].id"); + IdentityTestUtil.flattenMap(map.asXDMMap(false)).get("identityMap.location[0].id"); } @Test @@ -148,7 +148,7 @@ public void test_merge_sameItem_GetsReplaced() { baseMap.merge(newMap); // verify the existing identityMap is unchanged - Map flattenedMap = IdentityTestUtil.flattenMap(baseMap.asXDMMap()); + Map flattenedMap = IdentityTestUtil.flattenMap(baseMap.asXDMMap(false)); assertEquals(3, flattenedMap.size()); assertEquals("California", flattenedMap.get("identityMap.location[0].id")); assertEquals("authenticated", flattenedMap.get("identityMap.location[0].authenticatedState")); @@ -219,7 +219,7 @@ public void test_removeAllIdentityItemsForNamespace_onEmptyMap() { // test emptyMap.clearItemsForNamespace("location"); - assertTrue(emptyMap.asXDMMap().isEmpty()); + assertTrue(emptyMap.asXDMMap(false).isEmpty()); } @Test @@ -301,7 +301,7 @@ public void test_FromData() throws Exception { IdentityMap map = IdentityMap.fromXDMMap(xdmData); // verify - Map flattenedMap = IdentityTestUtil.flattenMap(map.asXDMMap()); + Map flattenedMap = IdentityTestUtil.flattenMap(map.asXDMMap(false)); assertEquals("randomECID", flattenedMap.get("identityMap.ECID[0].id")); assertEquals("ambiguous", flattenedMap.get("identityMap.ECID[0].authenticatedState")); assertEquals("true", flattenedMap.get("identityMap.ECID[0].primary")); @@ -387,16 +387,16 @@ public void testFromXDMMap_InvalidIdentityMap() throws Exception { } @Test - public void testAsXDMMap_AllowEmptyTrue() { + public void testAsXDMMap_AllowEmptyFalse() { IdentityMap map = new IdentityMap(); - Map xdmMap = map.asXDMMap(true); + Map xdmMap = map.asXDMMap(false); assertTrue(xdmMap.isEmpty()); } @Test - public void testAsXDMMap_AllowEmptyFalse() { + public void testAsXDMMap_AllowEmptyTrue() { IdentityMap map = new IdentityMap(); - Map xdmMap = map.asXDMMap(false); + Map xdmMap = map.asXDMMap(true); // verify that the base xdm key identityMap is present assertEquals(1, xdmMap.size()); @@ -404,7 +404,7 @@ public void testAsXDMMap_AllowEmptyFalse() { } private Map> getCastedIdentityMap(final IdentityMap map) { - final Map xdmMap = map.asXDMMap(); + final Map xdmMap = map.asXDMMap(false); return (Map>) xdmMap.get(IdentityConstants.XDMKeys.IDENTITY_MAP); } diff --git a/code/edgeidentity/src/test/java/com/adobe/marketing/mobile/edge/identity/IdentityPropertiesTests.java b/code/edgeidentity/src/test/java/com/adobe/marketing/mobile/edge/identity/IdentityPropertiesTests.java index 68339f26..425d0627 100644 --- a/code/edgeidentity/src/test/java/com/adobe/marketing/mobile/edge/identity/IdentityPropertiesTests.java +++ b/code/edgeidentity/src/test/java/com/adobe/marketing/mobile/edge/identity/IdentityPropertiesTests.java @@ -13,8 +13,12 @@ import static com.adobe.marketing.mobile.edge.identity.IdentityTestUtil.*; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import com.adobe.marketing.mobile.util.DataReader; +import com.adobe.marketing.mobile.util.DataReaderException; import java.util.Map; import org.junit.Test; @@ -25,13 +29,31 @@ public class IdentityPropertiesTests { // ====================================================================================================================== @Test - public void test_toXDMData_AllowEmpty() { + public void test_toXDMData_AllowEmpty_True() throws DataReaderException { // setup IdentityProperties props = new IdentityProperties(); // test Map xdmMap = props.toXDMData(true); + // verify + Map identityMap = DataReader.getTypedMap( + Object.class, + xdmMap, + IdentityConstants.XDMKeys.IDENTITY_MAP + ); + assertNotNull(identityMap); + assertTrue(identityMap.isEmpty()); + } + + @Test + public void test_toXDMData_AllowEmpty_False() { + // setup + IdentityProperties props = new IdentityProperties(); + + // test + Map xdmMap = props.toXDMData(false); + // verify assertNull(xdmMap.get(IdentityConstants.XDMKeys.IDENTITY_MAP)); } diff --git a/code/edgeidentity/src/test/java/com/adobe/marketing/mobile/edge/identity/IdentityTests.java b/code/edgeidentity/src/test/java/com/adobe/marketing/mobile/edge/identity/IdentityTests.java index af87cc32..713cff69 100644 --- a/code/edgeidentity/src/test/java/com/adobe/marketing/mobile/edge/identity/IdentityTests.java +++ b/code/edgeidentity/src/test/java/com/adobe/marketing/mobile/edge/identity/IdentityTests.java @@ -628,7 +628,7 @@ public void testUpdateIdentities() { assertEquals(IdentityConstants.EventNames.UPDATE_IDENTITIES, dispatchedEvent.getName()); assertEquals(EventType.EDGE_IDENTITY, dispatchedEvent.getType()); assertEquals(EventSource.UPDATE_IDENTITY, dispatchedEvent.getSource()); - assertEquals(map.asXDMMap(), dispatchedEvent.getEventData()); + assertEquals(map.asXDMMap(false), dispatchedEvent.getEventData()); } @Test @@ -685,7 +685,7 @@ public void testRemoveIdentity() { final IdentityMap expectedIdentityMap = new IdentityMap(); expectedIdentityMap.addItem(sampleItem, "namespace"); - assertEquals(expectedIdentityMap.asXDMMap(), dispatchedEvent.getEventData()); + assertEquals(expectedIdentityMap.asXDMMap(false), dispatchedEvent.getEventData()); } @Test