diff --git a/demo-app/build.gradle b/demo-app/build.gradle index 5c1d98ba..8d3f7c89 100644 --- a/demo-app/build.gradle +++ b/demo-app/build.gradle @@ -38,14 +38,14 @@ android { defaultConfig { applicationId "com.personalization.demo" - // Compose requires 21. The SDK keeps minSdk 19 — it takes Compose as compileOnly. - minSdkVersion 21 + // The SDK's minimum. + minSdkVersion 23 targetSdkVersion 34 versionCode 1 versionName "1.0" multiDexEnabled true - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "com.personalization.demo.DemoTestRunner" // Add shop ID to BuildConfig buildConfigField "String", "SHOP_ID", "\"${shopId}\"" diff --git a/demo-app/src/androidTest/java/com/personalization/demo/CoreLiveE2ETest.kt b/demo-app/src/androidTest/java/com/personalization/demo/CoreLiveE2ETest.kt new file mode 100644 index 00000000..5eb3383b --- /dev/null +++ b/demo-app/src/androidTest/java/com/personalization/demo/CoreLiveE2ETest.kt @@ -0,0 +1,428 @@ +package com.personalization.demo + +import android.content.Context +import android.net.ConnectivityManager +import android.net.NetworkCapabilities +import android.os.ParcelFileDescriptor +import android.util.Log +import androidx.test.core.app.ActivityScenario +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry +import com.personalization.LogLevel +import com.personalization.Rees46 +import com.personalization.Rees46Config +import com.personalization.SDK +import com.personalization.SdkLogHandler +import com.personalization.SdkLogMessage +import com.personalization.api.OnApiCallbackListener +import com.personalization.api.models.purchase.PurchaseItemRequest +import com.personalization.api.models.purchase.PurchaseTrackingRequest +import com.personalization.api.models.tracking.TrackingItem +import com.personalization.core.SdkResult +import com.personalization.core.SdkState +import java.io.File +import java.util.concurrent.CopyOnWriteArrayList +import java.util.concurrent.CountDownLatch +import java.util.concurrent.TimeUnit +import org.json.JSONArray +import org.json.JSONObject +import org.junit.After +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertTrue +import org.junit.Assume.assumeTrue +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith + +/** + * Live end-to-end check of the SDK's cores against the real API and the demo shop. + * + * A process has one core, decided by its first initialization, and [DemoApplication] initializes the + * demo shop itself; so these tests run only in a process the application left alone + * (`cleanProcess=true`, see [DemoTestRunner]), one core per run, and each is selected by its own + * argument. Without them every test here is skipped. + * + * [roundTrip], with `coreV2=true` or `coreV2=false`: a fresh install initializes the demo shop, runs a + * live search, tracks a product view, an add to cart, a purchase and a custom event, and checks that + * every request got a `2xx`: + * ``` + * ./gradlew :demo-app:connectedRees46DebugAndroidTest \ + * -Pandroid.testInstrumentationRunnerArguments.class=com.personalization.demo.CoreLiveE2ETest \ + * -Pandroid.testInstrumentationRunnerArguments.cleanProcess=true \ + * -Pandroid.testInstrumentationRunnerArguments.coreV2=true + * ``` + * + * The new core's queue across a restart without a network, in two runs of `am instrument` (the end of + * a run kills the process; the network stays off between them): + * - `offlineStep=1` ([offlineRestart1_queueWithoutNetwork]): initializes online, turns the network + * off, tracks a purchase and a custom event, and checks they wait on disk; + * - `offlineStep=2` ([offlineRestart2_deliverAfterRestart]): a new process initializes offline on the + * stored `did`, turns the network on, and checks that the queue goes without a flush. + * ``` + * adb shell am instrument -w -e cleanProcess true -e offlineStep 1 \ + * -e class com.personalization.demo.CoreLiveE2ETest \ + * com.personalization.demo.test/com.personalization.demo.DemoTestRunner + * ``` + * + * Every purchase is a real order of the demo shop, named `sdk-core-e2e--