From aa376aa413f7342d71024156685fff72590b2f3c Mon Sep 17 00:00:00 2001 From: timkimadobe <95260439+timkimadobe@users.noreply.github.com> Date: Wed, 29 May 2024 18:18:11 -0700 Subject: [PATCH 01/11] Update EdgeFunctionalTests.java to use AEPTestUtils --- .../marketing/mobile/EdgeFunctionalTests.java | 710 ++++++++++-------- 1 file changed, 417 insertions(+), 293 deletions(-) diff --git a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java index f2735553..72c4488a 100644 --- a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java +++ b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java @@ -12,6 +12,9 @@ package com.adobe.marketing.mobile; import static com.adobe.marketing.mobile.services.HttpMethod.POST; +import static com.adobe.marketing.mobile.util.JSONAsserts.assertExactMatch; +import static com.adobe.marketing.mobile.util.JSONAsserts.assertTypeMatch; +import static com.adobe.marketing.mobile.util.NodeConfig.Scope.Subtree; import static com.adobe.marketing.mobile.util.TestHelper.LogOnErrorRule; import static com.adobe.marketing.mobile.util.TestHelper.SetupCoreRule; import static com.adobe.marketing.mobile.util.TestHelper.assertExpectedEvents; @@ -24,19 +27,27 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.adobe.marketing.mobile.edge.identity.Identity; import com.adobe.marketing.mobile.services.HttpConnecting; import com.adobe.marketing.mobile.services.NamedCollection; +import com.adobe.marketing.mobile.services.NetworkRequest; import com.adobe.marketing.mobile.services.ServiceProvider; import com.adobe.marketing.mobile.services.TestableNetworkRequest; +import com.adobe.marketing.mobile.util.AnyOrderMatch; +import com.adobe.marketing.mobile.util.CollectionEqualCount; +import com.adobe.marketing.mobile.util.ElementCount; +import com.adobe.marketing.mobile.util.JSONAsserts; +import com.adobe.marketing.mobile.util.KeyMustBeAbsent; import com.adobe.marketing.mobile.util.MockNetworkService; import com.adobe.marketing.mobile.util.MonitorExtension; import com.adobe.marketing.mobile.util.TestConstants; import com.adobe.marketing.mobile.util.TestHelper; -import com.adobe.marketing.mobile.util.TestUtils; import com.adobe.marketing.mobile.util.TestXDMSchema; +import com.adobe.marketing.mobile.util.ValueTypeMatch; + import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -46,6 +57,9 @@ import java.util.TimeZone; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; + +import org.json.JSONException; +import org.json.JSONObject; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -152,18 +166,23 @@ public void testSendEvent_withXDMData_sendsCorrectRequestEvent() throws Interrup assertExpectedEvents(false); List resultEvents = getDispatchedEventsWith(EventType.EDGE, EventSource.REQUEST_CONTENT); assertEquals(1, resultEvents.size()); - Map eventData = resultEvents.get(0).getEventData(); - assertNotNull(eventData); - - Map flattenedData = TestUtils.flattenMap(eventData); - assertEquals(7, flattenedData.size()); - assertEquals("xdm", flattenedData.get("xdm.testString")); - assertEquals("10", flattenedData.get("xdm.testInt")); - assertEquals("false", flattenedData.get("xdm.testBool")); - assertEquals("12.89", flattenedData.get("xdm.testDouble")); - assertEquals("elem1", flattenedData.get("xdm.testArray[0]")); - assertEquals("elem2", flattenedData.get("xdm.testArray[1]")); - assertEquals("value", flattenedData.get("xdm.testMap.key")); + + String expected = "{" + + " \"xdm\": {" + + " \"testString\": \"xdm\"," + + " \"testInt\": 10," + + " \"testBool\": false," + + " \"testDouble\": 12.89," + + " \"testArray\": [" + + " \"elem1\"," + + " \"elem2\"" + + " ]," + + " \"testMap\": {" + + " \"key\": \"value\"" + + " }" + + " }" + + "}"; + JSONAsserts.assertEquals(expected, resultEvents.get(0).getEventData()); } @Test @@ -212,19 +231,26 @@ public void testSendEvent_withXDMDataAndCustomData_sendsCorrectRequestEvent() th assertExpectedEvents(false); List resultEvents = getDispatchedEventsWith(EventType.EDGE, EventSource.REQUEST_CONTENT); assertEquals(1, resultEvents.size()); - Map eventData = resultEvents.get(0).getEventData(); - assertNotNull(eventData); - - Map flattenedData = TestUtils.flattenMap(eventData); - assertEquals(8, flattenedData.size()); - assertEquals("xdm", flattenedData.get("xdm.testString")); - assertEquals("stringValue", flattenedData.get("data.testString")); - assertEquals("101", flattenedData.get("data.testInt")); - assertEquals("true", flattenedData.get("data.testBool")); - assertEquals("13.66", flattenedData.get("data.testDouble")); - assertEquals("elem1", flattenedData.get("data.testArray[0]")); - assertEquals("elem2", flattenedData.get("data.testArray[1]")); - assertEquals("value", flattenedData.get("data.testMap.key")); + + String expected = "{" + + " \"xdm\": {" + + " \"testString\": \"xdm\"" + + " }," + + " \"data\": {" + + " \"testString\": \"stringValue\"," + + " \"testInt\": 101," + + " \"testBool\": true," + + " \"testDouble\": 13.66," + + " \"testArray\": [" + + " \"elem1\"," + + " \"elem2\"" + + " ]," + + " \"testMap\": {" + + " \"key\": \"value\"" + + " }" + + " }" + + "}"; + JSONAsserts.assertEquals(expected, resultEvents.get(0).getEventData()); } @Test @@ -247,12 +273,13 @@ public void testSendEvent_withXDMDataAndNullData_sendsCorrectRequestEvent() thro assertExpectedEvents(false); List resultEvents = getDispatchedEventsWith(EventType.EDGE, EventSource.REQUEST_CONTENT); assertEquals(1, resultEvents.size()); - Map eventData = resultEvents.get(0).getEventData(); - assertNotNull(eventData); - Map flattenedData = TestUtils.flattenMap(eventData); - assertEquals(1, flattenedData.size()); - assertEquals("xdm", flattenedData.get("xdm.testString")); + String expected = "{" + + " \"xdm\": {" + + " \"testString\": \"xdm\"" + + " }" + + "}"; + JSONAsserts.assertEquals(expected, resultEvents.get(0).getEventData()); } @Test @@ -329,11 +356,9 @@ public void call(Event event) { assertEquals(EventSource.CONTENT_COMPLETE, event.getSource()); assertEquals(edgeEvent.getUniqueIdentifier(), event.getParentID()); assertEquals(edgeEvent.getUniqueIdentifier(), event.getResponseID()); - assertNotNull(event.getEventData()); - Map flattenedData = TestUtils.flattenMap(event.getEventData()); - assertEquals(1, flattenedData.size()); - assertNotNull(flattenedData.get("requestId")); + String expected = "{ \"requestId\": \"STRING_TYPE\" }"; + assertTypeMatch(expected, event.getEventData(), new CollectionEqualCount(Subtree)); latch.countDown(); } } @@ -385,44 +410,63 @@ public void testSendEvent_withXDMData_sendsExEdgeNetworkRequest() throws Excepti // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - Map resultPayload = mockNetworkService.getFlattenedNetworkRequestBody(resultRequests.get(0)); - assertEquals(18, resultPayload.size()); - assertEquals("true", resultPayload.get("meta.konductorConfig.streaming.enabled")); - assertEquals("\u0000", resultPayload.get("meta.konductorConfig.streaming.recordSeparator")); - assertEquals("\n", resultPayload.get("meta.konductorConfig.streaming.lineFeed")); - assertNotNull(resultPayload.get("xdm.identityMap.ECID[0].id")); - assertEquals("false", resultPayload.get("xdm.identityMap.ECID[0].primary")); - assertEquals("ambiguous", resultPayload.get("xdm.identityMap.ECID[0].authenticatedState")); - assertNotNull(resultPayload.get("events[0].xdm._id")); - assertNotNull(resultPayload.get("events[0].xdm.timestamp")); - assertEquals("xdmValue", resultPayload.get("events[0].xdm.testString")); - assertEquals("10", resultPayload.get("events[0].xdm.testInt")); - assertEquals("false", resultPayload.get("events[0].xdm.testBool")); - assertEquals("12.89", resultPayload.get("events[0].xdm.testDouble")); - assertEquals("elem1", resultPayload.get("events[0].xdm.testArray[0]")); - assertEquals("elem2", resultPayload.get("events[0].xdm.testArray[1]")); - assertEquals("value", resultPayload.get("events[0].xdm.testMap.key")); - - assertTrue(resultRequests.get(0).getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); - assertEquals(CONFIG_ID, resultRequests.get(0).queryParam("configId")); - assertNotNull(resultRequests.get(0).queryParam("requestId")); - - assertEquals("app", resultPayload.get("xdm.implementationDetails.environment")); - assertEquals( - EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE, - resultPayload.get("xdm.implementationDetails.name") - ); - assertEquals( - MobileCore.extensionVersion() + "+" + Edge.extensionVersion(), - resultPayload.get("xdm.implementationDetails.version") - ); + TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); + assertTrue(testableNetworkRequest.getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); + assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); + assertNotNull(testableNetworkRequest.queryParam("requestId")); + + String expected = "{" + + " \"events\": [" + + " {" + + " \"xdm\": {" + + " \"_id\": \"STRING_TYPE\"," + + " \"testArray\": [\"elem1\", \"elem2\"]," + + " \"testBool\": false," + + " \"testDouble\": 12.89," + + " \"testInt\": 10," + + " \"testMap\": {" + + " \"key\": \"value\"" + + " }," + + " \"testString\": \"xdmValue\"," + + " \"timestamp\": \"STRING_TYPE\"" + + " }" + + " }" + + " ]," + + " \"meta\": {" + + " \"konductorConfig\": {" + + " \"streaming\": {" + + " \"enabled\": true," + + " \"lineFeed\": \"\\n\"," + + " \"recordSeparator\": \"\\u0000\"" + + " }" + + " }" + + " }," + + " \"xdm\": {" + + " \"identityMap\": {" + + " \"ECID\": [" + + " {" + + " \"authenticatedState\": \"ambiguous\"," + + " \"id\": \"STRING_TYPE\"," + + " \"primary\": false" + + " }" + + " ]" + + " }," + + " \"implementationDetails\": {" + + " \"environment\": \"app\"," + + " \"name\": \"" + EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE + "\"," + + " \"version\": \"" + MobileCore.extensionVersion() + "+" + Edge.extensionVersion() + "\"" + + " }" + + " }" + + "}"; + + assertExactMatch(expected, getPayloadJson(resultRequests.get(0)), new CollectionEqualCount(Subtree), new ValueTypeMatch("xdm.identityMap.ECID[0].id", "events[0].xdm._id", "events[0].xdm.timestamp")); } @Test @@ -471,44 +515,65 @@ public void testSendEvent_withXDMDataAndCustomData_sendsExEdgeNetworkRequest() t // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - Map resultPayload = mockNetworkService.getFlattenedNetworkRequestBody(resultRequests.get(0)); - assertEquals(19, resultPayload.size()); - assertEquals("true", resultPayload.get("meta.konductorConfig.streaming.enabled")); - assertEquals("\u0000", resultPayload.get("meta.konductorConfig.streaming.recordSeparator")); - assertEquals("\n", resultPayload.get("meta.konductorConfig.streaming.lineFeed")); - assertNotNull(resultPayload.get("xdm.identityMap.ECID[0].id")); - assertEquals("false", resultPayload.get("xdm.identityMap.ECID[0].primary")); - assertEquals("ambiguous", resultPayload.get("xdm.identityMap.ECID[0].authenticatedState")); - assertNotNull(resultPayload.get("events[0].xdm._id")); - assertNotNull(resultPayload.get("events[0].xdm.timestamp")); - assertEquals("xdmValue", resultPayload.get("events[0].xdm.testString")); - assertEquals("stringValue", resultPayload.get("events[0].data.testString")); - assertEquals("101", resultPayload.get("events[0].data.testInt")); - assertEquals("true", resultPayload.get("events[0].data.testBool")); - assertEquals("13.66", resultPayload.get("events[0].data.testDouble")); - assertEquals("elem1", resultPayload.get("events[0].data.testArray[0]")); - assertEquals("elem2", resultPayload.get("events[0].data.testArray[1]")); - assertEquals("value", resultPayload.get("events[0].data.testMap.key")); - assertEquals("app", resultPayload.get("xdm.implementationDetails.environment")); - assertEquals( - EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE, - resultPayload.get("xdm.implementationDetails.name") - ); - assertEquals( - MobileCore.extensionVersion() + "+" + Edge.extensionVersion(), - resultPayload.get("xdm.implementationDetails.version") - ); + TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); + assertTrue(testableNetworkRequest.getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); + assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); + assertNotNull(testableNetworkRequest.queryParam("requestId")); - assertTrue(resultRequests.get(0).getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); - assertEquals(CONFIG_ID, resultRequests.get(0).queryParam("configId")); - assertNotNull(resultRequests.get(0).queryParam("requestId")); + String expected = "{" + + " \"events\": [" + + " {" + + " \"data\": {" + + " \"testArray\": [\"elem1\", \"elem2\"]," + + " \"testBool\": true," + + " \"testDouble\": 13.66," + + " \"testInt\": 101," + + " \"testMap\": {" + + " \"key\": \"value\"" + + " }," + + " \"testString\": \"stringValue\"" + + " }," + + " \"xdm\": {" + + " \"_id\": \"STRING_TYPE\"," + + " \"testString\": \"xdmValue\"," + + " \"timestamp\": \"STRING_TYPE\"" + + " }" + + " }" + + " ]," + + " \"meta\": {" + + " \"konductorConfig\": {" + + " \"streaming\": {" + + " \"enabled\": true," + + " \"lineFeed\": \"\\n\"," + + " \"recordSeparator\": \"\\u0000\"" + + " }" + + " }" + + " }," + + " \"xdm\": {" + + " \"identityMap\": {" + + " \"ECID\": [" + + " {" + + " \"authenticatedState\": \"ambiguous\"," + + " \"id\": \"STRING_TYPE\"," + + " \"primary\": false" + + " }" + + " ]" + + " }," + + " \"implementationDetails\": {" + + " \"environment\": \"app\"," + + " \"name\": \"" + EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE + "\"," + + " \"version\": \"" + MobileCore.extensionVersion() + "+" + Edge.extensionVersion() + "\"" + + " }" + + " }" + + "}"; + assertExactMatch(expected, getPayloadJson(resultRequests.get(0)), new CollectionEqualCount(Subtree), new ValueTypeMatch("xdm.identityMap.ECID[0].id", "events[0].xdm._id", "events[0].xdm.timestamp")); } @Test @@ -531,44 +596,66 @@ public void testSendEvent_withXDMSchema_sendsExEdgeNetworkRequest() throws Excep // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - Map resultPayload = mockNetworkService.getFlattenedNetworkRequestBody(resultRequests.get(0)); - assertEquals(17, resultPayload.size()); - - assertEquals("true", resultPayload.get("meta.konductorConfig.streaming.enabled")); - assertEquals("\u0000", resultPayload.get("meta.konductorConfig.streaming.recordSeparator")); - assertEquals("\n", resultPayload.get("meta.konductorConfig.streaming.lineFeed")); - assertNotNull(resultPayload.get("xdm.identityMap.ECID[0].id")); - assertEquals("false", resultPayload.get("xdm.identityMap.ECID[0].primary")); - assertEquals("ambiguous", resultPayload.get("xdm.identityMap.ECID[0].authenticatedState")); - assertNotNull(resultPayload.get("events[0].xdm._id")); - assertNotNull(resultPayload.get("events[0].xdm.timestamp")); - - assertEquals("testWithXdmSchema", resultPayload.get("events[0].xdm.stringObject")); - assertEquals("100", resultPayload.get("events[0].xdm.intObject")); - assertEquals("true", resultPayload.get("events[0].xdm.boolObject")); - assertEquals("3.42", resultPayload.get("events[0].xdm.doubleObject")); - assertEquals("testInnerObject", resultPayload.get("events[0].xdm.xdmObject.innerKey")); - assertEquals("abc123def", resultPayload.get("events[0].meta.collect.datasetId")); - - assertTrue(resultRequests.get(0).getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); - assertEquals(CONFIG_ID, resultRequests.get(0).queryParam("configId")); - assertNotNull(resultRequests.get(0).queryParam("requestId")); - - assertEquals("app", resultPayload.get("xdm.implementationDetails.environment")); - assertEquals( - EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE, - resultPayload.get("xdm.implementationDetails.name") - ); - assertEquals( - MobileCore.extensionVersion() + "+" + Edge.extensionVersion(), - resultPayload.get("xdm.implementationDetails.version") - ); + + TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); + assertTrue(testableNetworkRequest.getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); + assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); + assertNotNull(testableNetworkRequest.queryParam("requestId")); + + String expected = "{" + + " \"events\": [" + + " {" + + " \"meta\": {" + + " \"collect\": {" + + " \"datasetId\": \"abc123def\"" + + " }" + + " }," + + " \"xdm\": {" + + " \"_id\": \"STRING_TYPE\"," + + " \"boolObject\": true," + + " \"doubleObject\": 3.42," + + " \"intObject\": 100," + + " \"stringObject\": \"testWithXdmSchema\"," + + " \"timestamp\": \"STRING_TYPE\"," + + " \"xdmObject\": {" + + " \"innerKey\": \"testInnerObject\"" + + " }" + + " }" + + " }" + + " ]," + + " \"meta\": {" + + " \"konductorConfig\": {" + + " \"streaming\": {" + + " \"enabled\": true," + + " \"lineFeed\": \"\\n\"," + + " \"recordSeparator\": \"\\u0000\"" + + " }" + + " }" + + " }," + + " \"xdm\": {" + + " \"identityMap\": {" + + " \"ECID\": [" + + " {" + + " \"authenticatedState\": \"ambiguous\"," + + " \"id\": \"STRING_TYPE\"," + + " \"primary\": false" + + " }" + + " ]" + + " }," + + " \"implementationDetails\": {" + + " \"environment\": \"app\"," + + " \"name\": \"" + EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE + "\"," + + " \"version\": \"" + MobileCore.extensionVersion() + "+" + Edge.extensionVersion() + "\"" + + " }" + + " }" + + "}"; + assertExactMatch(expected, getPayloadJson(resultRequests.get(0)), new CollectionEqualCount(Subtree), new ValueTypeMatch("xdm.identityMap.ECID[0].id", "events[0].xdm._id", "events[0].xdm.timestamp")); } @Test @@ -579,7 +666,7 @@ public void testSendEvent_withEmptyXDMSchema_doesNotSendExEdgeNetworkRequest() t ExperienceEvent experienceEvent = new ExperienceEvent.Builder().setXdmSchema(new TestXDMSchema()).build(); Edge.sendEvent(experienceEvent, null); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST ); @@ -598,7 +685,7 @@ public void testSendEvent_withEmptyXDMSchemaAndEmptyData_doesNotSendExEdgeNetwor .build(); Edge.sendEvent(experienceEvent, null); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST ); @@ -617,7 +704,7 @@ public void testSendEvent_withEmptyXDMSchemaAndNullData_doesNotSendExEdgeNetwork .build(); Edge.sendEvent(experienceEvent, null); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST ); @@ -636,16 +723,17 @@ public void testSendEvent_withConfigurableEndpoint_withEmptyConfig_usesProductio // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( TestConstants.Defaults.EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - assertTrue(resultRequests.get(0).getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_URL_STRING)); - assertEquals(CONFIG_ID, resultRequests.get(0).queryParam("configId")); - assertNotNull(resultRequests.get(0).queryParam("requestId")); + TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); + assertTrue(testableNetworkRequest.getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_URL_STRING)); + assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); + assertNotNull(testableNetworkRequest.queryParam("requestId")); } @Test @@ -664,16 +752,17 @@ public void testSendEvent_withConfigurableEndpoint_withInvalidConfig_usesProduct // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( TestConstants.Defaults.EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - assertTrue(resultRequests.get(0).getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_URL_STRING)); - assertEquals(CONFIG_ID, resultRequests.get(0).queryParam("configId")); - assertNotNull(resultRequests.get(0).queryParam("requestId")); + TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); + assertTrue(testableNetworkRequest.getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_URL_STRING)); + assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); + assertNotNull(testableNetworkRequest.queryParam("requestId")); } @Test @@ -693,16 +782,17 @@ public void testSendEvent_withConfigurableEndpoint_withProdConfigEndpoint_usesPr // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( TestConstants.Defaults.EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - assertTrue(resultRequests.get(0).getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_URL_STRING)); - assertEquals(CONFIG_ID, resultRequests.get(0).queryParam("configId")); - assertNotNull(resultRequests.get(0).queryParam("requestId")); + TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); + assertTrue(testableNetworkRequest.getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_URL_STRING)); + assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); + assertNotNull(testableNetworkRequest.queryParam("requestId")); } @Test @@ -726,18 +816,19 @@ public void testSendEvent_withConfigurableEndpoint_withPreProdConfigEndpoint_use // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( TestConstants.Defaults.EXEDGE_INTERACT_PRE_PROD_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); + TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); assertTrue( - resultRequests.get(0).getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_PRE_PROD_URL_STRING) + testableNetworkRequest.getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_PRE_PROD_URL_STRING) ); - assertEquals(CONFIG_ID, resultRequests.get(0).queryParam("configId")); - assertNotNull(resultRequests.get(0).queryParam("requestId")); + assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); + assertNotNull(testableNetworkRequest.queryParam("requestId")); } @Test @@ -761,16 +852,17 @@ public void testSendEvent_withConfigurableEndpoint_withIntConfigEndpoint_usesInt // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( TestConstants.Defaults.EXEDGE_INTERACT_INT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - assertTrue(resultRequests.get(0).getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_INT_URL_STRING)); - assertEquals(CONFIG_ID, resultRequests.get(0).queryParam("configId")); - assertNotNull(resultRequests.get(0).queryParam("requestId")); + TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); + assertTrue(testableNetworkRequest.getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_INT_URL_STRING)); + assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); + assertNotNull(testableNetworkRequest.queryParam("requestId")); } // -------------------------------------------------------------------------------------------- @@ -778,7 +870,7 @@ public void testSendEvent_withConfigurableEndpoint_withIntConfigEndpoint_usesInt // -------------------------------------------------------------------------------------------- @Test - public void testSendEvent_twoConsecutiveCalls_appendsReceivedClientSideStore() throws InterruptedException { + public void testSendEvent_twoConsecutiveCalls_appendsReceivedClientSideStore() throws InterruptedException, JSONException { mockNetworkService.setExpectationForNetworkRequest(EXEDGE_INTERACT_URL_STRING, POST, 1); final String storeResponseBody = @@ -790,14 +882,13 @@ public void testSendEvent_twoConsecutiveCalls_appendsReceivedClientSideStore() t Edge.sendEvent(XDM_EXPERIENCE_EVENT, null); // first network call, no stored data - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - Map requestBody = mockNetworkService.getFlattenedNetworkRequestBody(resultRequests.get(0)); - assertEquals("Expected request body with 12 elements, but found: " + requestBody, 12, requestBody.size()); + assertTypeMatch("{}", getPayloadJson(resultRequests.get(0)), new ElementCount(12, Subtree)); assertExpectedEvents(true); resetTestExpectations(); @@ -810,31 +901,37 @@ public void testSendEvent_twoConsecutiveCalls_appendsReceivedClientSideStore() t resultRequests = mockNetworkService.getNetworkRequestsWith(EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS); assertEquals(1, resultRequests.size()); - requestBody = mockNetworkService.getFlattenedNetworkRequestBody(resultRequests.get(0)); - assertEquals("Expected request body with 18 elements, but found: " + requestBody, 18, requestBody.size()); - - String firstStore = requestBody.get("meta.state.entries[0].key"); - assertNotNull("client-side store not found", firstStore); - int identityIndex = firstStore.equals("kndctr_testOrg_AdobeOrg_identity") ? 0 : 1; - int consentIndex = firstStore.equals("kndctr_testOrg_AdobeOrg_identity") ? 1 : 0; - assertEquals( - "kndctr_testOrg_AdobeOrg_identity", - requestBody.get("meta.state.entries[" + identityIndex + "].key") - ); - assertEquals("hashed_value", requestBody.get("meta.state.entries[" + identityIndex + "].value")); - assertEquals("34128000", requestBody.get("meta.state.entries[" + identityIndex + "].maxAge")); - - assertEquals( - "kndctr_testOrg_AdobeOrg_consent_check", - requestBody.get("meta.state.entries[" + consentIndex + "].key") + TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); + assertTrue(testableNetworkRequest.getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); + assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); + assertNotNull(testableNetworkRequest.queryParam("requestId")); + + String expected = "{" + + " \"meta\": {" + + " \"state\": {" + + " \"entries\": [" + + " {" + + " \"key\": \"kndctr_testOrg_AdobeOrg_identity\"," + + " \"maxAge\": 34128000," + + " \"value\": \"hashed_value\"" + + " }," + + " {" + + " \"key\": \"kndctr_testOrg_AdobeOrg_consent_check\"," + + " \"maxAge\": 7200," + + " \"value\": \"1\"" + + " }" + + " ]" + + " }" + + " }" + + "}"; + assertExactMatch( + expected, + getPayloadJson(resultRequests.get(0)), + new CollectionEqualCount(Subtree, "meta.state.entries"), + new AnyOrderMatch("meta.state.entries"), + new ElementCount(18, Subtree) ); - assertEquals("1", requestBody.get("meta.state.entries[" + consentIndex + "].value")); - assertEquals("7200", requestBody.get("meta.state.entries[" + consentIndex + "].maxAge")); - - assertTrue(resultRequests.get(0).getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); - assertEquals(CONFIG_ID, resultRequests.get(0).queryParam("configId")); - assertNotNull(resultRequests.get(0).queryParam("requestId")); assertExpectedEvents(true); } @@ -858,14 +955,13 @@ public void testSendEvent_twoConsecutiveCalls_resetBefore_appendsReceivedClientS Edge.sendEvent(XDM_EXPERIENCE_EVENT, null); // first network call, no stored data - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - Map requestBody = mockNetworkService.getFlattenedNetworkRequestBody(resultRequests.get(0)); - assertEquals("Expected request body with 12 elements, but found: " + requestBody, 12, requestBody.size()); + assertTypeMatch("{}", getPayloadJson(resultRequests.get(0)), new ElementCount(12, Subtree)); assertExpectedEvents(true); resetTestExpectations(); @@ -876,33 +972,41 @@ public void testSendEvent_twoConsecutiveCalls_resetBefore_appendsReceivedClientS setExpectationEvent(EventType.EDGE, "state:store", 1); Edge.sendEvent(XDM_EXPERIENCE_EVENT, null); + // Validate resultRequests = mockNetworkService.getNetworkRequestsWith(EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS); assertEquals(1, resultRequests.size()); - requestBody = mockNetworkService.getFlattenedNetworkRequestBody(resultRequests.get(0)); - assertEquals("Expected request body with 18 elements, but found: " + requestBody, 18, requestBody.size()); - String firstStore = requestBody.get("meta.state.entries[0].key"); - assertNotNull("client-side store not found", firstStore); - int identityIndex = firstStore.equals("kndctr_testOrg_AdobeOrg_identity") ? 0 : 1; - int consentIndex = firstStore.equals("kndctr_testOrg_AdobeOrg_identity") ? 1 : 0; - - assertEquals( - "kndctr_testOrg_AdobeOrg_identity", - requestBody.get("meta.state.entries[" + identityIndex + "].key") - ); - assertEquals("hashed_value", requestBody.get("meta.state.entries[" + identityIndex + "].value")); - assertEquals("34128000", requestBody.get("meta.state.entries[" + identityIndex + "].maxAge")); - - assertEquals( - "kndctr_testOrg_AdobeOrg_consent_check", - requestBody.get("meta.state.entries[" + consentIndex + "].key") + // Validate network request query params + TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); + assertTrue(testableNetworkRequest.getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); + assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); + assertNotNull(testableNetworkRequest.queryParam("requestId")); + + String expected = "{" + + " \"meta\": {" + + " \"state\": {" + + " \"entries\": [" + + " {" + + " \"key\": \"kndctr_testOrg_AdobeOrg_identity\"," + + " \"maxAge\": 34128000," + + " \"value\": \"hashed_value\"" + + " }," + + " {" + + " \"key\": \"kndctr_testOrg_AdobeOrg_consent_check\"," + + " \"maxAge\": 7200," + + " \"value\": \"1\"" + + " }" + + " ]" + + " }" + + " }" + + "}"; + assertExactMatch( + expected, + getPayloadJson(resultRequests.get(0)), + new CollectionEqualCount(Subtree, "meta.state.entries"), + new AnyOrderMatch("meta.state.entries"), + new ElementCount(18, Subtree) ); - assertEquals("1", requestBody.get("meta.state.entries[" + consentIndex + "].value")); - assertEquals("7200", requestBody.get("meta.state.entries[" + consentIndex + "].maxAge")); - - assertTrue(resultRequests.get(0).getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); - assertEquals(CONFIG_ID, resultRequests.get(0).queryParam("configId")); - assertNotNull(resultRequests.get(0).queryParam("requestId")); assertExpectedEvents(true); } @@ -920,14 +1024,13 @@ public void testSendEvent_twoConsecutiveCalls_resetBetween_clearsClientSideStore Edge.sendEvent(XDM_EXPERIENCE_EVENT, null); // first network call, no stored data - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - Map requestBody = mockNetworkService.getFlattenedNetworkRequestBody(resultRequests.get(0)); - assertEquals("Expected request body with 12 elements, but found: " + requestBody, 12, requestBody.size()); + assertTypeMatch("{}", getPayloadJson(resultRequests.get(0)), new ElementCount(12, Subtree)); assertExpectedEvents(true); resetTestExpectations(); @@ -945,11 +1048,12 @@ public void testSendEvent_twoConsecutiveCalls_resetBetween_clearsClientSideStore resultRequests = mockNetworkService.getNetworkRequestsWith(EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS); assertEquals(1, resultRequests.size()); - requestBody = mockNetworkService.getFlattenedNetworkRequestBody(resultRequests.get(0)); - assertEquals("Expected request body with 12 elements, but found: " + requestBody, 12, requestBody.size()); - - String firstStore = requestBody.get("meta.state.entries[0].key"); - assertNull("client-side store was found", firstStore); + assertExactMatch( + "{}", + getPayloadJson(resultRequests.get(0)), + new ElementCount(12, Subtree), + new KeyMustBeAbsent("meta.state.entries[0].key") + ); } // -------------------------------------------------------------------------------------------- @@ -973,13 +1077,14 @@ public void testSendEvent_receivesResponseEventHandle_sendsResponseEvent_pairedW mockNetworkService.assertAllNetworkRequestExpectations(); assertExpectedEvents(true); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - String requestId = resultRequests.get(0).queryParam("requestId"); + TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); + String requestId = testableNetworkRequest.queryParam("requestId"); List requestEvents = getDispatchedEventsWith(EventType.EDGE, EventSource.REQUEST_CONTENT); assertEquals(1, requestEvents.size()); @@ -987,24 +1092,29 @@ public void testSendEvent_receivesResponseEventHandle_sendsResponseEvent_pairedW List responseEvents = getDispatchedEventsWith(EventType.EDGE, "personalization:decisions"); assertEquals(1, responseEvents.size()); - Map responseEventData = responseEvents.get(0).getEventData(); - assertNotNull(responseEventData); - - Map flattenedEventData = TestUtils.flattenMap(responseEventData); - assertEquals(7, flattenedEventData.size()); - assertEquals("personalization:decisions", flattenedEventData.get("type")); - assertEquals( - "AT:eyJhY3Rpdml0eUlkIjoiMTE3NTg4IiwiZXhwZXJpZW5jZUlkIjoiMSJ9", - flattenedEventData.get("payload[0].id") - ); - assertEquals("#D41DBA", flattenedEventData.get("payload[0].items[0].data.content.value")); - assertEquals( - "https://ns.adobe.com/personalization/json-content-item", - flattenedEventData.get("payload[0].items[0].schema") - ); - assertEquals("buttonColor", flattenedEventData.get("payload[0].scope")); - assertEquals(requestId, flattenedEventData.get("requestId")); - assertEquals(requestEventUuid, flattenedEventData.get("requestEventId")); + + String expected = "{" + + " \"payload\": [" + + " {" + + " \"id\": \"AT:eyJhY3Rpdml0eUlkIjoiMTE3NTg4IiwiZXhwZXJpZW5jZUlkIjoiMSJ9\"," + + " \"items\": [" + + " {" + + " \"data\": {" + + " \"content\": {" + + " \"value\": \"#D41DBA\"" + + " }" + + " }," + + " \"schema\": \"https://ns.adobe.com/personalization/json-content-item\"" + + " }" + + " ]," + + " \"scope\": \"buttonColor\"" + + " }" + + " ]," + + " \"requestEventId\": \"" + requestEventUuid + "\"," + + " \"requestId\": \"" + requestId + "\"," + + " \"type\": \"personalization:decisions\"" + + "}"; + JSONAsserts.assertEquals(expected, responseEvents.get(0).getEventData()); assertEquals(requestEventUuid, responseEvents.get(0).getParentID()); } @@ -1035,13 +1145,14 @@ public void testSendEvent_receivesResponseEventWarning_sendsErrorResponseEvent_p mockNetworkService.assertAllNetworkRequestExpectations(); assertExpectedEvents(false); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - String requestId = resultRequests.get(0).queryParam("requestId"); + TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); + String requestId = testableNetworkRequest.queryParam("requestId"); List requestEvents = getDispatchedEventsWith(EventType.EDGE, EventSource.REQUEST_CONTENT); assertEquals(1, requestEvents.size()); @@ -1049,15 +1160,14 @@ public void testSendEvent_receivesResponseEventWarning_sendsErrorResponseEvent_p List errorResponseEvents = getDispatchedEventsWith(EventType.EDGE, EventSource.ERROR_RESPONSE_CONTENT); assertEquals(1, errorResponseEvents.size()); - Map responseEventData = errorResponseEvents.get(0).getEventData(); - assertNotNull(responseEventData); - - Map flattenedEventData = TestUtils.flattenMap(responseEventData); - assertEquals(4, flattenedEventData.size()); - assertEquals("personalization:0", flattenedEventData.get("code")); - assertEquals("Failed due to unrecoverable system error", flattenedEventData.get("message")); - assertEquals(requestId, flattenedEventData.get("requestId")); - assertEquals(requestEventUuid, flattenedEventData.get("requestEventId")); + + String expected = "{" + + " \"code\": \"personalization:0\"," + + " \"message\": \"Failed due to unrecoverable system error\"," + + " \"requestEventId\": \"" + requestEventUuid + "\"," + + " \"requestId\": \"" + requestId + "\"" + + "}"; + JSONAsserts.assertEquals(expected, errorResponseEvents.get(0).getEventData()); assertEquals(requestEventUuid, errorResponseEvents.get(0).getParentID()); } @@ -1082,7 +1192,7 @@ public void testSendEvent_edgeNetworkResponseContainsLocationHint_nextSendEventI Edge.sendEvent(XDM_EXPERIENCE_EVENT, null); // first network call, no location hint - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS @@ -1115,7 +1225,7 @@ public void testSendEvent_edgeNetworkResponseContainsLocationHint_sendEventDoesN Edge.sendEvent(XDM_EXPERIENCE_EVENT, null); // all network calls, no location hint - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS @@ -1219,7 +1329,7 @@ public void testSetLocationHint_withValueHint_edgeNetworkResponseContainsLocatio Edge.sendEvent(XDM_EXPERIENCE_EVENT, null); // send event // verify send event request includes set location hint - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_OR2_LOC_URL_STRING, POST, TIMEOUT_MILLIS @@ -1241,7 +1351,7 @@ public void testSetLocationHint_withHintWithSpaces_edgeNetworkResponseContainsLo Edge.sendEvent(XDM_EXPERIENCE_EVENT, null); // send event // verify send event request includes set location hint - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( "https://edge.adobedc.net/ee/incorrect location hint/v1/interact", POST, TIMEOUT_MILLIS @@ -1263,7 +1373,7 @@ public void testSetLocationHint_withHintWithSpecialCharacters_edgeNetworkRespons Edge.sendEvent(XDM_EXPERIENCE_EVENT, null); // send event // verify send event request includes set location hint - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( "https://edge.adobedc.net/ee/{\"example\":\"incorrect\"}/v1/interact", POST, TIMEOUT_MILLIS @@ -1285,7 +1395,7 @@ public void testSetLocationHint_withHintWithUnicodeCharacters_edgeNetworkRespons Edge.sendEvent(XDM_EXPERIENCE_EVENT, null); // send event // verify send event request includes set location hint - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( "https://edge.adobedc.net/ee/\u0048\u0065\u006C\u006C\u006F/v1/interact", POST, TIMEOUT_MILLIS @@ -1420,7 +1530,8 @@ public void testSendEvent_withXDMData_sendsExEdgeNetworkRequest_afterRetry() thr mockNetworkService.setMockResponseFor(EXEDGE_INTERACT_URL_STRING, POST, responseConnection); setExpectationEvent(EventType.EDGE, EventSource.ERROR_RESPONSE_CONTENT, 1); - mockNetworkService.assertAllNetworkRequestExpectations(); + // Edge retry interval is 5 sec + mockNetworkService.assertAllNetworkRequestExpectations(true, true, 6000); assertExpectedEvents(true); } @@ -1503,7 +1614,8 @@ public void testSendEvent_withXDMData_sendsExEdgeNetworkRequest_afterRetryMultip mockNetworkService.setMockResponseFor(EXEDGE_INTERACT_URL_STRING, POST, responseConnection); setExpectationEvent(EventType.EDGE, EventSource.ERROR_RESPONSE_CONTENT, 2); - mockNetworkService.assertAllNetworkRequestExpectations(); + // Edge retry interval is 5 sec + mockNetworkService.assertAllNetworkRequestExpectations(true, true, 6000); assertExpectedEvents(false); } @@ -1531,28 +1643,28 @@ public void testSendEvent_multiStatusResponse_dispatchesEvents() throws Interrup List resultEvents = getDispatchedEventsWith(EventType.EDGE, EventSource.ERROR_RESPONSE_CONTENT); assertEquals(2, resultEvents.size()); - Map eventData1 = TestUtils.flattenMap(resultEvents.get(0).getEventData()); - assertEquals(5, eventData1.size()); - assertEquals("504", eventData1.get("status")); - assertEquals("https://ns.adobe.com/aep/errors/EXEG-0201-504", eventData1.get("type")); - assertEquals( - "The 'com.adobe.experience.platform.ode' service is temporarily unable to serve this request. Please try again later.", - eventData1.get("title") - ); - assertEquals(requestEvents.get(0).getUniqueIdentifier(), eventData1.get("requestEventId")); + String expectedEventData1 = "{" + + " \"requestEventId\": \"" + requestEvents.get(0).getUniqueIdentifier() + "\"," + + " \"status\": 504," + + " \"title\": \"The 'com.adobe.experience.platform.ode' service is temporarily unable to serve this request. Please try again later.\"," + + " \"type\": \"https://ns.adobe.com/aep/errors/EXEG-0201-504\"" + + "}"; + assertExactMatch(expectedEventData1, resultEvents.get(0).getEventData(), new ElementCount(5, Subtree)); assertEquals(requestEvents.get(0).getUniqueIdentifier(), resultEvents.get(0).getParentID()); - Map eventData2 = TestUtils.flattenMap(resultEvents.get(1).getEventData()); - assertEquals(7, eventData2.size()); - assertEquals("200", eventData2.get("status")); - assertEquals("https://ns.adobe.com/aep/errors/EXEG-0204-200", eventData2.get("type")); - assertEquals( - "A warning occurred while calling the 'com.adobe.audiencemanager' service for this request.", - eventData2.get("title") - ); - assertEquals("Cannot read related customer for device id: ...", eventData2.get("report.cause.message")); - assertEquals("202", eventData2.get("report.cause.code")); - assertEquals(requestEvents.get(0).getUniqueIdentifier(), eventData2.get("requestEventId")); + String expectedEventData2 = "{" + + " \"report\": {" + + " \"cause\": {" + + " \"code\": 202," + + " \"message\": \"Cannot read related customer for device id: ...\"" + + " }" + + " }," + + " \"requestEventId\": \"" + requestEvents.get(0).getUniqueIdentifier() + "\"," + + " \"status\": 200," + + " \"title\": \"A warning occurred while calling the 'com.adobe.audiencemanager' service for this request.\"," + + " \"type\": \"https://ns.adobe.com/aep/errors/EXEG-0204-200\"" + + "}"; + assertExactMatch(expectedEventData2, resultEvents.get(1).getEventData(), new ElementCount(7, Subtree)); assertEquals(requestEvents.get(0).getUniqueIdentifier(), resultEvents.get(1).getParentID()); } @@ -1600,25 +1712,23 @@ public void testSendEvent_fatalError() throws InterruptedException { List resultEvents = getDispatchedEventsWith(EventType.EDGE, EventSource.ERROR_RESPONSE_CONTENT); assertEquals(1, resultEvents.size()); - Map eventData = TestUtils.flattenMap(resultEvents.get(0).getEventData()); - - assertEquals(11, eventData.size()); - assertEquals("422", eventData.get("status")); - assertEquals("https://ns.adobe.com/aep/errors/EXEG-0104-422", eventData.get("type")); - assertEquals("Unprocessable Entity", eventData.get("title")); - assertEquals( - "Invalid request (report attached). Please check your input and try again.", - eventData.get("detail") - ); - assertEquals("Allowed Adobe version is 1.0 for standard 'Adobe' at index 0", eventData.get("report.errors[0]")); - assertEquals("Allowed IAB version is 2.0 for standard 'IAB TCF' at index 1", eventData.get("report.errors[1]")); - assertEquals( - "IAB consent string value must not be empty for standard 'IAB TCF' at index 1", - eventData.get("report.errors[2]") - ); - assertEquals("0f8821e5-ed1a-4301-b445-5f336fb50ee8", eventData.get("report.requestId")); - assertEquals("test@AdobeOrg", eventData.get("report.orgId")); - assertEquals(requestEvents.get(0).getUniqueIdentifier(), eventData.get("requestEventId")); + String expected = "{" + + " \"detail\": \"Invalid request (report attached). Please check your input and try again.\"," + + " \"report\": {" + + " \"errors\": [" + + " \"Allowed Adobe version is 1.0 for standard 'Adobe' at index 0\"," + + " \"Allowed IAB version is 2.0 for standard 'IAB TCF' at index 1\"," + + " \"IAB consent string value must not be empty for standard 'IAB TCF' at index 1\"" + + " ]," + + " \"orgId\": \"test@AdobeOrg\"," + + " \"requestId\": \"0f8821e5-ed1a-4301-b445-5f336fb50ee8\"" + + " }," + + " \"requestEventId\": \"" + requestEvents.get(0).getUniqueIdentifier() + "\"," + + " \"status\": 422," + + " \"title\": \"Unprocessable Entity\"," + + " \"type\": \"https://ns.adobe.com/aep/errors/EXEG-0104-422\"" + + "}"; + assertExactMatch(expected, resultEvents.get(0).getEventData(), new ElementCount(11, Subtree)); assertEquals(requestEvents.get(0).getUniqueIdentifier(), resultEvents.get(0).getParentID()); } @@ -1637,4 +1747,18 @@ private void updateConfiguration(final Map config) throws Interr assertTrue(latch.await(2, TimeUnit.SECONDS)); } + + private JSONObject getPayloadJson(NetworkRequest networkRequest) { + if (networkRequest == null || networkRequest.getBody() == null) { + return null; + } + + String payload = new String(networkRequest.getBody()); + try { + return new JSONObject(payload); + } catch (Exception e) { + fail("Failed to create JSONObject from payload: " + e.getMessage()); + return null; + } + } } From dc1c9d30da7fd906cbead07ab8155b737f4e7bf0 Mon Sep 17 00:00:00 2001 From: timkimadobe <95260439+timkimadobe@users.noreply.github.com> Date: Wed, 29 May 2024 18:18:46 -0700 Subject: [PATCH 02/11] Apply lint formatting to EdgeFunctionalTests.java --- .../marketing/mobile/EdgeFunctionalTests.java | 126 +++++++++++++----- 1 file changed, 90 insertions(+), 36 deletions(-) diff --git a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java index 72c4488a..242e55cc 100644 --- a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java +++ b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java @@ -47,7 +47,6 @@ import com.adobe.marketing.mobile.util.TestHelper; import com.adobe.marketing.mobile.util.TestXDMSchema; import com.adobe.marketing.mobile.util.ValueTypeMatch; - import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -57,7 +56,6 @@ import java.util.TimeZone; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; - import org.json.JSONException; import org.json.JSONObject; import org.junit.After; @@ -167,7 +165,8 @@ public void testSendEvent_withXDMData_sendsCorrectRequestEvent() throws Interrup List resultEvents = getDispatchedEventsWith(EventType.EDGE, EventSource.REQUEST_CONTENT); assertEquals(1, resultEvents.size()); - String expected = "{" + + String expected = + "{" + " \"xdm\": {" + " \"testString\": \"xdm\"," + " \"testInt\": 10," + @@ -232,7 +231,8 @@ public void testSendEvent_withXDMDataAndCustomData_sendsCorrectRequestEvent() th List resultEvents = getDispatchedEventsWith(EventType.EDGE, EventSource.REQUEST_CONTENT); assertEquals(1, resultEvents.size()); - String expected = "{" + + String expected = + "{" + " \"xdm\": {" + " \"testString\": \"xdm\"" + " }," + @@ -274,11 +274,7 @@ public void testSendEvent_withXDMDataAndNullData_sendsCorrectRequestEvent() thro List resultEvents = getDispatchedEventsWith(EventType.EDGE, EventSource.REQUEST_CONTENT); assertEquals(1, resultEvents.size()); - String expected = "{" + - " \"xdm\": {" + - " \"testString\": \"xdm\"" + - " }" + - "}"; + String expected = "{" + " \"xdm\": {" + " \"testString\": \"xdm\"" + " }" + "}"; JSONAsserts.assertEquals(expected, resultEvents.get(0).getEventData()); } @@ -422,7 +418,8 @@ public void testSendEvent_withXDMData_sendsExEdgeNetworkRequest() throws Excepti assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); assertNotNull(testableNetworkRequest.queryParam("requestId")); - String expected = "{" + + String expected = + "{" + " \"events\": [" + " {" + " \"xdm\": {" + @@ -460,13 +457,24 @@ public void testSendEvent_withXDMData_sendsExEdgeNetworkRequest() throws Excepti " }," + " \"implementationDetails\": {" + " \"environment\": \"app\"," + - " \"name\": \"" + EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE + "\"," + - " \"version\": \"" + MobileCore.extensionVersion() + "+" + Edge.extensionVersion() + "\"" + + " \"name\": \"" + + EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE + + "\"," + + " \"version\": \"" + + MobileCore.extensionVersion() + + "+" + + Edge.extensionVersion() + + "\"" + " }" + " }" + "}"; - assertExactMatch(expected, getPayloadJson(resultRequests.get(0)), new CollectionEqualCount(Subtree), new ValueTypeMatch("xdm.identityMap.ECID[0].id", "events[0].xdm._id", "events[0].xdm.timestamp")); + assertExactMatch( + expected, + getPayloadJson(resultRequests.get(0)), + new CollectionEqualCount(Subtree), + new ValueTypeMatch("xdm.identityMap.ECID[0].id", "events[0].xdm._id", "events[0].xdm.timestamp") + ); } @Test @@ -527,7 +535,8 @@ public void testSendEvent_withXDMDataAndCustomData_sendsExEdgeNetworkRequest() t assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); assertNotNull(testableNetworkRequest.queryParam("requestId")); - String expected = "{" + + String expected = + "{" + " \"events\": [" + " {" + " \"data\": {" + @@ -568,12 +577,23 @@ public void testSendEvent_withXDMDataAndCustomData_sendsExEdgeNetworkRequest() t " }," + " \"implementationDetails\": {" + " \"environment\": \"app\"," + - " \"name\": \"" + EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE + "\"," + - " \"version\": \"" + MobileCore.extensionVersion() + "+" + Edge.extensionVersion() + "\"" + + " \"name\": \"" + + EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE + + "\"," + + " \"version\": \"" + + MobileCore.extensionVersion() + + "+" + + Edge.extensionVersion() + + "\"" + " }" + " }" + "}"; - assertExactMatch(expected, getPayloadJson(resultRequests.get(0)), new CollectionEqualCount(Subtree), new ValueTypeMatch("xdm.identityMap.ECID[0].id", "events[0].xdm._id", "events[0].xdm.timestamp")); + assertExactMatch( + expected, + getPayloadJson(resultRequests.get(0)), + new CollectionEqualCount(Subtree), + new ValueTypeMatch("xdm.identityMap.ECID[0].id", "events[0].xdm._id", "events[0].xdm.timestamp") + ); } @Test @@ -608,7 +628,8 @@ public void testSendEvent_withXDMSchema_sendsExEdgeNetworkRequest() throws Excep assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); assertNotNull(testableNetworkRequest.queryParam("requestId")); - String expected = "{" + + String expected = + "{" + " \"events\": [" + " {" + " \"meta\": {" + @@ -650,12 +671,23 @@ public void testSendEvent_withXDMSchema_sendsExEdgeNetworkRequest() throws Excep " }," + " \"implementationDetails\": {" + " \"environment\": \"app\"," + - " \"name\": \"" + EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE + "\"," + - " \"version\": \"" + MobileCore.extensionVersion() + "+" + Edge.extensionVersion() + "\"" + + " \"name\": \"" + + EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE + + "\"," + + " \"version\": \"" + + MobileCore.extensionVersion() + + "+" + + Edge.extensionVersion() + + "\"" + " }" + " }" + "}"; - assertExactMatch(expected, getPayloadJson(resultRequests.get(0)), new CollectionEqualCount(Subtree), new ValueTypeMatch("xdm.identityMap.ECID[0].id", "events[0].xdm._id", "events[0].xdm.timestamp")); + assertExactMatch( + expected, + getPayloadJson(resultRequests.get(0)), + new CollectionEqualCount(Subtree), + new ValueTypeMatch("xdm.identityMap.ECID[0].id", "events[0].xdm._id", "events[0].xdm.timestamp") + ); } @Test @@ -870,7 +902,8 @@ public void testSendEvent_withConfigurableEndpoint_withIntConfigEndpoint_usesInt // -------------------------------------------------------------------------------------------- @Test - public void testSendEvent_twoConsecutiveCalls_appendsReceivedClientSideStore() throws InterruptedException, JSONException { + public void testSendEvent_twoConsecutiveCalls_appendsReceivedClientSideStore() + throws InterruptedException, JSONException { mockNetworkService.setExpectationForNetworkRequest(EXEDGE_INTERACT_URL_STRING, POST, 1); final String storeResponseBody = @@ -907,7 +940,8 @@ public void testSendEvent_twoConsecutiveCalls_appendsReceivedClientSideStore() t assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); assertNotNull(testableNetworkRequest.queryParam("requestId")); - String expected = "{" + + String expected = + "{" + " \"meta\": {" + " \"state\": {" + " \"entries\": [" + @@ -982,7 +1016,8 @@ public void testSendEvent_twoConsecutiveCalls_resetBefore_appendsReceivedClientS assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); assertNotNull(testableNetworkRequest.queryParam("requestId")); - String expected = "{" + + String expected = + "{" + " \"meta\": {" + " \"state\": {" + " \"entries\": [" + @@ -1093,7 +1128,8 @@ public void testSendEvent_receivesResponseEventHandle_sendsResponseEvent_pairedW List responseEvents = getDispatchedEventsWith(EventType.EDGE, "personalization:decisions"); assertEquals(1, responseEvents.size()); - String expected = "{" + + String expected = + "{" + " \"payload\": [" + " {" + " \"id\": \"AT:eyJhY3Rpdml0eUlkIjoiMTE3NTg4IiwiZXhwZXJpZW5jZUlkIjoiMSJ9\"," + @@ -1110,8 +1146,12 @@ public void testSendEvent_receivesResponseEventHandle_sendsResponseEvent_pairedW " \"scope\": \"buttonColor\"" + " }" + " ]," + - " \"requestEventId\": \"" + requestEventUuid + "\"," + - " \"requestId\": \"" + requestId + "\"," + + " \"requestEventId\": \"" + + requestEventUuid + + "\"," + + " \"requestId\": \"" + + requestId + + "\"," + " \"type\": \"personalization:decisions\"" + "}"; JSONAsserts.assertEquals(expected, responseEvents.get(0).getEventData()); @@ -1161,11 +1201,16 @@ public void testSendEvent_receivesResponseEventWarning_sendsErrorResponseEvent_p List errorResponseEvents = getDispatchedEventsWith(EventType.EDGE, EventSource.ERROR_RESPONSE_CONTENT); assertEquals(1, errorResponseEvents.size()); - String expected = "{" + + String expected = + "{" + " \"code\": \"personalization:0\"," + " \"message\": \"Failed due to unrecoverable system error\"," + - " \"requestEventId\": \"" + requestEventUuid + "\"," + - " \"requestId\": \"" + requestId + "\"" + + " \"requestEventId\": \"" + + requestEventUuid + + "\"," + + " \"requestId\": \"" + + requestId + + "\"" + "}"; JSONAsserts.assertEquals(expected, errorResponseEvents.get(0).getEventData()); assertEquals(requestEventUuid, errorResponseEvents.get(0).getParentID()); @@ -1643,8 +1688,11 @@ public void testSendEvent_multiStatusResponse_dispatchesEvents() throws Interrup List resultEvents = getDispatchedEventsWith(EventType.EDGE, EventSource.ERROR_RESPONSE_CONTENT); assertEquals(2, resultEvents.size()); - String expectedEventData1 = "{" + - " \"requestEventId\": \"" + requestEvents.get(0).getUniqueIdentifier() + "\"," + + String expectedEventData1 = + "{" + + " \"requestEventId\": \"" + + requestEvents.get(0).getUniqueIdentifier() + + "\"," + " \"status\": 504," + " \"title\": \"The 'com.adobe.experience.platform.ode' service is temporarily unable to serve this request. Please try again later.\"," + " \"type\": \"https://ns.adobe.com/aep/errors/EXEG-0201-504\"" + @@ -1652,14 +1700,17 @@ public void testSendEvent_multiStatusResponse_dispatchesEvents() throws Interrup assertExactMatch(expectedEventData1, resultEvents.get(0).getEventData(), new ElementCount(5, Subtree)); assertEquals(requestEvents.get(0).getUniqueIdentifier(), resultEvents.get(0).getParentID()); - String expectedEventData2 = "{" + + String expectedEventData2 = + "{" + " \"report\": {" + " \"cause\": {" + " \"code\": 202," + " \"message\": \"Cannot read related customer for device id: ...\"" + " }" + " }," + - " \"requestEventId\": \"" + requestEvents.get(0).getUniqueIdentifier() + "\"," + + " \"requestEventId\": \"" + + requestEvents.get(0).getUniqueIdentifier() + + "\"," + " \"status\": 200," + " \"title\": \"A warning occurred while calling the 'com.adobe.audiencemanager' service for this request.\"," + " \"type\": \"https://ns.adobe.com/aep/errors/EXEG-0204-200\"" + @@ -1712,7 +1763,8 @@ public void testSendEvent_fatalError() throws InterruptedException { List resultEvents = getDispatchedEventsWith(EventType.EDGE, EventSource.ERROR_RESPONSE_CONTENT); assertEquals(1, resultEvents.size()); - String expected = "{" + + String expected = + "{" + " \"detail\": \"Invalid request (report attached). Please check your input and try again.\"," + " \"report\": {" + " \"errors\": [" + @@ -1723,7 +1775,9 @@ public void testSendEvent_fatalError() throws InterruptedException { " \"orgId\": \"test@AdobeOrg\"," + " \"requestId\": \"0f8821e5-ed1a-4301-b445-5f336fb50ee8\"" + " }," + - " \"requestEventId\": \"" + requestEvents.get(0).getUniqueIdentifier() + "\"," + + " \"requestEventId\": \"" + + requestEvents.get(0).getUniqueIdentifier() + + "\"," + " \"status\": 422," + " \"title\": \"Unprocessable Entity\"," + " \"type\": \"https://ns.adobe.com/aep/errors/EXEG-0104-422\"" + From 55e012bce87498bf550b74ea7cf86a94d15e5f47 Mon Sep 17 00:00:00 2001 From: timkimadobe <95260439+timkimadobe@users.noreply.github.com> Date: Thu, 30 May 2024 16:25:25 -0700 Subject: [PATCH 03/11] Update EdgePathOverwriteTests.java to use JSON comparison APIs --- .../mobile/EdgePathOverwriteTests.java | 191 ++++++++++++------ 1 file changed, 131 insertions(+), 60 deletions(-) diff --git a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java index a68e81ca..e515448b 100644 --- a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java +++ b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java @@ -12,28 +12,37 @@ package com.adobe.marketing.mobile; import static com.adobe.marketing.mobile.services.HttpMethod.POST; +import static com.adobe.marketing.mobile.util.JSONAsserts.assertExactMatch; +import static com.adobe.marketing.mobile.util.NodeConfig.Scope.Subtree; import static com.adobe.marketing.mobile.util.TestHelper.assertExpectedEvents; import static com.adobe.marketing.mobile.util.TestHelper.resetTestExpectations; import static com.adobe.marketing.mobile.util.TestHelper.setExpectationEvent; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.adobe.marketing.mobile.edge.identity.Identity; import com.adobe.marketing.mobile.services.HttpConnecting; import com.adobe.marketing.mobile.services.ServiceProvider; +import com.adobe.marketing.mobile.services.NetworkRequest; import com.adobe.marketing.mobile.services.TestableNetworkRequest; +import com.adobe.marketing.mobile.util.CollectionEqualCount; import com.adobe.marketing.mobile.util.MockNetworkService; import com.adobe.marketing.mobile.util.MonitorExtension; import com.adobe.marketing.mobile.util.TestConstants; import com.adobe.marketing.mobile.util.TestHelper; +import com.adobe.marketing.mobile.util.ValueTypeMatch; + import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.CountDownLatch; + +import org.json.JSONObject; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -142,44 +151,68 @@ public void testSendEvent_withXDMData_withOverwritePath_overwritesRequestPathAnd // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_MEDIA_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - Map resultPayload = mockNetworkService.getFlattenedNetworkRequestBody(resultRequests.get(0)); - assertEquals(18, resultPayload.size()); - assertEquals("true", resultPayload.get("meta.konductorConfig.streaming.enabled")); - assertEquals("\u0000", resultPayload.get("meta.konductorConfig.streaming.recordSeparator")); - assertEquals("\n", resultPayload.get("meta.konductorConfig.streaming.lineFeed")); - assertNotNull(resultPayload.get("xdm.identityMap.ECID[0].id")); - assertEquals("false", resultPayload.get("xdm.identityMap.ECID[0].primary")); - assertEquals("ambiguous", resultPayload.get("xdm.identityMap.ECID[0].authenticatedState")); - assertNotNull(resultPayload.get("events[0].xdm._id")); - assertNotNull(resultPayload.get("events[0].xdm.timestamp")); - assertEquals("xdmValue", resultPayload.get("events[0].xdm.testString")); - assertEquals("10", resultPayload.get("events[0].xdm.testInt")); - assertEquals("false", resultPayload.get("events[0].xdm.testBool")); - assertEquals("12.89", resultPayload.get("events[0].xdm.testDouble")); - assertEquals("elem1", resultPayload.get("events[0].xdm.testArray[0]")); - assertEquals("elem2", resultPayload.get("events[0].xdm.testArray[1]")); - assertEquals("value", resultPayload.get("events[0].xdm.testMap.key")); - - assertTrue(resultRequests.get(0).getUrl().startsWith(EXEDGE_MEDIA_URL_STRING)); - assertEquals(CONFIG_ID, resultRequests.get(0).queryParam("configId")); - assertNotNull(resultRequests.get(0).queryParam("requestId")); + String expected = "{" + + " \"events\": [" + + " {" + + " \"xdm\": {" + + " \"_id\": \"STRING_TYPE\"," + + " \"testArray\": [\"elem1\", \"elem2\"]," + + " \"testBool\": false," + + " \"testDouble\": 12.89," + + " \"testInt\": 10," + + " \"testMap\": {" + + " \"key\": \"value\"" + + " }," + + " \"testString\": \"xdmValue\"," + + " \"timestamp\": \"STRING_TYPE\"" + + " }" + + " }" + + " ]," + + " \"meta\": {" + + " \"konductorConfig\": {" + + " \"streaming\": {" + + " \"enabled\": true," + + " \"lineFeed\": \"\\n\"," + + " \"recordSeparator\": \"\\u0000\"" + + " }" + + " }" + + " }," + + " \"xdm\": {" + + " \"identityMap\": {" + + " \"ECID\": [" + + " {" + + " \"authenticatedState\": \"ambiguous\"," + + " \"id\": \"STRING_TYPE\"," + + " \"primary\": false" + + " }" + + " ]" + + " }," + + " \"implementationDetails\": {" + + " \"environment\": \"app\"," + + " \"name\": \"" + EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE + "\"," + + " \"version\": \"" + MobileCore.extensionVersion() + "+" + Edge.extensionVersion() + "\"" + + " }" + + " }" + + "}"; - assertEquals("app", resultPayload.get("xdm.implementationDetails.environment")); - assertEquals( - EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE, - resultPayload.get("xdm.implementationDetails.name") - ); - assertEquals( - MobileCore.extensionVersion() + "+" + Edge.extensionVersion(), - resultPayload.get("xdm.implementationDetails.version") + assertExactMatch( + expected, + getPayloadJson(resultRequests.get(0)), + new CollectionEqualCount(Subtree), + new ValueTypeMatch("xdm.identityMap.ECID[0].id", "events[0].xdm._id", "events[0].xdm.timestamp") ); + + TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); + assertTrue(testableNetworkRequest.getUrl().startsWith(EXEDGE_MEDIA_URL_STRING)); + assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); + assertNotNull(testableNetworkRequest.queryParam("requestId")); } @Test @@ -239,43 +272,81 @@ public void testSendEvent_withXDMData_withOverwritePath_withLocationHintSet_over // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_MEDIA_OR2_LOC_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - Map resultPayload = mockNetworkService.getFlattenedNetworkRequestBody(resultRequests.get(0)); - assertEquals(18, resultPayload.size()); - assertEquals("true", resultPayload.get("meta.konductorConfig.streaming.enabled")); - assertEquals("\u0000", resultPayload.get("meta.konductorConfig.streaming.recordSeparator")); - assertEquals("\n", resultPayload.get("meta.konductorConfig.streaming.lineFeed")); - assertNotNull(resultPayload.get("xdm.identityMap.ECID[0].id")); - assertEquals("false", resultPayload.get("xdm.identityMap.ECID[0].primary")); - assertEquals("ambiguous", resultPayload.get("xdm.identityMap.ECID[0].authenticatedState")); - assertNotNull(resultPayload.get("events[0].xdm._id")); - assertNotNull(resultPayload.get("events[0].xdm.timestamp")); - assertEquals("xdmValue", resultPayload.get("events[0].xdm.testString")); - assertEquals("10", resultPayload.get("events[0].xdm.testInt")); - assertEquals("false", resultPayload.get("events[0].xdm.testBool")); - assertEquals("12.89", resultPayload.get("events[0].xdm.testDouble")); - assertEquals("elem1", resultPayload.get("events[0].xdm.testArray[0]")); - assertEquals("elem2", resultPayload.get("events[0].xdm.testArray[1]")); - assertEquals("value", resultPayload.get("events[0].xdm.testMap.key")); - - assertTrue(resultRequests.get(0).getUrl().startsWith(EXEDGE_MEDIA_OR2_LOC_URL_STRING)); - assertEquals(CONFIG_ID, resultRequests.get(0).queryParam("configId")); - assertNotNull(resultRequests.get(0).queryParam("requestId")); + String expected = "{" + + " \"events\": [" + + " {" + + " \"xdm\": {" + + " \"_id\": \"STRING_TYPE\"," + + " \"testArray\": [\"elem1\", \"elem2\"]," + + " \"testBool\": false," + + " \"testDouble\": 12.89," + + " \"testInt\": 10," + + " \"testMap\": {" + + " \"key\": \"value\"" + + " }," + + " \"testString\": \"xdmValue\"," + + " \"timestamp\": \"STRING_TYPE\"" + + " }" + + " }" + + " ]," + + " \"meta\": {" + + " \"konductorConfig\": {" + + " \"streaming\": {" + + " \"enabled\": true," + + " \"lineFeed\": \"\\n\"," + + " \"recordSeparator\": \"\\u0000\"" + + " }" + + " }" + + " }," + + " \"xdm\": {" + + " \"identityMap\": {" + + " \"ECID\": [" + + " {" + + " \"authenticatedState\": \"ambiguous\"," + + " \"id\": \"STRING_TYPE\"," + + " \"primary\": false" + + " }" + + " ]" + + " }," + + " \"implementationDetails\": {" + + " \"environment\": \"app\"," + + " \"name\": \"" + EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE + "\"," + + " \"version\": \"" + MobileCore.extensionVersion() + "+" + Edge.extensionVersion() + "\"" + + " }" + + " }" + + "}"; - assertEquals("app", resultPayload.get("xdm.implementationDetails.environment")); - assertEquals( - EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE, - resultPayload.get("xdm.implementationDetails.name") - ); - assertEquals( - MobileCore.extensionVersion() + "+" + Edge.extensionVersion(), - resultPayload.get("xdm.implementationDetails.version") + assertExactMatch( + expected, + getPayloadJson(resultRequests.get(0)), + new CollectionEqualCount(Subtree), + new ValueTypeMatch("xdm.identityMap.ECID[0].id", "events[0].xdm._id", "events[0].xdm.timestamp") ); + + TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); + assertTrue(testableNetworkRequest.getUrl().startsWith(EXEDGE_MEDIA_OR2_LOC_URL_STRING)); + assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); + assertNotNull(testableNetworkRequest.queryParam("requestId")); + } + + private JSONObject getPayloadJson(NetworkRequest networkRequest) { + if (networkRequest == null || networkRequest.getBody() == null) { + return null; + } + + String payload = new String(networkRequest.getBody()); + try { + return new JSONObject(payload); + } catch (Exception e) { + fail("Failed to create JSONObject from payload: " + e.getMessage()); + return null; + } } } From 18df84b3b1fa687130ec1eae64016e2c6996f7a6 Mon Sep 17 00:00:00 2001 From: timkimadobe <95260439+timkimadobe@users.noreply.github.com> Date: Thu, 30 May 2024 16:25:47 -0700 Subject: [PATCH 04/11] Apply lint formatting for EdgePathOverwriteTests.java --- .../mobile/EdgePathOverwriteTests.java | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java index e515448b..ed81de85 100644 --- a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java +++ b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java @@ -25,8 +25,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; import com.adobe.marketing.mobile.edge.identity.Identity; import com.adobe.marketing.mobile.services.HttpConnecting; -import com.adobe.marketing.mobile.services.ServiceProvider; import com.adobe.marketing.mobile.services.NetworkRequest; +import com.adobe.marketing.mobile.services.ServiceProvider; import com.adobe.marketing.mobile.services.TestableNetworkRequest; import com.adobe.marketing.mobile.util.CollectionEqualCount; import com.adobe.marketing.mobile.util.MockNetworkService; @@ -34,14 +34,11 @@ import com.adobe.marketing.mobile.util.TestConstants; import com.adobe.marketing.mobile.util.TestHelper; import com.adobe.marketing.mobile.util.ValueTypeMatch; - import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.concurrent.CountDownLatch; - import org.json.JSONObject; import org.junit.After; import org.junit.Before; @@ -158,7 +155,8 @@ public void testSendEvent_withXDMData_withOverwritePath_overwritesRequestPathAnd ); assertEquals(1, resultRequests.size()); - String expected = "{" + + String expected = + "{" + " \"events\": [" + " {" + " \"xdm\": {" + @@ -196,8 +194,14 @@ public void testSendEvent_withXDMData_withOverwritePath_overwritesRequestPathAnd " }," + " \"implementationDetails\": {" + " \"environment\": \"app\"," + - " \"name\": \"" + EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE + "\"," + - " \"version\": \"" + MobileCore.extensionVersion() + "+" + Edge.extensionVersion() + "\"" + + " \"name\": \"" + + EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE + + "\"," + + " \"version\": \"" + + MobileCore.extensionVersion() + + "+" + + Edge.extensionVersion() + + "\"" + " }" + " }" + "}"; @@ -279,7 +283,8 @@ public void testSendEvent_withXDMData_withOverwritePath_withLocationHintSet_over ); assertEquals(1, resultRequests.size()); - String expected = "{" + + String expected = + "{" + " \"events\": [" + " {" + " \"xdm\": {" + @@ -317,8 +322,14 @@ public void testSendEvent_withXDMData_withOverwritePath_withLocationHintSet_over " }," + " \"implementationDetails\": {" + " \"environment\": \"app\"," + - " \"name\": \"" + EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE + "\"," + - " \"version\": \"" + MobileCore.extensionVersion() + "+" + Edge.extensionVersion() + "\"" + + " \"name\": \"" + + EdgeJson.Event.ImplementationDetails.BASE_NAMESPACE + + "\"," + + " \"version\": \"" + + MobileCore.extensionVersion() + + "+" + + Edge.extensionVersion() + + "\"" + " }" + " }" + "}"; From a994baa15cb8258edcc0232a5e0e84b7d61a8867 Mon Sep 17 00:00:00 2001 From: timkimadobe <95260439+timkimadobe@users.noreply.github.com> Date: Fri, 7 Jun 2024 16:54:00 -0700 Subject: [PATCH 05/11] Update EdgeFunctionalTests.java to use TestableNetworkRequest Replace local getPayloadJson method and usages --- .../marketing/mobile/EdgeFunctionalTests.java | 176 ++++++++---------- 1 file changed, 81 insertions(+), 95 deletions(-) diff --git a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java index 242e55cc..3d35c5bf 100644 --- a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java +++ b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java @@ -27,13 +27,11 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.adobe.marketing.mobile.edge.identity.Identity; import com.adobe.marketing.mobile.services.HttpConnecting; import com.adobe.marketing.mobile.services.NamedCollection; -import com.adobe.marketing.mobile.services.NetworkRequest; import com.adobe.marketing.mobile.services.ServiceProvider; import com.adobe.marketing.mobile.services.TestableNetworkRequest; import com.adobe.marketing.mobile.util.AnyOrderMatch; @@ -406,17 +404,17 @@ public void testSendEvent_withXDMData_sendsExEdgeNetworkRequest() throws Excepti // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); - assertTrue(testableNetworkRequest.getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); - assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); - assertNotNull(testableNetworkRequest.queryParam("requestId")); + TestableNetworkRequest networkRequest = resultRequests.get(0); + assertTrue(networkRequest.getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); + assertEquals(CONFIG_ID, networkRequest.queryParam("configId")); + assertNotNull(networkRequest.queryParam("requestId")); String expected = "{" + @@ -471,7 +469,7 @@ public void testSendEvent_withXDMData_sendsExEdgeNetworkRequest() throws Excepti assertExactMatch( expected, - getPayloadJson(resultRequests.get(0)), + networkRequest.getBodyJson(), new CollectionEqualCount(Subtree), new ValueTypeMatch("xdm.identityMap.ECID[0].id", "events[0].xdm._id", "events[0].xdm.timestamp") ); @@ -523,17 +521,17 @@ public void testSendEvent_withXDMDataAndCustomData_sendsExEdgeNetworkRequest() t // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); - assertTrue(testableNetworkRequest.getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); - assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); - assertNotNull(testableNetworkRequest.queryParam("requestId")); + TestableNetworkRequest networkRequest = resultRequests.get(0); + assertTrue(networkRequest.getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); + assertEquals(CONFIG_ID, networkRequest.queryParam("configId")); + assertNotNull(networkRequest.queryParam("requestId")); String expected = "{" + @@ -590,7 +588,7 @@ public void testSendEvent_withXDMDataAndCustomData_sendsExEdgeNetworkRequest() t "}"; assertExactMatch( expected, - getPayloadJson(resultRequests.get(0)), + networkRequest.getBodyJson(), new CollectionEqualCount(Subtree), new ValueTypeMatch("xdm.identityMap.ECID[0].id", "events[0].xdm._id", "events[0].xdm.timestamp") ); @@ -616,17 +614,17 @@ public void testSendEvent_withXDMSchema_sendsExEdgeNetworkRequest() throws Excep // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); - assertTrue(testableNetworkRequest.getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); - assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); - assertNotNull(testableNetworkRequest.queryParam("requestId")); + TestableNetworkRequest networkRequest = resultRequests.get(0); + assertTrue(networkRequest.getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); + assertEquals(CONFIG_ID, networkRequest.queryParam("configId")); + assertNotNull(networkRequest.queryParam("requestId")); String expected = "{" + @@ -684,7 +682,7 @@ public void testSendEvent_withXDMSchema_sendsExEdgeNetworkRequest() throws Excep "}"; assertExactMatch( expected, - getPayloadJson(resultRequests.get(0)), + networkRequest.getBodyJson(), new CollectionEqualCount(Subtree), new ValueTypeMatch("xdm.identityMap.ECID[0].id", "events[0].xdm._id", "events[0].xdm.timestamp") ); @@ -698,7 +696,7 @@ public void testSendEvent_withEmptyXDMSchema_doesNotSendExEdgeNetworkRequest() t ExperienceEvent experienceEvent = new ExperienceEvent.Builder().setXdmSchema(new TestXDMSchema()).build(); Edge.sendEvent(experienceEvent, null); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST ); @@ -717,7 +715,7 @@ public void testSendEvent_withEmptyXDMSchemaAndEmptyData_doesNotSendExEdgeNetwor .build(); Edge.sendEvent(experienceEvent, null); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST ); @@ -736,7 +734,7 @@ public void testSendEvent_withEmptyXDMSchemaAndNullData_doesNotSendExEdgeNetwork .build(); Edge.sendEvent(experienceEvent, null); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST ); @@ -755,17 +753,17 @@ public void testSendEvent_withConfigurableEndpoint_withEmptyConfig_usesProductio // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( TestConstants.Defaults.EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); - assertTrue(testableNetworkRequest.getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_URL_STRING)); - assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); - assertNotNull(testableNetworkRequest.queryParam("requestId")); + TestableNetworkRequest networkRequest = resultRequests.get(0); + assertTrue(networkRequest.getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_URL_STRING)); + assertEquals(CONFIG_ID, networkRequest.queryParam("configId")); + assertNotNull(networkRequest.queryParam("requestId")); } @Test @@ -784,17 +782,17 @@ public void testSendEvent_withConfigurableEndpoint_withInvalidConfig_usesProduct // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( TestConstants.Defaults.EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); - assertTrue(testableNetworkRequest.getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_URL_STRING)); - assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); - assertNotNull(testableNetworkRequest.queryParam("requestId")); + TestableNetworkRequest networkRequest = resultRequests.get(0); + assertTrue(networkRequest.getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_URL_STRING)); + assertEquals(CONFIG_ID, networkRequest.queryParam("configId")); + assertNotNull(networkRequest.queryParam("requestId")); } @Test @@ -814,17 +812,17 @@ public void testSendEvent_withConfigurableEndpoint_withProdConfigEndpoint_usesPr // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( TestConstants.Defaults.EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); - assertTrue(testableNetworkRequest.getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_URL_STRING)); - assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); - assertNotNull(testableNetworkRequest.queryParam("requestId")); + TestableNetworkRequest networkRequest = resultRequests.get(0); + assertTrue(networkRequest.getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_URL_STRING)); + assertEquals(CONFIG_ID, networkRequest.queryParam("configId")); + assertNotNull(networkRequest.queryParam("requestId")); } @Test @@ -848,19 +846,19 @@ public void testSendEvent_withConfigurableEndpoint_withPreProdConfigEndpoint_use // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( TestConstants.Defaults.EXEDGE_INTERACT_PRE_PROD_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); + TestableNetworkRequest networkRequest = resultRequests.get(0); assertTrue( - testableNetworkRequest.getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_PRE_PROD_URL_STRING) + networkRequest.getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_PRE_PROD_URL_STRING) ); - assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); - assertNotNull(testableNetworkRequest.queryParam("requestId")); + assertEquals(CONFIG_ID, networkRequest.queryParam("configId")); + assertNotNull(networkRequest.queryParam("requestId")); } @Test @@ -884,17 +882,17 @@ public void testSendEvent_withConfigurableEndpoint_withIntConfigEndpoint_usesInt // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( TestConstants.Defaults.EXEDGE_INTERACT_INT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); - assertTrue(testableNetworkRequest.getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_INT_URL_STRING)); - assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); - assertNotNull(testableNetworkRequest.queryParam("requestId")); + TestableNetworkRequest networkRequest = resultRequests.get(0); + assertTrue(networkRequest.getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_INT_URL_STRING)); + assertEquals(CONFIG_ID, networkRequest.queryParam("configId")); + assertNotNull(networkRequest.queryParam("requestId")); } // -------------------------------------------------------------------------------------------- @@ -915,13 +913,13 @@ public void testSendEvent_twoConsecutiveCalls_appendsReceivedClientSideStore() Edge.sendEvent(XDM_EXPERIENCE_EVENT, null); // first network call, no stored data - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - assertTypeMatch("{}", getPayloadJson(resultRequests.get(0)), new ElementCount(12, Subtree)); + assertTypeMatch("{}", resultRequests.get(0).getBodyJson(), new ElementCount(12, Subtree)); assertExpectedEvents(true); resetTestExpectations(); @@ -935,10 +933,10 @@ public void testSendEvent_twoConsecutiveCalls_appendsReceivedClientSideStore() resultRequests = mockNetworkService.getNetworkRequestsWith(EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS); assertEquals(1, resultRequests.size()); - TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); - assertTrue(testableNetworkRequest.getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); - assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); - assertNotNull(testableNetworkRequest.queryParam("requestId")); + TestableNetworkRequest networkRequest = resultRequests.get(0); + assertTrue(networkRequest.getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); + assertEquals(CONFIG_ID, networkRequest.queryParam("configId")); + assertNotNull(networkRequest.queryParam("requestId")); String expected = "{" + @@ -961,7 +959,7 @@ public void testSendEvent_twoConsecutiveCalls_appendsReceivedClientSideStore() "}"; assertExactMatch( expected, - getPayloadJson(resultRequests.get(0)), + networkRequest.getBodyJson(), new CollectionEqualCount(Subtree, "meta.state.entries"), new AnyOrderMatch("meta.state.entries"), new ElementCount(18, Subtree) @@ -989,13 +987,13 @@ public void testSendEvent_twoConsecutiveCalls_resetBefore_appendsReceivedClientS Edge.sendEvent(XDM_EXPERIENCE_EVENT, null); // first network call, no stored data - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - assertTypeMatch("{}", getPayloadJson(resultRequests.get(0)), new ElementCount(12, Subtree)); + assertTypeMatch("{}", resultRequests.get(0).getBodyJson(), new ElementCount(12, Subtree)); assertExpectedEvents(true); resetTestExpectations(); @@ -1011,10 +1009,10 @@ public void testSendEvent_twoConsecutiveCalls_resetBefore_appendsReceivedClientS assertEquals(1, resultRequests.size()); // Validate network request query params - TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); - assertTrue(testableNetworkRequest.getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); - assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); - assertNotNull(testableNetworkRequest.queryParam("requestId")); + TestableNetworkRequest networkRequest = resultRequests.get(0); + assertTrue(networkRequest.getUrl().startsWith(EXEDGE_INTERACT_URL_STRING)); + assertEquals(CONFIG_ID, networkRequest.queryParam("configId")); + assertNotNull(networkRequest.queryParam("requestId")); String expected = "{" + @@ -1037,7 +1035,7 @@ public void testSendEvent_twoConsecutiveCalls_resetBefore_appendsReceivedClientS "}"; assertExactMatch( expected, - getPayloadJson(resultRequests.get(0)), + networkRequest.getBodyJson(), new CollectionEqualCount(Subtree, "meta.state.entries"), new AnyOrderMatch("meta.state.entries"), new ElementCount(18, Subtree) @@ -1059,13 +1057,13 @@ public void testSendEvent_twoConsecutiveCalls_resetBetween_clearsClientSideStore Edge.sendEvent(XDM_EXPERIENCE_EVENT, null); // first network call, no stored data - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - assertTypeMatch("{}", getPayloadJson(resultRequests.get(0)), new ElementCount(12, Subtree)); + assertTypeMatch("{}", resultRequests.get(0).getBodyJson(), new ElementCount(12, Subtree)); assertExpectedEvents(true); resetTestExpectations(); @@ -1085,7 +1083,7 @@ public void testSendEvent_twoConsecutiveCalls_resetBetween_clearsClientSideStore assertEquals(1, resultRequests.size()); assertExactMatch( "{}", - getPayloadJson(resultRequests.get(0)), + resultRequests.get(0).getBodyJson(), new ElementCount(12, Subtree), new KeyMustBeAbsent("meta.state.entries[0].key") ); @@ -1112,14 +1110,14 @@ public void testSendEvent_receivesResponseEventHandle_sendsResponseEvent_pairedW mockNetworkService.assertAllNetworkRequestExpectations(); assertExpectedEvents(true); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); - String requestId = testableNetworkRequest.queryParam("requestId"); + TestableNetworkRequest networkRequest = resultRequests.get(0); + String requestId = networkRequest.queryParam("requestId"); List requestEvents = getDispatchedEventsWith(EventType.EDGE, EventSource.REQUEST_CONTENT); assertEquals(1, requestEvents.size()); @@ -1154,8 +1152,9 @@ public void testSendEvent_receivesResponseEventHandle_sendsResponseEvent_pairedW "\"," + " \"type\": \"personalization:decisions\"" + "}"; - JSONAsserts.assertEquals(expected, responseEvents.get(0).getEventData()); - assertEquals(requestEventUuid, responseEvents.get(0).getParentID()); + Event event = responseEvents.get(0); + JSONAsserts.assertEquals(expected, event.getEventData()); + assertEquals(requestEventUuid, event.getParentID()); } @Test @@ -1185,14 +1184,14 @@ public void testSendEvent_receivesResponseEventWarning_sendsErrorResponseEvent_p mockNetworkService.assertAllNetworkRequestExpectations(); assertExpectedEvents(false); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); - TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); - String requestId = testableNetworkRequest.queryParam("requestId"); + TestableNetworkRequest networkRequest = resultRequests.get(0); + String requestId = networkRequest.queryParam("requestId"); List requestEvents = getDispatchedEventsWith(EventType.EDGE, EventSource.REQUEST_CONTENT); assertEquals(1, requestEvents.size()); @@ -1212,8 +1211,9 @@ public void testSendEvent_receivesResponseEventWarning_sendsErrorResponseEvent_p requestId + "\"" + "}"; - JSONAsserts.assertEquals(expected, errorResponseEvents.get(0).getEventData()); - assertEquals(requestEventUuid, errorResponseEvents.get(0).getParentID()); + Event errorEvent = errorResponseEvents.get(0); + JSONAsserts.assertEquals(expected, errorEvent.getEventData()); + assertEquals(requestEventUuid, errorEvent.getParentID()); } // -------------------------------------------------------------------------------------------- @@ -1237,7 +1237,7 @@ public void testSendEvent_edgeNetworkResponseContainsLocationHint_nextSendEventI Edge.sendEvent(XDM_EXPERIENCE_EVENT, null); // first network call, no location hint - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS @@ -1270,7 +1270,7 @@ public void testSendEvent_edgeNetworkResponseContainsLocationHint_sendEventDoesN Edge.sendEvent(XDM_EXPERIENCE_EVENT, null); // all network calls, no location hint - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS @@ -1374,7 +1374,7 @@ public void testSetLocationHint_withValueHint_edgeNetworkResponseContainsLocatio Edge.sendEvent(XDM_EXPERIENCE_EVENT, null); // send event // verify send event request includes set location hint - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_INTERACT_OR2_LOC_URL_STRING, POST, TIMEOUT_MILLIS @@ -1396,7 +1396,7 @@ public void testSetLocationHint_withHintWithSpaces_edgeNetworkResponseContainsLo Edge.sendEvent(XDM_EXPERIENCE_EVENT, null); // send event // verify send event request includes set location hint - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( "https://edge.adobedc.net/ee/incorrect location hint/v1/interact", POST, TIMEOUT_MILLIS @@ -1418,7 +1418,7 @@ public void testSetLocationHint_withHintWithSpecialCharacters_edgeNetworkRespons Edge.sendEvent(XDM_EXPERIENCE_EVENT, null); // send event // verify send event request includes set location hint - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( "https://edge.adobedc.net/ee/{\"example\":\"incorrect\"}/v1/interact", POST, TIMEOUT_MILLIS @@ -1440,7 +1440,7 @@ public void testSetLocationHint_withHintWithUnicodeCharacters_edgeNetworkRespons Edge.sendEvent(XDM_EXPERIENCE_EVENT, null); // send event // verify send event request includes set location hint - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( "https://edge.adobedc.net/ee/\u0048\u0065\u006C\u006C\u006F/v1/interact", POST, TIMEOUT_MILLIS @@ -1801,18 +1801,4 @@ private void updateConfiguration(final Map config) throws Interr assertTrue(latch.await(2, TimeUnit.SECONDS)); } - - private JSONObject getPayloadJson(NetworkRequest networkRequest) { - if (networkRequest == null || networkRequest.getBody() == null) { - return null; - } - - String payload = new String(networkRequest.getBody()); - try { - return new JSONObject(payload); - } catch (Exception e) { - fail("Failed to create JSONObject from payload: " + e.getMessage()); - return null; - } - } } From fcfd6927fe3b1496a5e06c5db506f014bf8d2bbe Mon Sep 17 00:00:00 2001 From: timkimadobe <95260439+timkimadobe@users.noreply.github.com> Date: Fri, 7 Jun 2024 16:54:48 -0700 Subject: [PATCH 06/11] Update EdgePathOverwriteTests.java to use TestableNetworkRequest Replace usage of local getPayloadJson --- .../mobile/EdgePathOverwriteTests.java | 38 ++++++------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java index ed81de85..6e29fd8f 100644 --- a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java +++ b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java @@ -148,7 +148,7 @@ public void testSendEvent_withXDMData_withOverwritePath_overwritesRequestPathAnd // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_MEDIA_URL_STRING, POST, TIMEOUT_MILLIS @@ -208,15 +208,15 @@ public void testSendEvent_withXDMData_withOverwritePath_overwritesRequestPathAnd assertExactMatch( expected, - getPayloadJson(resultRequests.get(0)), + resultRequests.get(0).getBodyJson(), new CollectionEqualCount(Subtree), new ValueTypeMatch("xdm.identityMap.ECID[0].id", "events[0].xdm._id", "events[0].xdm.timestamp") ); - TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); - assertTrue(testableNetworkRequest.getUrl().startsWith(EXEDGE_MEDIA_URL_STRING)); - assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); - assertNotNull(testableNetworkRequest.queryParam("requestId")); + TestableNetworkRequest networkRequest = resultRequests.get(0); + assertTrue(networkRequest.getUrl().startsWith(EXEDGE_MEDIA_URL_STRING)); + assertEquals(CONFIG_ID, networkRequest.queryParam("configId")); + assertNotNull(networkRequest.queryParam("requestId")); } @Test @@ -276,7 +276,7 @@ public void testSendEvent_withXDMData_withOverwritePath_withLocationHintSet_over // verify mockNetworkService.assertAllNetworkRequestExpectations(); - List resultRequests = mockNetworkService.getNetworkRequestsWith( + List resultRequests = mockNetworkService.getNetworkRequestsWith( EXEDGE_MEDIA_OR2_LOC_URL_STRING, POST, TIMEOUT_MILLIS @@ -336,28 +336,14 @@ public void testSendEvent_withXDMData_withOverwritePath_withLocationHintSet_over assertExactMatch( expected, - getPayloadJson(resultRequests.get(0)), + resultRequests.get(0).getBodyJson(), new CollectionEqualCount(Subtree), new ValueTypeMatch("xdm.identityMap.ECID[0].id", "events[0].xdm._id", "events[0].xdm.timestamp") ); - TestableNetworkRequest testableNetworkRequest = new TestableNetworkRequest(resultRequests.get(0)); - assertTrue(testableNetworkRequest.getUrl().startsWith(EXEDGE_MEDIA_OR2_LOC_URL_STRING)); - assertEquals(CONFIG_ID, testableNetworkRequest.queryParam("configId")); - assertNotNull(testableNetworkRequest.queryParam("requestId")); - } - - private JSONObject getPayloadJson(NetworkRequest networkRequest) { - if (networkRequest == null || networkRequest.getBody() == null) { - return null; - } - - String payload = new String(networkRequest.getBody()); - try { - return new JSONObject(payload); - } catch (Exception e) { - fail("Failed to create JSONObject from payload: " + e.getMessage()); - return null; - } + TestableNetworkRequest networkRequest = resultRequests.get(0); + assertTrue(networkRequest.getUrl().startsWith(EXEDGE_MEDIA_OR2_LOC_URL_STRING)); + assertEquals(CONFIG_ID, networkRequest.queryParam("configId")); + assertNotNull(networkRequest.queryParam("requestId")); } } From 35af6407812ec1116a4594524f4597970646edfb Mon Sep 17 00:00:00 2001 From: timkimadobe <95260439+timkimadobe@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:07:51 -0700 Subject: [PATCH 07/11] Update testSendEvent_withXDMDataAndNullData_sendsCorrectRequestEvent to update testValue for clarity --- .../java/com/adobe/marketing/mobile/EdgeFunctionalTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java index 3d35c5bf..f07082f9 100644 --- a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java +++ b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java @@ -259,7 +259,7 @@ public void testSendEvent_withXDMDataAndNullData_sendsCorrectRequestEvent() thro .setXdmSchema( new HashMap() { { - put("testString", "xdm"); + put("testString", "testValue"); } } ) @@ -272,7 +272,7 @@ public void testSendEvent_withXDMDataAndNullData_sendsCorrectRequestEvent() thro List resultEvents = getDispatchedEventsWith(EventType.EDGE, EventSource.REQUEST_CONTENT); assertEquals(1, resultEvents.size()); - String expected = "{" + " \"xdm\": {" + " \"testString\": \"xdm\"" + " }" + "}"; + String expected = "{\"xdm\": {\"testString\": \"testValue\"}}"; JSONAsserts.assertEquals(expected, resultEvents.get(0).getEventData()); } From 5e09f9e8b4c19b1dcf398ec9c157b3c7b0c82b8b Mon Sep 17 00:00:00 2001 From: timkimadobe <95260439+timkimadobe@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:12:07 -0700 Subject: [PATCH 08/11] Apply lint formatting for EdgeFunctionalTests.java and EdgePathOverwriteTests.java --- .../java/com/adobe/marketing/mobile/EdgeFunctionalTests.java | 5 +---- .../com/adobe/marketing/mobile/EdgePathOverwriteTests.java | 3 --- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java index f07082f9..ff842236 100644 --- a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java +++ b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java @@ -55,7 +55,6 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import org.json.JSONException; -import org.json.JSONObject; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -854,9 +853,7 @@ public void testSendEvent_withConfigurableEndpoint_withPreProdConfigEndpoint_use assertEquals(1, resultRequests.size()); TestableNetworkRequest networkRequest = resultRequests.get(0); - assertTrue( - networkRequest.getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_PRE_PROD_URL_STRING) - ); + assertTrue(networkRequest.getUrl().startsWith(TestConstants.Defaults.EXEDGE_INTERACT_PRE_PROD_URL_STRING)); assertEquals(CONFIG_ID, networkRequest.queryParam("configId")); assertNotNull(networkRequest.queryParam("requestId")); } diff --git a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java index 6e29fd8f..b7a16394 100644 --- a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java +++ b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java @@ -20,12 +20,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.adobe.marketing.mobile.edge.identity.Identity; import com.adobe.marketing.mobile.services.HttpConnecting; -import com.adobe.marketing.mobile.services.NetworkRequest; import com.adobe.marketing.mobile.services.ServiceProvider; import com.adobe.marketing.mobile.services.TestableNetworkRequest; import com.adobe.marketing.mobile.util.CollectionEqualCount; @@ -39,7 +37,6 @@ import java.util.HashMap; import java.util.List; import java.util.concurrent.CountDownLatch; -import org.json.JSONObject; import org.junit.After; import org.junit.Before; import org.junit.Rule; From 56a388dc36bcd72082562457cd331a2d9d69c2e7 Mon Sep 17 00:00:00 2001 From: timkimadobe <95260439+timkimadobe@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:47:53 -0700 Subject: [PATCH 09/11] Update to use stringValue for test case strings in event payloads --- .../marketing/mobile/EdgeFunctionalTests.java | 16 ++++++++-------- .../marketing/mobile/EdgePathOverwriteTests.java | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java index ff842236..22f835e1 100644 --- a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java +++ b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java @@ -130,7 +130,7 @@ public void testSendEvent_withXDMData_sendsCorrectRequestEvent() throws Interrup .setXdmSchema( new HashMap() { { - put("testString", "xdm"); + put("testString", "stringValue"); put("testInt", 10); put("testBool", false); put("testDouble", 12.89); @@ -165,7 +165,7 @@ public void testSendEvent_withXDMData_sendsCorrectRequestEvent() throws Interrup String expected = "{" + " \"xdm\": {" + - " \"testString\": \"xdm\"," + + " \"testString\": \"stringValue\"," + " \"testInt\": 10," + " \"testBool\": false," + " \"testDouble\": 12.89," + @@ -189,7 +189,7 @@ public void testSendEvent_withXDMDataAndCustomData_sendsCorrectRequestEvent() th .setXdmSchema( new HashMap() { { - put("testString", "xdm"); + put("testString", "stringValue"); } } ) @@ -231,7 +231,7 @@ public void testSendEvent_withXDMDataAndCustomData_sendsCorrectRequestEvent() th String expected = "{" + " \"xdm\": {" + - " \"testString\": \"xdm\"" + + " \"testString\": \"stringValue\"" + " }," + " \"data\": {" + " \"testString\": \"stringValue\"," + @@ -258,7 +258,7 @@ public void testSendEvent_withXDMDataAndNullData_sendsCorrectRequestEvent() thro .setXdmSchema( new HashMap() { { - put("testString", "testValue"); + put("testString", "stringValue"); } } ) @@ -271,7 +271,7 @@ public void testSendEvent_withXDMDataAndNullData_sendsCorrectRequestEvent() thro List resultEvents = getDispatchedEventsWith(EventType.EDGE, EventSource.REQUEST_CONTENT); assertEquals(1, resultEvents.size()); - String expected = "{\"xdm\": {\"testString\": \"testValue\"}}"; + String expected = "{\"xdm\": {\"testString\": \"stringValue\"}}"; JSONAsserts.assertEquals(expected, resultEvents.get(0).getEventData()); } @@ -374,7 +374,7 @@ public void testSendEvent_withXDMData_sendsExEdgeNetworkRequest() throws Excepti .setXdmSchema( new HashMap() { { - put("testString", "xdmValue"); + put("testString", "stringValue"); put("testInt", 10); put("testBool", false); put("testDouble", 12.89); @@ -428,7 +428,7 @@ public void testSendEvent_withXDMData_sendsExEdgeNetworkRequest() throws Excepti " \"testMap\": {" + " \"key\": \"value\"" + " }," + - " \"testString\": \"xdmValue\"," + + " \"testString\": \"stringValue\"," + " \"timestamp\": \"STRING_TYPE\"" + " }" + " }" + diff --git a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java index b7a16394..74086c7c 100644 --- a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java +++ b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgePathOverwriteTests.java @@ -104,7 +104,7 @@ public void testSendEvent_withXDMData_withOverwritePath_overwritesRequestPathAnd "xdm", new HashMap() { { - put("testString", "xdmValue"); + put("testString", "stringValue"); put("testInt", 10); put("testBool", false); put("testDouble", 12.89); @@ -165,7 +165,7 @@ public void testSendEvent_withXDMData_withOverwritePath_overwritesRequestPathAnd " \"testMap\": {" + " \"key\": \"value\"" + " }," + - " \"testString\": \"xdmValue\"," + + " \"testString\": \"stringValue\"," + " \"timestamp\": \"STRING_TYPE\"" + " }" + " }" + @@ -232,7 +232,7 @@ public void testSendEvent_withXDMData_withOverwritePath_withLocationHintSet_over "xdm", new HashMap() { { - put("testString", "xdmValue"); + put("testString", "stringValue"); put("testInt", 10); put("testBool", false); put("testDouble", 12.89); @@ -293,7 +293,7 @@ public void testSendEvent_withXDMData_withOverwritePath_withLocationHintSet_over " \"testMap\": {" + " \"key\": \"value\"" + " }," + - " \"testString\": \"xdmValue\"," + + " \"testString\": \"stringValue\"," + " \"timestamp\": \"STRING_TYPE\"" + " }" + " }" + From 8b75ecd860212faee92ff6f5c07cf86c292fa9e8 Mon Sep 17 00:00:00 2001 From: timkimadobe <95260439+timkimadobe@users.noreply.github.com> Date: Tue, 11 Jun 2024 15:30:11 -0700 Subject: [PATCH 10/11] Update EdgeFunctionalTests and TestXDMSchema to use "test" prefixed property names Add code comments for ElementCount cases to make assertion logic clearer --- .../marketing/mobile/EdgeFunctionalTests.java | 32 +++++++++++-------- .../marketing/mobile/util/TestXDMSchema.java | 30 ++++++++--------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java index 22f835e1..46e1d452 100644 --- a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java +++ b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java @@ -602,11 +602,11 @@ public void testSendEvent_withXDMSchema_sendsExEdgeNetworkRequest() throws Excep TestXDMSchema.TestXDMObject xdmObject = new TestXDMSchema.TestXDMObject(); xdmObject.innerKey = "testInnerObject"; TestXDMSchema xdmSchema = new TestXDMSchema(); - xdmSchema.boolObject = true; - xdmSchema.intObject = 100; - xdmSchema.stringObject = "testWithXdmSchema"; - xdmSchema.doubleObject = 3.42; - xdmSchema.xdmObject = xdmObject; + xdmSchema.testBool = true; + xdmSchema.testInt = 100; + xdmSchema.testString = "testWithXdmSchema"; + xdmSchema.testDouble = 3.42; + xdmSchema.testXDMObject = xdmObject; ExperienceEvent experienceEvent = new ExperienceEvent.Builder().setXdmSchema(xdmSchema).build(); Edge.sendEvent(experienceEvent, null); @@ -636,12 +636,12 @@ public void testSendEvent_withXDMSchema_sendsExEdgeNetworkRequest() throws Excep " }," + " \"xdm\": {" + " \"_id\": \"STRING_TYPE\"," + - " \"boolObject\": true," + - " \"doubleObject\": 3.42," + - " \"intObject\": 100," + - " \"stringObject\": \"testWithXdmSchema\"," + + " \"testBool\": true," + + " \"testDouble\": 3.42," + + " \"testInt\": 100," + + " \"testString\": \"testWithXdmSchema\"," + " \"timestamp\": \"STRING_TYPE\"," + - " \"xdmObject\": {" + + " \"testXDMObject\": {" + " \"innerKey\": \"testInnerObject\"" + " }" + " }" + @@ -916,6 +916,7 @@ public void testSendEvent_twoConsecutiveCalls_appendsReceivedClientSideStore() TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); + // Asserting body has 12 total key value elements assertTypeMatch("{}", resultRequests.get(0).getBodyJson(), new ElementCount(12, Subtree)); assertExpectedEvents(true); @@ -959,7 +960,7 @@ public void testSendEvent_twoConsecutiveCalls_appendsReceivedClientSideStore() networkRequest.getBodyJson(), new CollectionEqualCount(Subtree, "meta.state.entries"), new AnyOrderMatch("meta.state.entries"), - new ElementCount(18, Subtree) + new ElementCount(18, Subtree) // Asserting body has 18 total key value elements ); assertExpectedEvents(true); @@ -990,6 +991,7 @@ public void testSendEvent_twoConsecutiveCalls_resetBefore_appendsReceivedClientS TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); + // Asserting body has 12 total key value elements assertTypeMatch("{}", resultRequests.get(0).getBodyJson(), new ElementCount(12, Subtree)); assertExpectedEvents(true); @@ -1035,7 +1037,7 @@ public void testSendEvent_twoConsecutiveCalls_resetBefore_appendsReceivedClientS networkRequest.getBodyJson(), new CollectionEqualCount(Subtree, "meta.state.entries"), new AnyOrderMatch("meta.state.entries"), - new ElementCount(18, Subtree) + new ElementCount(18, Subtree) // Asserting body has 18 total key value elements ); assertExpectedEvents(true); @@ -1060,6 +1062,7 @@ public void testSendEvent_twoConsecutiveCalls_resetBetween_clearsClientSideStore TIMEOUT_MILLIS ); assertEquals(1, resultRequests.size()); + // Asserting body has 12 total key value elements assertTypeMatch("{}", resultRequests.get(0).getBodyJson(), new ElementCount(12, Subtree)); assertExpectedEvents(true); @@ -1081,7 +1084,7 @@ public void testSendEvent_twoConsecutiveCalls_resetBetween_clearsClientSideStore assertExactMatch( "{}", resultRequests.get(0).getBodyJson(), - new ElementCount(12, Subtree), + new ElementCount(12, Subtree), // Asserting body has 12 total key value elements new KeyMustBeAbsent("meta.state.entries[0].key") ); } @@ -1694,6 +1697,7 @@ public void testSendEvent_multiStatusResponse_dispatchesEvents() throws Interrup " \"title\": \"The 'com.adobe.experience.platform.ode' service is temporarily unable to serve this request. Please try again later.\"," + " \"type\": \"https://ns.adobe.com/aep/errors/EXEG-0201-504\"" + "}"; + // Asserting body has 5 total key value elements assertExactMatch(expectedEventData1, resultEvents.get(0).getEventData(), new ElementCount(5, Subtree)); assertEquals(requestEvents.get(0).getUniqueIdentifier(), resultEvents.get(0).getParentID()); @@ -1712,6 +1716,7 @@ public void testSendEvent_multiStatusResponse_dispatchesEvents() throws Interrup " \"title\": \"A warning occurred while calling the 'com.adobe.audiencemanager' service for this request.\"," + " \"type\": \"https://ns.adobe.com/aep/errors/EXEG-0204-200\"" + "}"; + // Asserting body has 7 total key value elements assertExactMatch(expectedEventData2, resultEvents.get(1).getEventData(), new ElementCount(7, Subtree)); assertEquals(requestEvents.get(0).getUniqueIdentifier(), resultEvents.get(1).getParentID()); } @@ -1779,6 +1784,7 @@ public void testSendEvent_fatalError() throws InterruptedException { " \"title\": \"Unprocessable Entity\"," + " \"type\": \"https://ns.adobe.com/aep/errors/EXEG-0104-422\"" + "}"; + // Asserting body has 11 total key value elements assertExactMatch(expected, resultEvents.get(0).getEventData(), new ElementCount(11, Subtree)); assertEquals(requestEvents.get(0).getUniqueIdentifier(), resultEvents.get(0).getParentID()); } diff --git a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/util/TestXDMSchema.java b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/util/TestXDMSchema.java index f819b5d5..8ed05d09 100644 --- a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/util/TestXDMSchema.java +++ b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/util/TestXDMSchema.java @@ -19,11 +19,11 @@ public class TestXDMSchema implements Schema { - public String stringObject; - public Integer intObject; - public Boolean boolObject; - public Double doubleObject; - public TestXDMObject xdmObject; + public String testString; + public Integer testInt; + public Boolean testBool; + public Double testDouble; + public TestXDMObject testXDMObject; public Date timestamp; @Override @@ -45,24 +45,24 @@ public String getDatasetIdentifier() { public Map serializeToXdm() { Map map = new HashMap<>(); - if (this.stringObject != null) { - map.put("stringObject", this.stringObject); + if (this.testString != null) { + map.put("testString", this.testString); } - if (this.intObject != null) { - map.put("intObject", this.intObject); + if (this.testInt != null) { + map.put("testInt", this.testInt); } - if (this.boolObject != null) { - map.put("boolObject", this.boolObject); + if (this.testBool != null) { + map.put("testBool", this.testBool); } - if (this.doubleObject != null) { - map.put("doubleObject", this.doubleObject); + if (this.testDouble != null) { + map.put("testDouble", this.testDouble); } - if (this.xdmObject != null) { - map.put("xdmObject", this.xdmObject.serializeToXdm()); + if (this.testXDMObject != null) { + map.put("testXDMObject", this.testXDMObject.serializeToXdm()); } if (this.timestamp != null) { From b5800b6c0c57d28ef57154b61e25b8b0da043ec0 Mon Sep 17 00:00:00 2001 From: timkimadobe <95260439+timkimadobe@users.noreply.github.com> Date: Tue, 11 Jun 2024 15:37:51 -0700 Subject: [PATCH 11/11] Remove test case comments for JSON assertions with actual expected payloads --- .../adobe/marketing/mobile/EdgeFunctionalTests.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java index 46e1d452..668d4b21 100644 --- a/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java +++ b/code/edge/src/androidTest/java/com/adobe/marketing/mobile/EdgeFunctionalTests.java @@ -960,7 +960,7 @@ public void testSendEvent_twoConsecutiveCalls_appendsReceivedClientSideStore() networkRequest.getBodyJson(), new CollectionEqualCount(Subtree, "meta.state.entries"), new AnyOrderMatch("meta.state.entries"), - new ElementCount(18, Subtree) // Asserting body has 18 total key value elements + new ElementCount(18, Subtree) ); assertExpectedEvents(true); @@ -1037,7 +1037,7 @@ public void testSendEvent_twoConsecutiveCalls_resetBefore_appendsReceivedClientS networkRequest.getBodyJson(), new CollectionEqualCount(Subtree, "meta.state.entries"), new AnyOrderMatch("meta.state.entries"), - new ElementCount(18, Subtree) // Asserting body has 18 total key value elements + new ElementCount(18, Subtree) ); assertExpectedEvents(true); @@ -1081,10 +1081,12 @@ public void testSendEvent_twoConsecutiveCalls_resetBetween_clearsClientSideStore resultRequests = mockNetworkService.getNetworkRequestsWith(EXEDGE_INTERACT_URL_STRING, POST, TIMEOUT_MILLIS); assertEquals(1, resultRequests.size()); + // Asserting body has 12 total key value elements and that "key" is not present in the first + // element of "entries" assertExactMatch( "{}", resultRequests.get(0).getBodyJson(), - new ElementCount(12, Subtree), // Asserting body has 12 total key value elements + new ElementCount(12, Subtree), new KeyMustBeAbsent("meta.state.entries[0].key") ); } @@ -1697,7 +1699,6 @@ public void testSendEvent_multiStatusResponse_dispatchesEvents() throws Interrup " \"title\": \"The 'com.adobe.experience.platform.ode' service is temporarily unable to serve this request. Please try again later.\"," + " \"type\": \"https://ns.adobe.com/aep/errors/EXEG-0201-504\"" + "}"; - // Asserting body has 5 total key value elements assertExactMatch(expectedEventData1, resultEvents.get(0).getEventData(), new ElementCount(5, Subtree)); assertEquals(requestEvents.get(0).getUniqueIdentifier(), resultEvents.get(0).getParentID()); @@ -1716,7 +1717,6 @@ public void testSendEvent_multiStatusResponse_dispatchesEvents() throws Interrup " \"title\": \"A warning occurred while calling the 'com.adobe.audiencemanager' service for this request.\"," + " \"type\": \"https://ns.adobe.com/aep/errors/EXEG-0204-200\"" + "}"; - // Asserting body has 7 total key value elements assertExactMatch(expectedEventData2, resultEvents.get(1).getEventData(), new ElementCount(7, Subtree)); assertEquals(requestEvents.get(0).getUniqueIdentifier(), resultEvents.get(1).getParentID()); } @@ -1784,7 +1784,6 @@ public void testSendEvent_fatalError() throws InterruptedException { " \"title\": \"Unprocessable Entity\"," + " \"type\": \"https://ns.adobe.com/aep/errors/EXEG-0104-422\"" + "}"; - // Asserting body has 11 total key value elements assertExactMatch(expected, resultEvents.get(0).getEventData(), new ElementCount(11, Subtree)); assertEquals(requestEvents.get(0).getUniqueIdentifier(), resultEvents.get(0).getParentID()); }