From 8295b0029e21101b85f0fcdfa2f53a6cf3259aa4 Mon Sep 17 00:00:00 2001 From: Vitalii Pavlenko Date: Thu, 1 Aug 2024 17:34:22 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=96=20Bump=20to=20version=207.0.0=20(#?= =?UTF-8?q?311)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 111 +++++++++--------- CHANGELOG.md | 3 + .../criteo/testapp/AdMobMediationActivity.kt | 11 +- .../java/com/criteo/testapp/DfpActivity.java | 10 +- .../criteo/testapp/PubSdkDemoApplication.kt | 1 + app/src/main/res/layout/activity_in_house.xml | 2 +- buildSrc/src/main/java/SdkVersion.kt | 2 +- .../publisher/BidManagerFunctionalTest.java | 1 + .../integration/MraidBannerFunctionalTest.kt | 2 + .../java/com/criteo/publisher/Criteo.java | 9 ++ .../criteo/publisher/DependencyProvider.java | 12 ++ .../publisher/model/CdbRequestFactory.java | 6 + .../com/criteo/publisher/model/Publisher.kt | 2 + .../publisher/model/RemoteConfigRequest.kt | 2 + .../model/RemoteConfigRequestFactory.kt | 4 +- .../publisher/DependencyProviderTest.java | 6 + .../publisher/model/CdbRequestFactoryTest.kt | 48 +++++++- .../criteo/publisher/model/CdbRequestTest.kt | 24 +++- .../model/RemoteConfigRequestFactoryTest.kt | 31 +++++ .../model/RemoteConfigRequestTest.kt | 26 ++++ .../publisher/network/PubSdkApiTest.java | 32 +++++ settings.gradle | 4 +- .../java/com/criteo/publisher/CriteoUtil.java | 1 + .../application/ApplicationResource.java | 1 + 24 files changed, 276 insertions(+), 75 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8bde31604..c2612d922 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -76,7 +76,8 @@ jobs: **/TEST-*.xml android-tests: - runs-on: macos-11 + runs-on: ubuntu-latest + timeout-minutes: 30 strategy: fail-fast: false matrix: @@ -109,6 +110,12 @@ jobs: with: ref: ${{ github.event.inputs.git-ref }} + - name: Enable KVM group perms + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + - name: Setup Java 11 uses: actions/setup-java@v3 with: @@ -122,21 +129,14 @@ jobs: key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} restore-keys: ${{ runner.os }}-gradle- - - name: Disable TCP/UDP Offloading (macOS) - shell: bash - run: | - sudo sysctl -w net.link.generic.system.hwcksum_tx=0 - sudo sysctl -w net.link.generic.system.hwcksum_rx=0 - - name: Run all Android tests uses: reactivecircus/android-emulator-runner@v2 with: api-level: ${{ matrix.api }} target: ${{ matrix.tag }} arch: ${{ matrix.abi }} - force-avd-creation: false # Use a medium size skin rather than default size. Some tests need to have a decent size. - emulator-options: -no-snapshot-save -noaudio -no-boot-anim -skin 360x640 + emulator-options: -no-window -no-snapshot-save -noaudio -no-boot-anim -skin 360x640 disable-animations: true script: | adb logcat -c # clear logs @@ -175,52 +175,53 @@ jobs: **/TEST-*.xml **/test-results/gordon/*.xml - quality-tests: - runs-on: ubuntu-latest - - needs: - - java-tests - - android-tests - - steps: - - name: Checkout (latest) - uses: actions/checkout@v3 - if: github.event.inputs.git-ref == '' - with: - # Fetch the whole history to activate the auto-assignment of Sonar issues. - # Also, Sonar needs the base branch to be fetched in order to provide a good report. - fetch-depth: 0 - - - name: Checkout (custom ref) - uses: actions/checkout@v3 - if: github.event.inputs.git-ref != '' - with: - fetch-depth: 0 # Same as above - ref: ${{ github.event.inputs.git-ref }} - - # Sonar drops support of Java 8 in favor of the new LTS: Java 11. - # See https://sonarcloud.io/documentation/user-guide/move-analysis-java-11/ - - name: Setup Java 11 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: '11' - - - name: Download quality reports of java-tests - uses: actions/download-artifact@v3 - with: - name: java-quality-reports - - - name: Download quality reports of android-tests - uses: actions/download-artifact@v3 - with: - name: android-quality-reports - - - name: SonarQube Analysis - run: ./gradlew sonarqube - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# @TODO: sonarqube doesn't work with Java 11, it needs 17 version as minimum, but the project doesn't build when using Java 17 (there are Kapt errors, which needed to be fixed) +# quality-tests: +# runs-on: ubuntu-latest +# +# needs: +# - java-tests +# - android-tests +# +# steps: +# - name: Checkout (latest) +# uses: actions/checkout@v3 +# if: github.event.inputs.git-ref == '' +# with: +# # Fetch the whole history to activate the auto-assignment of Sonar issues. +# # Also, Sonar needs the base branch to be fetched in order to provide a good report. +# fetch-depth: 0 +# +# - name: Checkout (custom ref) +# uses: actions/checkout@v3 +# if: github.event.inputs.git-ref != '' +# with: +# fetch-depth: 0 # Same as above +# ref: ${{ github.event.inputs.git-ref }} +# +# # Sonar drops support of Java 11 in favor of the Java 17. +# # See https://docs.sonarsource.com/sonarcloud/appendices/announcements/#january-15-end-of-support-for-java-11 +# - name: Setup Java 17 +# uses: actions/setup-java@v3 +# with: +# distribution: 'temurin' +# java-version: '17' +# +# - name: Download quality reports of java-tests +# uses: actions/download-artifact@v3 +# with: +# name: java-quality-reports +# +# - name: Download quality reports of android-tests +# uses: actions/download-artifact@v3 +# with: +# name: android-quality-reports +# +# - name: SonarQube Analysis +# run: ./gradlew sonarqube +# env: +# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} deploy-development-artifacts: runs-on: ubuntu-latest diff --git a/CHANGELOG.md b/CHANGELOG.md index b3f193578..7ab07f4ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Next Version +# Version 7.0.0 +- Add inventoryGroupId parameter + # Version 6.0.0 - Add support of Android 14 (API level 34) - Add support for MRAID 2.0 specification diff --git a/app/src/main/java/com/criteo/testapp/AdMobMediationActivity.kt b/app/src/main/java/com/criteo/testapp/AdMobMediationActivity.kt index 03633e8b6..ed5bd537e 100644 --- a/app/src/main/java/com/criteo/testapp/AdMobMediationActivity.kt +++ b/app/src/main/java/com/criteo/testapp/AdMobMediationActivity.kt @@ -41,14 +41,9 @@ import java.security.MessageDigest class AdMobMediationActivity : AppCompatActivity() { private companion object { - /** This AdMob AdUnit is mapped to this Criteo AdUnit: /140800857/Endeavour_320x50 */ - const val ADMOB_BANNER = "ca-app-pub-8459323526901202/2832836926" - - /** This AdMob AdUnit is mapped to this Criteo AdUnit: /140800857/Endeavour_320x480 */ - const val ADMOB_INTERSTITIAL = "ca-app-pub-8459323526901202/6462812944" - - /** This AdMob AdUnit is mapped to this Criteo AdUnit: /140800857/Endeavour_Native */ - const val ADMOB_NATIVE = "ca-app-pub-8459323526901202/2863808899" + const val ADMOB_BANNER = "ca-app-pub-3940256099942544/9214589741" + const val ADMOB_INTERSTITIAL = "ca-app-pub-3940256099942544/1033173712" + const val ADMOB_NATIVE = "ca-app-pub-3940256099942544/2247696110" } private val tag = javaClass.simpleName diff --git a/app/src/main/java/com/criteo/testapp/DfpActivity.java b/app/src/main/java/com/criteo/testapp/DfpActivity.java index ae192fde7..0f0c59ec8 100644 --- a/app/src/main/java/com/criteo/testapp/DfpActivity.java +++ b/app/src/main/java/com/criteo/testapp/DfpActivity.java @@ -54,11 +54,11 @@ public class DfpActivity extends AppCompatActivity { private static final String TAG = DfpActivity.class.getSimpleName(); - private static final String DFP_INTERSTITIAL_AD_UNIT_ID = "/140800857/Endeavour_Interstitial_320x480"; - private static final String DFP_BANNER_AD_UNIT_ID = "/140800857/Endeavour_320x50"; - private static final String DFP_NATIVE_AD_UNIT_ID = "/140800857/Endeavour_Native"; - private static final String DFP_INTERSTITIAL_VIDEO_ID = INTERSTITIAL_VIDEO.getAdUnitId(); - private static final String DFP_REWARDED_VIDEO_ID = DFP_INTERSTITIAL_VIDEO_ID; // TODO? + private static final String DFP_INTERSTITIAL_AD_UNIT_ID = "/21775744923/example/interstitial"; + private static final String DFP_BANNER_AD_UNIT_ID = "/6499/example/banner"; + private static final String DFP_NATIVE_AD_UNIT_ID = "/6499/example/native"; + private static final String DFP_INTERSTITIAL_VIDEO_ID = "/21775744923/example/rewarded-interstitial"; + private static final String DFP_REWARDED_VIDEO_ID = "/21775744923/example/rewarded"; private LinearLayout linearLayout; private Criteo criteo; diff --git a/app/src/main/java/com/criteo/testapp/PubSdkDemoApplication.kt b/app/src/main/java/com/criteo/testapp/PubSdkDemoApplication.kt index 771e8f78d..838dd7666 100644 --- a/app/src/main/java/com/criteo/testapp/PubSdkDemoApplication.kt +++ b/app/src/main/java/com/criteo/testapp/PubSdkDemoApplication.kt @@ -123,6 +123,7 @@ class PubSdkDemoApplication : MultiDexApplication() { val builder = Criteo.Builder(this, "B-000000") .adUnits(adUnits) + .inventoryGroupId("myInventoryGroupId") if ("release" == BuildConfig.BUILD_TYPE) { // Enable debug logs only on release build. diff --git a/app/src/main/res/layout/activity_in_house.xml b/app/src/main/res/layout/activity_in_house.xml index 79f87a005..6fa8279f3 100644 --- a/app/src/main/res/layout/activity_in_house.xml +++ b/app/src/main/res/layout/activity_in_house.xml @@ -71,7 +71,7 @@ android:layout_height="match_parent" app:criteoAdUnitHeight="50" app:criteoAdUnitWidth="320" - app:criteoAdUnitId="/140800857/Endeavour_320x50" + app:criteoAdUnitId="/6499/example/banner" app:layout_constraintStart_toStartOf="parent" /> () ); diff --git a/publisher-sdk/src/androidTest/java/com/criteo/publisher/integration/MraidBannerFunctionalTest.kt b/publisher-sdk/src/androidTest/java/com/criteo/publisher/integration/MraidBannerFunctionalTest.kt index cc6e375bf..2cc706eb8 100644 --- a/publisher-sdk/src/androidTest/java/com/criteo/publisher/integration/MraidBannerFunctionalTest.kt +++ b/publisher-sdk/src/androidTest/java/com/criteo/publisher/integration/MraidBannerFunctionalTest.kt @@ -20,6 +20,7 @@ import android.view.ViewGroup import android.webkit.JavascriptInterface import android.webkit.WebView import androidx.test.filters.FlakyTest +import androidx.test.filters.LargeTest import androidx.test.rule.ActivityTestRule import com.criteo.publisher.CriteoBannerView import com.criteo.publisher.CriteoUtil @@ -128,6 +129,7 @@ class MraidBannerFunctionalTest { } @Test + @LargeTest @FlakyTest(detail = "Flakiness comes from UI and concurrency") fun whenExpandAndThenClose_ShouldMoveBackToOriginalContainer() { val originalLayoutParams = getWebView().layoutParams diff --git a/publisher-sdk/src/main/java/com/criteo/publisher/Criteo.java b/publisher-sdk/src/main/java/com/criteo/publisher/Criteo.java index 88398e78f..35f5c2c3e 100644 --- a/publisher-sdk/src/main/java/com/criteo/publisher/Criteo.java +++ b/publisher-sdk/src/main/java/com/criteo/publisher/Criteo.java @@ -66,6 +66,9 @@ public static class Builder { @Nullable private Boolean tagForChildDirectedTreatment = null; + @Nullable + private String inventoryGroupId = null; + public Builder(@NonNull Application application, @NonNull String criteoPublisherId) { this.application = application; this.criteoPublisherId = criteoPublisherId; @@ -105,6 +108,11 @@ public Builder tagForChildDirectedTreatment(@Nullable Boolean tagForChildDirecte return this; } + public Builder inventoryGroupId(@Nullable String inventoryGroupId) { + this.inventoryGroupId = inventoryGroupId; + return this; + } + public Criteo init() throws CriteoInitException { return Criteo.init(this); } @@ -119,6 +127,7 @@ private static Criteo init(@NonNull Builder builder) throws CriteoInitException DependencyProvider dependencyProvider = DependencyProvider.getInstance(); dependencyProvider.setApplication(builder.application); dependencyProvider.setCriteoPublisherId(builder.criteoPublisherId); + dependencyProvider.setInventoryGroupId(builder.inventoryGroupId); if (builder.isDebugLogsEnabled) { dependencyProvider.provideConsoleHandler().setMinLogLevel(Log.INFO); diff --git a/publisher-sdk/src/main/java/com/criteo/publisher/DependencyProvider.java b/publisher-sdk/src/main/java/com/criteo/publisher/DependencyProvider.java index f4293a430..67d017f6f 100644 --- a/publisher-sdk/src/main/java/com/criteo/publisher/DependencyProvider.java +++ b/publisher-sdk/src/main/java/com/criteo/publisher/DependencyProvider.java @@ -139,6 +139,7 @@ public class DependencyProvider { private Application application; private String criteoPublisherId; + private String inventoryGroupId; protected DependencyProvider() { } @@ -169,6 +170,10 @@ public void setCriteoPublisherId(@NonNull String criteoPublisherId) { checkCriteoPublisherIdIsSet(); } + public void setInventoryGroupId(@Nullable String inventoryGroupId) { + this.inventoryGroupId = inventoryGroupId; + } + boolean isApplicationSet() { try { DependencyProvider.getInstance().checkApplicationIsSet(); @@ -207,6 +212,11 @@ public String provideCriteoPublisherId() { return criteoPublisherId; } + @Nullable + public String provideInventoryGroupId() { + return inventoryGroupId; + } + @NonNull public PubSdkApi providePubSdkApi() { return getOrCreate(PubSdkApi.class, () -> new PubSdkApi( @@ -351,6 +361,7 @@ public CdbRequestFactory provideCdbRequestFactory() { return getOrCreate(CdbRequestFactory.class, () -> new CdbRequestFactory( provideContext(), provideCriteoPublisherId(), + provideInventoryGroupId(), provideDeviceInfo(), provideAdvertisingInfo(), provideUserPrivacyUtil(), @@ -375,6 +386,7 @@ public RemoteConfigRequestFactory provideRemoteConfigRequestFactory() { return getOrCreate(RemoteConfigRequestFactory.class, () -> new RemoteConfigRequestFactory( provideContext(), provideCriteoPublisherId(), + provideInventoryGroupId(), provideBuildConfigWrapper(), provideIntegrationRegistry() )); diff --git a/publisher-sdk/src/main/java/com/criteo/publisher/model/CdbRequestFactory.java b/publisher-sdk/src/main/java/com/criteo/publisher/model/CdbRequestFactory.java index 92c22eaa7..2f0037a56 100644 --- a/publisher-sdk/src/main/java/com/criteo/publisher/model/CdbRequestFactory.java +++ b/publisher-sdk/src/main/java/com/criteo/publisher/model/CdbRequestFactory.java @@ -49,6 +49,9 @@ public class CdbRequestFactory { @NonNull private final String criteoPublisherId; + @Nullable + private final String inventoryGroupId; + @NonNull private final DeviceInfo deviceInfo; @@ -79,6 +82,7 @@ public class CdbRequestFactory { public CdbRequestFactory( @NonNull Context context, @NonNull String criteoPublisherId, + @Nullable String inventoryGroupId, @NonNull DeviceInfo deviceInfo, @NonNull AdvertisingInfo advertisingInfo, @NonNull UserPrivacyUtil userPrivacyUtil, @@ -91,6 +95,7 @@ public CdbRequestFactory( ) { this.context = context; this.criteoPublisherId = criteoPublisherId; + this.inventoryGroupId = inventoryGroupId; this.deviceInfo = deviceInfo; this.advertisingInfo = advertisingInfo; this.userPrivacyUtil = userPrivacyUtil; @@ -112,6 +117,7 @@ public CdbRequest createRequest( Publisher publisher = new Publisher( context.getPackageName(), criteoPublisherId, + inventoryGroupId, publisherExt ); diff --git a/publisher-sdk/src/main/java/com/criteo/publisher/model/Publisher.kt b/publisher-sdk/src/main/java/com/criteo/publisher/model/Publisher.kt index 7a88d64f3..3c6800bc8 100644 --- a/publisher-sdk/src/main/java/com/criteo/publisher/model/Publisher.kt +++ b/publisher-sdk/src/main/java/com/criteo/publisher/model/Publisher.kt @@ -27,6 +27,8 @@ data class Publisher( val bundleId: String, @Json(name = "cpId") val criteoPublisherId: String, + @Json(name = "inventoryGroupId") + val inventoryGroupId: String?, @Json(name = "ext") val ext: Map ) diff --git a/publisher-sdk/src/main/java/com/criteo/publisher/model/RemoteConfigRequest.kt b/publisher-sdk/src/main/java/com/criteo/publisher/model/RemoteConfigRequest.kt index 660c12935..81ee829ec 100644 --- a/publisher-sdk/src/main/java/com/criteo/publisher/model/RemoteConfigRequest.kt +++ b/publisher-sdk/src/main/java/com/criteo/publisher/model/RemoteConfigRequest.kt @@ -24,6 +24,8 @@ import com.squareup.moshi.JsonClass data class RemoteConfigRequest @JvmOverloads constructor( @Json(name = "cpId") val criteoPublisherId: String, + @Json(name = "inventoryGroupId") + val inventoryGroupId: String?, @Json(name = "bundleId") val bundleId: String, @Json(name = "sdkVersion") diff --git a/publisher-sdk/src/main/java/com/criteo/publisher/model/RemoteConfigRequestFactory.kt b/publisher-sdk/src/main/java/com/criteo/publisher/model/RemoteConfigRequestFactory.kt index aba5bd231..40234618b 100644 --- a/publisher-sdk/src/main/java/com/criteo/publisher/model/RemoteConfigRequestFactory.kt +++ b/publisher-sdk/src/main/java/com/criteo/publisher/model/RemoteConfigRequestFactory.kt @@ -24,12 +24,14 @@ import com.criteo.publisher.util.BuildConfigWrapper class RemoteConfigRequestFactory( private val context: Context, private val criteoPublisherId: String, + private val inventoryGroupId: String?, private val buildConfigWrapper: BuildConfigWrapper, - private val integrationRegistry: IntegrationRegistry + private val integrationRegistry: IntegrationRegistry, ) { fun createRequest(): RemoteConfigRequest { return RemoteConfigRequest( criteoPublisherId, + inventoryGroupId, context.packageName, buildConfigWrapper.sdkVersion, integrationRegistry.profileId diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/DependencyProviderTest.java b/publisher-sdk/src/test/java/com/criteo/publisher/DependencyProviderTest.java index 5df4dbc86..89e782da3 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/DependencyProviderTest.java +++ b/publisher-sdk/src/test/java/com/criteo/publisher/DependencyProviderTest.java @@ -315,6 +315,12 @@ public void provideMraidController_WhenMraidEnabledIsTrueAndMraid2EnabledIsTrueA }); } + @Test + public void setInventoryGroupId_GivenNullIsOk() { + dependencyProvider = DependencyProvider.getInstance(); + dependencyProvider.setInventoryGroupId(null); + } + private void givenMraidIsEnabledEquals(Boolean isMraidEnabled, Boolean isMraid2Enabled, Function providing) { DependencyProvider instance = spy(DependencyProvider.getInstance()); instance.setApplication(ApplicationMock.newMock()); diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/model/CdbRequestFactoryTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/model/CdbRequestFactoryTest.kt index 617f3c814..e452cf53f 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/model/CdbRequestFactoryTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/model/CdbRequestFactoryTest.kt @@ -90,6 +90,7 @@ class CdbRequestFactoryTest { factory = CdbRequestFactory( context, cpId, + null, deviceInfo, advertisingInfo, userPrivacyUtil, @@ -153,6 +154,7 @@ class CdbRequestFactoryTest { val expectedPublisher = Publisher( "bundle.id", "myCpId", + null, mapOf( "a" to mapOf("a" to "foo"), "b" to "bar" @@ -213,7 +215,7 @@ class CdbRequestFactoryTest { var request = factory.createRequest(adUnits, contextData) assertThat(request.id).isEqualTo("myRequestId") - assertThat(request.publisher).isEqualTo(Publisher("bundle.id", "myCpId", mapOf())) + assertThat(request.publisher).isEqualTo(Publisher("bundle.id", "myCpId", null, mapOf())) assertThat(request.sdkVersion).isEqualTo("1.2.3") assertThat(request.profileId).isEqualTo(1337) assertThat(request.gdprData).isEqualTo(expectedGdpr) @@ -413,6 +415,50 @@ class CdbRequestFactoryTest { } } + @Test + fun createRequest_GivenInput_BuildRequestWithInventoryGroupId() { + val adUnit = createAdUnit() + val adUnits: List = listOf(adUnit) + val contextData: ContextData = ContextData().set("a.a", "foo").set("b", "bar") + + buildConfigWrapper.stub { + on { sdkVersion } doReturn "1.2.3" + } + + whenever(context.packageName).thenReturn("bundle.id") + whenever(uniqueIdGenerator.generateId()) + .thenReturn("myRequestId") + .thenReturn("impId") + + val expectedPublisher = Publisher( + "bundle.id", + "myCpId", + "myInventoryGroupId", + mapOf( + "a" to mapOf("a" to "foo"), + "b" to "bar" + ) + ) + + val factory = CdbRequestFactory( + context, + cpId, + "myInventoryGroupId", + deviceInfo, + advertisingInfo, + userPrivacyUtil, + uniqueIdGenerator, + buildConfigWrapper, + integrationRegistry, + contextProvider, + userDataHolder, + config + ) + val request = factory.createRequest(adUnits, contextData) + + assertThat(request.publisher).isEqualTo(expectedPublisher) + } + private fun mockRequiredObjects() { whenever(userPrivacyUtil.tagForChildDirectedTreatment).thenReturn(true) whenever(context.packageName).thenReturn("bundle.id") diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/model/CdbRequestTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/model/CdbRequestTest.kt index fc00aa4f1..f16259b67 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/model/CdbRequestTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/model/CdbRequestTest.kt @@ -41,6 +41,7 @@ class CdbRequestTest { Publisher( "myBundleId", "myCpId", + "myInventoryGroupId", mapOf( "content" to mapOf( "url" to "https://www.criteo.com" @@ -82,6 +83,7 @@ class CdbRequestTest { "publisher": { "bundleId": "myBundleId", "cpId": "myCpId", + "inventoryGroupId": "myInventoryGroupId", "ext": { "content": { "url": "https://www.criteo.com" @@ -126,7 +128,7 @@ class CdbRequestTest { fun toJson_GivenNoGdpr_DoesNotMapIt() { val request = CdbRequest( "myRequestId", - Publisher("myBundleId", "myCpId", mapOf()), + Publisher("myBundleId", "myCpId", "myInventoryGroupId", mapOf()), User(null, null, null, mapOf()), "1.2.3", 456, @@ -144,7 +146,7 @@ class CdbRequestTest { fun toJson_GivenCdbRegsObjectIsNull_DoesNotMapIt() { val request = CdbRequest( "myRequestId", - Publisher("myBundleId", "myCpId", mapOf()), + Publisher("myBundleId", "myCpId", "myInventoryGroupId", mapOf()), User(null, null, null, mapOf()), "1.2.3", 456, @@ -157,4 +159,22 @@ class CdbRequestTest { assertThat(json).doesNotContain("regs") } + + @Test + fun toJson_GivenInventoryGroupIdIsNull_DoesNotMapIt() { + val request = CdbRequest( + "myRequestId", + Publisher("myBundleId", "myCpId", null, mapOf()), + User(null, null, null, mapOf()), + "1.2.3", + 456, + null, + listOf(), + null + ) + + val json = serializer.writeIntoString(request) + + assertThat(json).doesNotContain("inventoryGroupId") + } } diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/model/RemoteConfigRequestFactoryTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/model/RemoteConfigRequestFactoryTest.kt index e6ed8cfb8..dec7b13b9 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/model/RemoteConfigRequestFactoryTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/model/RemoteConfigRequestFactoryTest.kt @@ -50,6 +50,7 @@ class RemoteConfigRequestFactoryTest { factory = RemoteConfigRequestFactory( context, "myCpId", + null, buildConfigWrapper, integrationRegistry ) @@ -76,4 +77,34 @@ class RemoteConfigRequestFactoryTest { assertThat(request.sdkVersion).isEqualTo("1.2.3") assertThat(request.profileId).isEqualTo(456) } + + @Test + fun createRequest_GivenInput_CreateRemoteConfigRequestWithInventoryGroupId() { + buildConfigWrapper.stub { + on { sdkVersion } doReturn "1.2.3" + } + + integrationRegistry.stub { + on { profileId } doReturn 456 + } + + context.stub { + on { packageName } doReturn "my.bundle" + } + + val factory = RemoteConfigRequestFactory( + context, + "myCpId", + "myInventoryGroupId", + buildConfigWrapper, + integrationRegistry + ) + val request = factory.createRequest() + + assertThat(request.bundleId).isEqualTo("my.bundle") + assertThat(request.criteoPublisherId).isEqualTo("myCpId") + assertThat(request.inventoryGroupId).isEqualTo("myInventoryGroupId") + assertThat(request.sdkVersion).isEqualTo("1.2.3") + assertThat(request.profileId).isEqualTo(456) + } } diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/model/RemoteConfigRequestTest.kt b/publisher-sdk/src/test/java/com/criteo/publisher/model/RemoteConfigRequestTest.kt index f2ac33253..33afc53a2 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/model/RemoteConfigRequestTest.kt +++ b/publisher-sdk/src/test/java/com/criteo/publisher/model/RemoteConfigRequestTest.kt @@ -37,6 +37,7 @@ class RemoteConfigRequestTest { fun write_GivenData_ReturnSerializedJson() { val request = RemoteConfigRequest( "myCpId", + null, "my.bundle.id", "1.2.3", 456 @@ -55,4 +56,29 @@ class RemoteConfigRequestTest { } """.trimIndent()) } + + @Test + fun write_GivenData_ReturnSerializedJsonWithInventoryGroupId() { + val request = RemoteConfigRequest( + "myCpId", + "myInventoryGroupId", + "my.bundle.id", + "1.2.3", + 456 + ) + + val json = serializer.writeIntoString(request) + + assertThat(json).isEqualToIgnoringWhitespace( + """ + { + "cpId" : "myCpId", + "inventoryGroupId": "myInventoryGroupId", + "bundleId" : "my.bundle.id", + "sdkVersion" : "1.2.3", + "rtbProfileId": 456, + "deviceOs": "android" + } + """.trimIndent()) + } } diff --git a/publisher-sdk/src/test/java/com/criteo/publisher/network/PubSdkApiTest.java b/publisher-sdk/src/test/java/com/criteo/publisher/network/PubSdkApiTest.java index b8ec82b78..edafab1b0 100644 --- a/publisher-sdk/src/test/java/com/criteo/publisher/network/PubSdkApiTest.java +++ b/publisher-sdk/src/test/java/com/criteo/publisher/network/PubSdkApiTest.java @@ -400,6 +400,7 @@ public void loadCdb_GivenHttpError_ThrowException() throws Exception { public void loadConfig_GivenInput_SendGetRequestWithQueryParameters() throws Exception { RemoteConfigRequest request = new RemoteConfigRequest( "myCpId", + null, "myAppId", "myVersion", 456, @@ -425,6 +426,37 @@ public void loadConfig_GivenInput_SendGetRequestWithQueryParameters() throws Exc assertThat(webRequest.getBody().snapshot().utf8()).isEqualToIgnoringWhitespace(expectedJson); } + @Test + public void loadConfig_GivenInput_SendGetRequestWithInventoryGroupId() throws Exception { + RemoteConfigRequest request = new RemoteConfigRequest( + "myCpId", + "myInventoryGroupId", + "myAppId", + "myVersion", + 456, + "android" + ); + + String expectedJson = "" + + "{\n" + + " \"cpId\" : \"myCpId\",\n" + + " \"inventoryGroupId\" : \"myInventoryGroupId\",\n" + + " \"bundleId\" : \"myAppId\",\n" + + " \"sdkVersion\" : \"myVersion\",\n" + + " \"rtbProfileId\": 456,\n" + + " \"deviceOs\": \"android\"" + + "}"; + + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody("{}")); + + api.loadConfig(request); + + RecordedRequest webRequest = mockWebServer.takeRequest(); + assertThat(webRequest.getPath()).isEqualTo("/config/app"); + assertThat(webRequest.getMethod()).isEqualTo("POST"); + assertThat(webRequest.getBody().snapshot().utf8()).isEqualToIgnoringWhitespace(expectedJson); + } + @Test public void executeRawGet_GivenConnectionError_ThrowIt() throws Exception { givenConnectionError(); diff --git a/settings.gradle b/settings.gradle index ea8939919..76425a9d7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -18,4 +18,6 @@ include ':app' include ':publisher-sdk' include ':publisher-sdk-tests' include ':test-utils' -include ':publisher-sdk-admob19-retrocompat-tests' \ No newline at end of file +include ':publisher-sdk-admob19-retrocompat-tests' + +System.setProperty("sonar.gradle.skipCompile", "true") diff --git a/test-utils/src/main/java/com/criteo/publisher/CriteoUtil.java b/test-utils/src/main/java/com/criteo/publisher/CriteoUtil.java index 85ca860e2..7899d3361 100644 --- a/test-utils/src/main/java/com/criteo/publisher/CriteoUtil.java +++ b/test-utils/src/main/java/com/criteo/publisher/CriteoUtil.java @@ -27,6 +27,7 @@ public class CriteoUtil { public static final String TEST_CP_ID = "B-000001"; public static final String PROD_CP_ID = "B-056946"; public static final String PROD_CDB_URL = "https://bidder.criteo.com"; + public static final String TEST_INVENTORY_GROUP_ID = "testInventoryGroupId"; public static Criteo givenInitializedCriteo(AdUnit... preloadedAdUnits) throws CriteoInitException { diff --git a/test-utils/src/main/java/com/criteo/publisher/application/ApplicationResource.java b/test-utils/src/main/java/com/criteo/publisher/application/ApplicationResource.java index ecc2d8106..44e151252 100644 --- a/test-utils/src/main/java/com/criteo/publisher/application/ApplicationResource.java +++ b/test-utils/src/main/java/com/criteo/publisher/application/ApplicationResource.java @@ -36,6 +36,7 @@ public void setUp() { DependencyProvider dependencyProvider = dependencyProviderRef.get(); dependencyProvider.setApplication(InstrumentationUtil.getApplication()); dependencyProvider.setCriteoPublisherId(CriteoUtil.TEST_CP_ID); + dependencyProvider.setInventoryGroupId(CriteoUtil.TEST_INVENTORY_GROUP_ID); } @Override