Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev to staging (v2.0.3) #35

Merged
merged 2 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Documentation/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ TargetRequest request2 = new TargetRequest("mboxName2", parameters2, "defaultCon
// and click metric analytics payload, if available
if (data != null && !data.isEmpty()) {

Map<String, String> responseTokens = data.containsKey("responseTokens") ?
(Map<String, String>) data.get("responseTokens") :
Map<String, Object> responseTokens = data.containsKey("responseTokens") ?
(Map<String, Object>) data.get("responseTokens") :
null;

Map<String, String> analyticsPayload = data.containsKey("analytics.payload") ?
Expand Down
2 changes: 1 addition & 1 deletion code/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ android.useAndroidX=true
moduleProjectName=target
moduleName=target
moduleAARName=target-phone-release.aar
moduleVersion=2.0.2
moduleVersion=2.0.3

mavenRepoName=AdobeMobileTargetSdk
mavenRepoDescription=Adobe Experience Platform Target extension for the Adobe Experience Platform Mobile SDK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class TargetTestConstants {

static final String EXTENSION_VERSION = "2.0.2";
static final String EXTENSION_VERSION = "2.0.3";

public final static class EventType {
public static final String TARGET = "com.adobe.eventType.target";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ List<TargetRequest> processCachedTargetRequest(final List<TargetRequest> batchRe

final String content = targetResponseParser.extractMboxContent(cachedMboxJson);
final Map<String, String> a4tParams = targetResponseParser.getAnalyticsForTargetPayload(cachedMboxJson);
final Map<String, String> responseTokens = targetResponseParser.getResponseTokens(cachedMboxJson);
final Map<String, Object> responseTokens = targetResponseParser.getResponseTokens(cachedMboxJson);
final Map<String, String> clickMetricA4TParams = targetResponseParser.extractClickMetricAnalyticsPayload(
cachedMboxJson);

Expand Down Expand Up @@ -1107,7 +1107,7 @@ private void processTargetRequestResponse(final List<TargetRequest> batchRequest

final JSONObject mboxJson = batchedMboxes.get(targetRequest.getMboxName());
final String content = targetResponseParser.extractMboxContent(mboxJson);
final Map<String, String> responseTokens = targetResponseParser.getResponseTokens(mboxJson);
final Map<String, Object> responseTokens = targetResponseParser.getResponseTokens(mboxJson);
final Map<String, String> clickMetricA4TParams = targetResponseParser.extractClickMetricAnalyticsPayload(mboxJson);

final Map<String, String> a4tParams = targetResponseParser.getAnalyticsForTargetPayload(mboxJson);
Expand Down Expand Up @@ -1325,7 +1325,7 @@ private void dispatchMboxPrefetchResult(final String error, final Event event) {
void dispatchMboxContent(final String content,
final Map<String, String> a4tParams,
final Map<String, String> clickMetricA4TParams,
final Map<String, String> responseTokens,
final Map<String, Object> responseTokens,
final String pairId,
final Event event) {
final Map<String, Object> data = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ Map<String, String> getAnalyticsForTargetPayload(final JSONObject json) {
* Parse the Mbox JSON object to read Response Tokens from the Options. The data will be read from the first option in the options list.
*
* @param mboxJson Mbox {@link JSONObject}
* @return Response Tokens from options payload as {@code Map<String, String>} OR null if Response Tokens are not activated on Target.
* @return Response tokens from options payload as {@code Map<String, Object>}, or null if response tokens are not activated on Target.
*/
Map<String, String> getResponseTokens(final JSONObject mboxJson) {
Map<String, Object> getResponseTokens(final JSONObject mboxJson) {
if (mboxJson == null) {
return null;
}
Expand All @@ -319,7 +319,14 @@ Map<String, String> getResponseTokens(final JSONObject mboxJson) {
return null;
}

return TargetUtils.toStringMap(responseTokens);
Map<String, Object> responseTokensMap = null;
try {
responseTokensMap = JSONUtils.toMap(responseTokens);
} catch (final JSONException e) {
Log.debug(TargetConstants.LOG_TAG, CLASS_NAME,
"Exception (%s) is thrown when parsing response tokens to create an object Map.", e);
}
return responseTokensMap;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

static final String LOG_TAG = "Target";
private static final String CLASS_NAME = "Target";
static final String EXTENSION_VERSION = "2.0.2";
static final String EXTENSION_VERSION = "2.0.3";

static final class EventName {
static final String PREFETCH_REQUEST = "TargetPrefetchRequest";
Expand Down Expand Up @@ -885,7 +885,8 @@
mboxPayload.put(EventDataKeys.ANALYTICS_PAYLOAD, a4tParams);
}

final Map<String, String> responseTokens = DataReader.optStringMap(data,
final Map<String, Object> responseTokens = DataReader.optTypedMap(Object.class,

Check warning on line 888 in code/target/src/phone/java/com/adobe/marketing/mobile/Target.java

View check run for this annotation

Codecov / codecov/patch

code/target/src/phone/java/com/adobe/marketing/mobile/Target.java#L888

Added line #L888 was not covered by tests
data,
EventDataKeys.RESPONSE_TOKENS,
null);
if (responseTokens != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -70,46 +72,46 @@
public class TargetExtensionTests {

// Mock Constants
private static String MOCKED_CLIENT_CODE = "clientCode";
private static String MOCKED_TARGET_SERVER = "targetServer";
private static String MOCK_EDGE_HOST = "mboxedge35.tt.omtrdc.net";
private static String MOCK_THIRD_PARTY_ID = "thirdPartyId";
private static String MOCK_THIRD_PARTY_ID_1 = "thirdPartyID_1";
private static String MOCK_TNT_ID = "66E5C681-4F70-41A2-86AE-F1E151443B10.35_0";
private static String MOCK_TNT_ID_1 = "66E5C681-4F70-41A2-86AE-F1E151443B10.32_0";
private static String MOCK_TNT_ID_2 = "4DBCC39D-4ACA-47D4-A7D2-A85C1C0CC382.32_0";
private static String MOCK_TNT_ID_INVALID = "66E5C681-4F70-41A2-86AE-F1E151443B10.a1a_0";
private static String MOCK_SESSION_ID = "mockSessionID";
private static Integer MOCK_NETWORK_TIMEOUT = 5;

private static HashMap<String, Object> targetParameters = new HashMap() {
private static final String MOCKED_CLIENT_CODE = "clientCode";
private static final String MOCKED_TARGET_SERVER = "targetServer";
private static final String MOCK_EDGE_HOST = "mboxedge35.tt.omtrdc.net";
private static final String MOCK_THIRD_PARTY_ID = "thirdPartyId";
private static final String MOCK_THIRD_PARTY_ID_1 = "thirdPartyID_1";
private static final String MOCK_TNT_ID = "66E5C681-4F70-41A2-86AE-F1E151443B10.35_0";
private static final String MOCK_TNT_ID_1 = "66E5C681-4F70-41A2-86AE-F1E151443B10.32_0";
private static final String MOCK_TNT_ID_2 = "4DBCC39D-4ACA-47D4-A7D2-A85C1C0CC382.32_0";
private static final String MOCK_TNT_ID_INVALID = "66E5C681-4F70-41A2-86AE-F1E151443B10.a1a_0";
private static final String MOCK_SESSION_ID = "mockSessionID";
private static final Integer MOCK_NETWORK_TIMEOUT = 5;

private static final HashMap<String, Object> targetParameters = new HashMap() {
{
put("paramKey", "paramValue");
}
};

private static HashMap<String, Object> targetSharedState = new HashMap() {
private static final HashMap<String, Object> targetSharedState = new HashMap() {
{
put("tntid", MOCK_TNT_ID);
put("sessionid", MOCK_SESSION_ID);
}
};

private static HashMap<String, String> lifecycleSharedState = new HashMap() {
private static final HashMap<String, String> lifecycleSharedState = new HashMap() {
{
put("lifecycleKey", "lifecycleValue");
}
};

private static HashMap<String, Object> identitySharedState = new HashMap() {
private static final HashMap<String, Object> identitySharedState = new HashMap() {
{
put("mid", "samplemid");
put("blob", "sampleBlob");
put("locationhint", "sampleLocationHint");
}
};

private static HashMap<String, Object> eventHubSharedState = new HashMap() {
private static final HashMap<String, Object> eventHubSharedState = new HashMap() {
{
put("version", "x.y.z");
put("wrapper", new HashMap<String, Object>() {
Expand All @@ -121,16 +123,28 @@ public class TargetExtensionTests {
}
};

private static Map<String, String> responseTokens = new HashMap() {{
private static final Map<String, Object> responseTokens = new HashMap() {{
put("responseTokens.Key", "responseTokens.Value");
put("profile.categoryAffinities", new ArrayList<String>(){
{
add("books");
}
});
put("someKey", new ArrayList<Object>(){
{
add("someValue");
add(true);
add(42);
}
});
}};

private static Map<String, String> clickMetricA4TParams = new HashMap() {{
private static final Map<String, String> clickMetricA4TParams = new HashMap() {{
put("pe", "tnt");
put("tnta", "1234|1234");
}};

private static Map<String, String> a4tParams = new HashMap() {{
private static final Map<String, String> a4tParams = new HashMap() {{
put("pe", "tnt");
put("tnta", "1234|1234");
}};
Expand Down Expand Up @@ -233,7 +247,7 @@ public void test_getFriendlyName() {
public void test_getVersion() {
// test
final String extensionVersion = extension.getVersion();
assertEquals("getVersion should return the correct extension version.", "2.0.2", extensionVersion);
assertEquals("getVersion should return the correct extension version.", "2.0.3", extensionVersion);
}

//**********************************************************************************************
Expand Down Expand Up @@ -618,7 +632,15 @@ public void testLoadRequests_whenValidResponse() throws Exception {

// verify the dispatched mbox content event
assertEquals("mbox0content", extractMboxContentFromEvent(mboxContentEvent));
assertEquals(responseTokens, extractResponseToken(mboxContentEvent));
final Map<String, Object> responseTokens = extractResponseToken(mboxContentEvent);
assertEquals(3, responseTokens.size());
assertEquals("responseTokens.Value", responseTokens.get("responseTokens.Key"));
assertEquals(new ArrayList<String>(Collections.singletonList("books")), responseTokens.get("profile.categoryAffinities"));
final List<Object> someList = (List<Object>)responseTokens.get("someKey");
assertEquals(3, someList.size());
assertEquals("someValue", someList.get(0));
assertTrue((Boolean)someList.get(1));
assertEquals(42, (int)someList.get(2));
assertEquals(a4tParams, extractAnalyticsPayload(mboxContentEvent));
assertEquals(clickMetricA4TParams, extractClickMetric(mboxContentEvent));
}
Expand Down Expand Up @@ -1962,7 +1984,6 @@ public void testHandleConfigurationResponseContentEvent_whenPrivacyOptedOut() {
// verify
verify(targetState, times(2)).updateEdgeHost(null);
verify(targetState).resetSession();
;
verify(targetState).updateTntId(null);
verify(targetState).updateThirdPartyId(null);
verify(mockExtensionApi).createSharedState(eq(targetSharedState), eq(event));
Expand Down Expand Up @@ -2135,12 +2156,11 @@ Map<String, Object> getTargetRawRequestForNotifications(int count) {

for (int i = 0; i < count; i++) {
final String notificationId = String.valueOf(i);
;
final String mboxName = "mbox" + i;
final Map<String, Object> notification = new HashMap<String, Object>() {
{
put("id", notificationId);
put("timestamp", (long) (System.currentTimeMillis()));
put("timestamp", System.currentTimeMillis());
put("type", "click");
put("mbox", new HashMap<String, Object>() {
{
Expand Down Expand Up @@ -2424,7 +2444,7 @@ private String extractMboxContentFromEvent(final Event event) {
"");
}

private Map<String, String> extractResponseToken(final Event event) {
private Map<String, Object> extractResponseToken(final Event event) {
Map<String, Map> data = DataReader.optTypedMap(Map.class, event.getEventData(), EventDataKeys.TARGET_DATA_PAYLOAD, null);
return data.get(EventDataKeys.RESPONSE_TOKENS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
import org.mockito.MockedStatic;
import org.mockito.Mockito;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.*;

import com.adobe.marketing.mobile.services.HttpConnecting;
import com.adobe.marketing.mobile.util.JSONUtils;
import com.adobe.marketing.mobile.util.StreamUtils;

public class TargetResponseParserTest {
Expand Down Expand Up @@ -758,6 +761,7 @@ public void testExtractResponseTokens_Will_Return_Valid_Map_When_Response_Tokens
" \"responseTokens\":{\n" +
" \"geo.connectionSpeed\":\"broadband\",\n" +
" \"geo.state\":\"california\",\n" +
" \"profile.categoryAffinities\":[\"shoes\"],\n" +
" },\n" +
" \"sourceType\":\"target\"\n" +
" }\n" +
Expand All @@ -773,12 +777,13 @@ public void testExtractResponseTokens_Will_Return_Valid_Map_When_Response_Tokens
final JSONObject mBoxPayloadObject = new JSONObject(mboxPayload);

//Assertions
Map<String, String> responseTokens = responseParser.getResponseTokens(mBoxPayloadObject);
Map<String, Object> responseTokens = responseParser.getResponseTokens(mBoxPayloadObject);

assertNotNull(responseTokens);
assertEquals(2, responseTokens.size());
assertEquals(3, responseTokens.size());
assertEquals("broadband", responseTokens.get("geo.connectionSpeed"));
assertEquals("california", responseTokens.get("geo.state"));
assertEquals(new ArrayList<String>(Arrays.asList("shoes")), responseTokens.get("profile.categoryAffinities"));
}

@Test
Expand Down Expand Up @@ -807,10 +812,62 @@ public void testExtractResponseTokens_Will_Return_Null_When_response_Tokens_Payl
final JSONObject mBoxPayloadObject = new JSONObject(mboxPayload);

//Assertions
Map<String, String> responseTokens = responseParser.getResponseTokens(mBoxPayloadObject);
Map<String, Object> responseTokens = responseParser.getResponseTokens(mBoxPayloadObject);
assertNull(responseTokens);
}

@Test
public void testExtractResponseTokens_Will_Return_Null_When_Mbox_Payload_Is_Null() throws JSONException {
// setup
final JSONObject mBoxPayloadObject = null;

// test
Map<String, Object> responseTokens = responseParser.getResponseTokens(mBoxPayloadObject);

// verify
assertNull(responseTokens);
}

@Test
public void testExtractResponseTokens_Will_Return_Null_When_Response_Tokens_Payload_Is_Invalid() throws JSONException {
try (MockedStatic<JSONUtils> jsonUtilsMock = Mockito.mockStatic(JSONUtils.class)) {
// setup
jsonUtilsMock.when(() -> JSONUtils.toMap(Mockito.any()))
.thenThrow(new JSONException("Invalid JSON"));

final String mboxPayload = "{\n" +
" \"index\":0,\n" +
" \"name\":\"ryan_a4t2\",\n" +
" \"options\":[\n" +
" {\n" +
" \"content\":{\n" +
" \"key2\":\"value2\"\n" +
" },\n" +
" \"type\":\"json\",\n" +
" \"responseTokens\":{\n" +
" \"geo.connectionSpeed\":\"broadband\"\n" +
" },\n" +
" \"sourceType\":\"target\"\n" +
" }\n" +
" ],\n" +
" \"analytics\":{\n" +
" \"payload\":{\n" +
" \"pe\":\"tnt\",\n" +
" \"tnta\":\"333911:0:0:0|2|4445.12,333911:0:0:0|1|4445.12\"\n" +
" }\n" +
" }\n" +
"}";

final JSONObject mBoxPayloadObject = new JSONObject(mboxPayload);

// test
Map<String, Object> responseTokens = responseParser.getResponseTokens(mBoxPayloadObject);

// verify
assertNull(responseTokens);
}
}

// =====================================
// Test extract Click Metric A4T Params
// =====================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void teardown() {
public void test_extensionVersion() {
// test
final String extensionVersion = Target.extensionVersion();
assertEquals("extensionVersion API should return the correct version string.", "2.0.2",
assertEquals("extensionVersion API should return the correct version string.", "2.0.3",
extensionVersion);
}

Expand Down
4 changes: 2 additions & 2 deletions code/testapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')

implementation project(':target')
implementation 'com.adobe.marketing.mobile:core:2.5.0'
implementation 'com.adobe.marketing.mobile:core:2.6.1'
implementation 'com.adobe.marketing.mobile:identity:2.0.3'
implementation 'com.adobe.marketing.mobile:lifecycle:2.0.4'
implementation 'com.adobe.marketing.mobile:assurance:2.1.1'
implementation 'com.adobe.marketing.mobile:assurance:2.2.0'

implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
Expand Down
Loading