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

Update Functional Tests, use Core TimeUtils date formatter, remove Jetifier #50

Merged
merged 16 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 0 additions & 6 deletions code/edgeconsent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,10 @@ dependencies {
testImplementation "org.mockito:mockito-core:${rootProject.ext.mockitoVersion}"
testImplementation "org.mockito:mockito-inline:${rootProject.ext.mockitoVersion}"
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.12.7'
testImplementation 'org.powermock:powermock-api-mockito2:2.0.0'
testImplementation 'org.powermock:powermock-module-junit4:2.0.0'
testImplementation 'org.json:json:20180813'

androidTestImplementation "androidx.test.ext:junit:${rootProject.ext.junitVersion}"
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// Using older version of PowerMock as it supports minimum Android API < 26
// the root issue appears to be a dependency with Objenesis in Mockito-Core
// where Objenesis 2 requires minimum Android API 26
androidTestImplementation 'org.powermock:powermock-module-junit4:1+'
androidTestImplementation 'com.fasterxml.jackson.core:jackson-databind:2.12.7'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright 2022 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

package com.adobe.marketing.mobile;

/**
* Helper class that exists as a way to access test helper methods provided in core
* within the package com.adobe.marketing.mobile
*/
public class MobileCoreHelper {

/**
* Wrapper around {@link MobileCore#resetSDK()}
*/
public static void resetSDK() {
MobileCore.resetSDK();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,32 @@

package com.adobe.marketing.mobile.edge.consent;

import static com.adobe.marketing.mobile.TestHelper.getDispatchedEventsWith;
import static com.adobe.marketing.mobile.TestHelper.getXDMSharedStateFor;
import static com.adobe.marketing.mobile.TestHelper.resetTestExpectations;
import static com.adobe.marketing.mobile.TestHelper.waitForThreads;
import static com.adobe.marketing.mobile.edge.consent.ConsentAndroidTestUtil.*;
import static com.adobe.marketing.mobile.edge.consent.util.ConsentFunctionalTestUtil.*;
import static com.adobe.marketing.mobile.edge.consent.util.TestHelper.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import com.adobe.marketing.mobile.AdobeCallback;
import com.adobe.marketing.mobile.Event;
import com.adobe.marketing.mobile.EventSource;
import com.adobe.marketing.mobile.EventType;
import com.adobe.marketing.mobile.Extension;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.TestHelper;
import com.adobe.marketing.mobile.TestPersistenceHelper;
import java.util.ArrayList;
import com.adobe.marketing.mobile.edge.consent.util.ConsentTestConstants;
import com.adobe.marketing.mobile.edge.consent.util.MonitorExtension;
import com.adobe.marketing.mobile.edge.consent.util.TestHelper;
import com.adobe.marketing.mobile.edge.consent.util.TestPersistenceHelper;
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.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;

public class ConsentBootUpTests {

@Rule
public RuleChain rule = RuleChain
.outerRule(new TestHelper.SetupCoreRule())
.around(new TestHelper.RegisterMonitorExtensionRule());
public TestRule rule = new TestHelper.SetupCoreRule();

@Test
public void test_BootUp_loadsFromPersistence() throws Exception {
Expand Down Expand Up @@ -188,7 +182,7 @@ public void test_BootUp_CompleteWorkflow() throws Exception {
);
HashMap<String, Object> config = new HashMap<String, Object>() {
{
put(ConsentConstants.ConfigurationKey.DEFAULT_CONSENT, CreateConsentXDMMap("y", "n"));
put(ConsentTestConstants.ConfigurationKey.DEFAULT_CONSENT, CreateConsentXDMMap("y", "n"));
}
};
waitForThreads(2000);
Expand Down Expand Up @@ -245,28 +239,12 @@ private void initExtensionWithPersistedDataAndDefaults(
if (defaultConsentMap != null) {
HashMap<String, Object> config = new HashMap<String, Object>() {
{
put(ConsentConstants.ConfigurationKey.DEFAULT_CONSENT, defaultConsentMap);
put(ConsentTestConstants.ConfigurationKey.DEFAULT_CONSENT, defaultConsentMap);
}
};
MobileCore.updateConfiguration(config);
}

//TODO: This file is part of the functional test, will be updated in the functional test PR. These lines need to be comments for this PR.
List<Class<? extends Extension>> extensions = new ArrayList<>();
//extensions.add(Consent.);
//extensions.add(MonitorExtension.class);
//MobileCore.registerExtensions(extensions, o -> latch.countDown());
Consent.registerExtension();
final CountDownLatch latch = new CountDownLatch(1);
MobileCore.start(
new AdobeCallback() {
@Override
public void call(Object o) {
latch.countDown();
}
}
);

latch.await();
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Consent.EXTENSION), null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,38 @@

package com.adobe.marketing.mobile.edge.consent;

import static com.adobe.marketing.mobile.TestHelper.getDispatchedEventsWith;
import static com.adobe.marketing.mobile.TestHelper.getXDMSharedStateFor;
import static com.adobe.marketing.mobile.TestHelper.resetTestExpectations;
import static com.adobe.marketing.mobile.TestHelper.waitForThreads;
import static com.adobe.marketing.mobile.edge.consent.ConsentAndroidTestUtil.*;
import static com.adobe.marketing.mobile.edge.consent.util.ConsentFunctionalTestUtil.CreateConsentXDMMap;
import static com.adobe.marketing.mobile.edge.consent.util.ConsentFunctionalTestUtil.flattenMap;
import static com.adobe.marketing.mobile.edge.consent.util.ConsentFunctionalTestUtil.getConsentsSync;
import static com.adobe.marketing.mobile.edge.consent.util.TestHelper.*;
import static com.adobe.marketing.mobile.edge.consent.util.TestHelper.getDispatchedEventsWith;
import static com.adobe.marketing.mobile.edge.consent.util.TestHelper.getXDMSharedStateFor;
import static com.adobe.marketing.mobile.edge.consent.util.TestHelper.waitForThreads;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import com.adobe.marketing.mobile.AdobeCallback;
import com.adobe.marketing.mobile.Event;
import com.adobe.marketing.mobile.EventSource;
import com.adobe.marketing.mobile.EventType;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.TestHelper;
import com.adobe.marketing.mobile.TestPersistenceHelper;
import com.adobe.marketing.mobile.edge.consent.util.ConsentFunctionalTestUtil;
import com.adobe.marketing.mobile.edge.consent.util.ConsentTestConstants;
import com.adobe.marketing.mobile.edge.consent.util.MonitorExtension;
import com.adobe.marketing.mobile.edge.consent.util.TestHelper;
import com.adobe.marketing.mobile.edge.consent.util.TestPersistenceHelper;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;

public class ConsentDefaultsTests {

@Rule
public RuleChain rule = RuleChain
.outerRule(new TestHelper.SetupCoreRule())
.around(new TestHelper.RegisterMonitorExtensionRule());
public TestRule rule = new TestHelper.SetupCoreRule();

@Test
public void test_ConsentExtension_UsesDefaultConsent() throws Exception {
Expand Down Expand Up @@ -120,7 +122,7 @@ public void test_Reset_DefaultConsent() throws Exception {
initWithDefaultConsent(CreateConsentXDMMap("y", "n")); // Initiate with collectConsent = y and adID = n
HashMap<String, Object> config = new HashMap<String, Object>() {
{
put(ConsentConstants.ConfigurationKey.DEFAULT_CONSENT, CreateConsentXDMMap("n")); // Reset collectConsent = y
put(ConsentTestConstants.ConfigurationKey.DEFAULT_CONSENT, CreateConsentXDMMap("n")); // Reset collectConsent = y
}
};
MobileCore.updateConfiguration(config);
Expand Down Expand Up @@ -169,24 +171,15 @@ public void test_DefaultConsent_NotSavedInPersistence() throws Exception {
private void initWithDefaultConsent(final Map<String, Object> defaultConsentMap) throws InterruptedException {
HashMap<String, Object> config = new HashMap<String, Object>() {
{
put(ConsentConstants.ConfigurationKey.DEFAULT_CONSENT, defaultConsentMap);
put(ConsentTestConstants.ConfigurationKey.DEFAULT_CONSENT, defaultConsentMap);
}
};
MobileCore.updateConfiguration(config);

Consent.registerExtension();

final CountDownLatch latch = new CountDownLatch(1);
MobileCore.start(
new AdobeCallback<Object>() {
@Override
public void call(Object o) {
latch.countDown();
}
}
ConsentFunctionalTestUtil.registerExtensions(
Arrays.asList(MonitorExtension.EXTENSION, Consent.EXTENSION),
config
);

latch.await();
resetTestExpectations();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,46 @@

package com.adobe.marketing.mobile.edge.consent;

import static com.adobe.marketing.mobile.TestHelper.getDispatchedEventsWith;
import static com.adobe.marketing.mobile.TestHelper.getXDMSharedStateFor;
import static com.adobe.marketing.mobile.TestHelper.resetTestExpectations;
import static com.adobe.marketing.mobile.TestHelper.waitForThreads;
import static com.adobe.marketing.mobile.edge.consent.ConsentAndroidTestUtil.*;
import static com.adobe.marketing.mobile.edge.consent.util.ConsentFunctionalTestUtil.*;
import static com.adobe.marketing.mobile.edge.consent.util.TestHelper.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import com.adobe.marketing.mobile.AdobeCallback;
import com.adobe.marketing.mobile.Event;
import com.adobe.marketing.mobile.EventSource;
import com.adobe.marketing.mobile.EventType;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.TestHelper;
import com.adobe.marketing.mobile.TestPersistenceHelper;
import com.adobe.marketing.mobile.edge.consent.util.ConsentFunctionalTestUtil;
import com.adobe.marketing.mobile.edge.consent.util.MonitorExtension;
import com.adobe.marketing.mobile.edge.consent.util.TestHelper;
import com.adobe.marketing.mobile.edge.consent.util.TestPersistenceHelper;
import com.adobe.marketing.mobile.util.JSONUtils;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;

public class ConsentEdgeResponseHandlingTests {

static final String SHARED_STATE = "com.adobe.eventSource.sharedState";

@Rule
public RuleChain rule = RuleChain
.outerRule(new TestHelper.SetupCoreRule())
.around(new TestHelper.RegisterMonitorExtensionRule());
public TestRule rule = new TestHelper.SetupCoreRule();

// --------------------------------------------------------------------------------------------
// Setup
// --------------------------------------------------------------------------------------------

@Before
public void setup() throws Exception {
Consent.registerExtension();

final CountDownLatch latch = new CountDownLatch(1);
MobileCore.start(
new AdobeCallback() {
@Override
public void call(Object o) {
latch.countDown();
}
}
ConsentFunctionalTestUtil.registerExtensions(
Arrays.asList(MonitorExtension.EXTENSION, Consent.EXTENSION),
null
);

latch.await();
resetTestExpectations();
}

@Test
Expand All @@ -86,7 +73,7 @@ public void test_EdgeResponse_MergesWithCurrentConsent() throws Exception {
waitForThreads(1000);
resetTestExpectations();

MobileCore.dispatchEvent(buildEdgeConsentPreferenceEventWithConsents(CreateConsentXDMMap("n")), null); // edge response sets the collect consent to no
MobileCore.dispatchEvent(buildEdgeConsentPreferenceEventWithConsents(CreateConsentXDMMap("n"))); // edge response sets the collect consent to no
waitForThreads(1000);

// verify consent response event dispatched
Expand All @@ -110,7 +97,7 @@ public void test_EdgeResponse_MergesWithCurrentConsent() throws Exception {
ConsentConstants.DataStoreKey.DATASTORE_NAME,
ConsentConstants.DataStoreKey.CONSENT_PREFERENCES
);
Map<String, Object> persistedMap = Utility.toMap(new JSONObject(persistedJson));
Map<String, Object> persistedMap = JSONUtils.toMap(new JSONObject(persistedJson));
Map<String, String> flattenPersistedMap = flattenMap(persistedMap);
assertEquals(2, flattenPersistedMap.size());
assertEquals("n", flattenPersistedMap.get("consents.collect.val"));
Expand Down Expand Up @@ -138,8 +125,7 @@ public void test_EdgeResponse_InvalidPayload() throws Exception {

// test
MobileCore.dispatchEvent(
buildEdgeConsentPreferenceEvent("{\n" + " \"payload\" : \"not what I expect\"\n" + "}"),
null
buildEdgeConsentPreferenceEvent("{\n" + " \"payload\" : \"not what I expect\"\n" + "}")
);
waitForThreads(1000);

Expand All @@ -154,7 +140,7 @@ public void test_EdgeResponse_InvalidPayload() throws Exception {
ConsentConstants.DataStoreKey.DATASTORE_NAME,
ConsentConstants.DataStoreKey.CONSENT_PREFERENCES
);
Map<String, Object> persistedMap = Utility.toMap(new JSONObject(persistedJson));
Map<String, Object> persistedMap = JSONUtils.toMap(new JSONObject(persistedJson));
Map<String, String> flattenPersistedMap = flattenMap(persistedMap);
assertEquals(2, flattenPersistedMap.size());
assertEquals("y", flattenPersistedMap.get("consents.collect.val"));
Expand Down Expand Up @@ -183,7 +169,7 @@ public void test_EdgeResponse_NoConsentChangeAndNoTimestamp() throws Exception {
String timestamp = xdmSharedState.get("consents.metadata.time");

// test
MobileCore.dispatchEvent(buildEdgeConsentPreferenceEventWithConsents(CreateConsentXDMMap("y")), null);
MobileCore.dispatchEvent(buildEdgeConsentPreferenceEventWithConsents(CreateConsentXDMMap("y")));
waitForThreads(1000);

// verify that shared state and consent response events are not dispatched
Expand Down Expand Up @@ -219,10 +205,7 @@ public void test_EdgeResponse_NoConsentChangeAndSameTimestamp() throws Exception
String timestamp = xdmSharedState.get("consents.metadata.time");

// test
MobileCore.dispatchEvent(
buildEdgeConsentPreferenceEventWithConsents(CreateConsentXDMMap("y", "n", timestamp)),
null
);
MobileCore.dispatchEvent(buildEdgeConsentPreferenceEventWithConsents(CreateConsentXDMMap("y", "n", timestamp)));
waitForThreads(1000);

// verify that shared state and consent response events are not dispatched
Expand Down
Loading