summaryrefslogtreecommitdiff
path: root/adservices/tests/unittest/service-core/src/com/android/adservices/service/measurement/reporting/AggregateReportingJobHandlerTest.java
diff options
context:
space:
mode:
authorAbhimanyu <abmehta@google.com>2024-01-09 02:07:48 +0000
committerAbhimanyu <abmehta@google.com>2024-01-09 02:14:19 +0000
commitd7d24d6735f18c1738492f49d706184004d29ee4 (patch)
tree8e18981b905b9f657731c2e9025fd60f4104be8d /adservices/tests/unittest/service-core/src/com/android/adservices/service/measurement/reporting/AggregateReportingJobHandlerTest.java
parentdb57ff4d0b0058ce7eaae317f6a6eb44748709a1 (diff)
downloadAdServices-d7d24d6735f18c1738492f49d706184004d29ee4.tar.gz
Add shared_info/debug_mode to normal aggregate report body
Details: Existing check added debug mode to be added to only debug reports. Bug: 319174610 Test: atest com.android.adservices.service.measurement.reporting.AggregateReportingJobHandlerTest Change-Id: I1ced22ced5438c5bdb01094f40bb2dab2f47c8c7
Diffstat (limited to 'adservices/tests/unittest/service-core/src/com/android/adservices/service/measurement/reporting/AggregateReportingJobHandlerTest.java')
-rw-r--r--adservices/tests/unittest/service-core/src/com/android/adservices/service/measurement/reporting/AggregateReportingJobHandlerTest.java159
1 files changed, 159 insertions, 0 deletions
diff --git a/adservices/tests/unittest/service-core/src/com/android/adservices/service/measurement/reporting/AggregateReportingJobHandlerTest.java b/adservices/tests/unittest/service-core/src/com/android/adservices/service/measurement/reporting/AggregateReportingJobHandlerTest.java
index e5700638e2..fd7668d937 100644
--- a/adservices/tests/unittest/service-core/src/com/android/adservices/service/measurement/reporting/AggregateReportingJobHandlerTest.java
+++ b/adservices/tests/unittest/service-core/src/com/android/adservices/service/measurement/reporting/AggregateReportingJobHandlerTest.java
@@ -54,6 +54,7 @@ import com.android.adservices.service.measurement.aggregation.AggregateCryptoFix
import com.android.adservices.service.measurement.aggregation.AggregateEncryptionKey;
import com.android.adservices.service.measurement.aggregation.AggregateEncryptionKeyManager;
import com.android.adservices.service.measurement.aggregation.AggregateReport;
+import com.android.adservices.service.measurement.aggregation.AggregateReportFixture;
import com.android.adservices.service.measurement.util.UnsignedLong;
import com.android.adservices.service.stats.AdServicesLogger;
import com.android.adservices.service.stats.MeasurementReportsStats;
@@ -989,6 +990,164 @@ public class AggregateReportingJobHandlerTest {
verify(mTransaction, times(1)).end();
}
+ @Test
+ public void performReport_normalReportWithDebugKeys_hasDebugModeEnabled()
+ throws DatastoreException, IOException, JSONException {
+ AggregateReport aggregateReport =
+ AggregateReportFixture.getValidAggregateReportBuilder()
+ .setSourceDebugKey(
+ AggregateReportFixture.ValidAggregateReportParams.SOURCE_DEBUG_KEY)
+ .setTriggerDebugKey(
+ AggregateReportFixture.ValidAggregateReportParams.TRIGGER_DEBUG_KEY)
+ .build();
+ executeDebugModeVerification(aggregateReport, mSpyAggregateReportingJobHandler, "enabled");
+ verify(mMeasurementDao, times(1))
+ .markAggregateReportStatus(
+ eq(aggregateReport.getId()), eq(AggregateReport.Status.DELIVERED));
+ }
+
+ @Test
+ public void performReport_normalReportWithOnlySourceDebugKey_hasDebugModeNull()
+ throws DatastoreException, IOException, JSONException {
+ // Setup
+ AggregateReport aggregateReport =
+ AggregateReportFixture.getValidAggregateReportBuilder()
+ .setSourceDebugKey(
+ AggregateReportFixture.ValidAggregateReportParams.SOURCE_DEBUG_KEY)
+ .setTriggerDebugKey(null)
+ .build();
+ executeDebugModeVerification(aggregateReport, mSpyAggregateReportingJobHandler, "");
+ verify(mMeasurementDao, times(1))
+ .markAggregateReportStatus(
+ eq(aggregateReport.getId()), eq(AggregateReport.Status.DELIVERED));
+ }
+
+ @Test
+ public void performReport_normalReportWithOnlyTriggerDebugKey_hasDebugModeNull()
+ throws DatastoreException, IOException, JSONException {
+ AggregateReport aggregateReport =
+ AggregateReportFixture.getValidAggregateReportBuilder()
+ .setSourceDebugKey(null)
+ .setTriggerDebugKey(
+ AggregateReportFixture.ValidAggregateReportParams.TRIGGER_DEBUG_KEY)
+ .build();
+ executeDebugModeVerification(aggregateReport, mSpyAggregateReportingJobHandler, "");
+ verify(mMeasurementDao, times(1))
+ .markAggregateReportStatus(
+ eq(aggregateReport.getId()), eq(AggregateReport.Status.DELIVERED));
+ }
+
+ @Test
+ public void performReport_normalReportWithNoDebugKey_hasDebugModeNull()
+ throws DatastoreException, IOException, JSONException {
+ AggregateReport aggregateReport =
+ AggregateReportFixture.getValidAggregateReportBuilder()
+ .setSourceDebugKey(null)
+ .setTriggerDebugKey(null)
+ .build();
+ executeDebugModeVerification(aggregateReport, mSpyAggregateReportingJobHandler, "");
+ verify(mMeasurementDao, times(1))
+ .markAggregateReportStatus(
+ eq(aggregateReport.getId()), eq(AggregateReport.Status.DELIVERED));
+ }
+
+ @Test
+ public void performReport_debugReportWithDebugKeys_hasDebugModeEnabled()
+ throws DatastoreException, IOException, JSONException {
+ AggregateReport aggregateReport =
+ AggregateReportFixture.getValidAggregateReportBuilder()
+ .setSourceDebugKey(
+ AggregateReportFixture.ValidAggregateReportParams.SOURCE_DEBUG_KEY)
+ .setTriggerDebugKey(
+ AggregateReportFixture.ValidAggregateReportParams.TRIGGER_DEBUG_KEY)
+ .build();
+ executeDebugModeVerification(
+ aggregateReport, mSpyDebugAggregateReportingJobHandler, "enabled");
+ verify(mMeasurementDao, times(1))
+ .markAggregateDebugReportDelivered(eq(aggregateReport.getId()));
+ }
+
+ @Test
+ public void performReport_debugReportWithOnlySourceDebugKey_hasDebugModeNull()
+ throws DatastoreException, IOException, JSONException {
+ AggregateReport aggregateReport =
+ AggregateReportFixture.getValidAggregateReportBuilder()
+ .setSourceDebugKey(
+ AggregateReportFixture.ValidAggregateReportParams.SOURCE_DEBUG_KEY)
+ .setTriggerDebugKey(null)
+ .build();
+ executeDebugModeVerification(aggregateReport, mSpyDebugAggregateReportingJobHandler, "");
+ verify(mMeasurementDao, times(1))
+ .markAggregateDebugReportDelivered(eq(aggregateReport.getId()));
+ }
+
+ @Test
+ public void performReport_debugReportWithOnlyTriggerDebugKey_hasDebugModeNull()
+ throws DatastoreException, IOException, JSONException {
+ AggregateReport aggregateReport =
+ AggregateReportFixture.getValidAggregateReportBuilder()
+ .setSourceDebugKey(null)
+ .setTriggerDebugKey(
+ AggregateReportFixture.ValidAggregateReportParams.TRIGGER_DEBUG_KEY)
+ .build();
+ executeDebugModeVerification(aggregateReport, mSpyDebugAggregateReportingJobHandler, "");
+ }
+
+ @Test
+ public void performReport_debugReportWithNoDebugKey_hasDebugModeNull()
+ throws DatastoreException, IOException, JSONException {
+ AggregateReport aggregateReport =
+ AggregateReportFixture.getValidAggregateReportBuilder()
+ .setSourceDebugKey(null)
+ .setTriggerDebugKey(null)
+ .build();
+ executeDebugModeVerification(aggregateReport, mSpyDebugAggregateReportingJobHandler, "");
+ verify(mMeasurementDao, times(1))
+ .markAggregateDebugReportDelivered(eq(aggregateReport.getId()));
+ }
+
+ private void executeDebugModeVerification(
+ AggregateReport aggregateReport,
+ AggregateReportingJobHandler aggregateReportingJobHandler,
+ String expectedDebugMode)
+ throws DatastoreException, IOException, JSONException {
+ when(mMeasurementDao.getAggregateReport(aggregateReport.getId()))
+ .thenReturn(aggregateReport);
+ doReturn(HttpURLConnection.HTTP_OK)
+ .when(aggregateReportingJobHandler)
+ .makeHttpPostRequest(eq(REPORTING_URI), Mockito.any());
+
+ doNothing()
+ .when(mMeasurementDao)
+ .markAggregateReportStatus(
+ aggregateReport.getId(), AggregateReport.Status.DELIVERED);
+ ArgumentCaptor<JSONObject> aggregateReportBodyCaptor =
+ ArgumentCaptor.forClass(JSONObject.class);
+
+ // Execution
+ Assert.assertEquals(
+ AdServicesStatusUtils.STATUS_SUCCESS,
+ aggregateReportingJobHandler.performReport(
+ aggregateReport.getId(),
+ AggregateCryptoFixture.getKey(),
+ new ReportingStatus()));
+
+ // Assertion
+ verify(aggregateReportingJobHandler)
+ .makeHttpPostRequest(eq(REPORTING_URI), aggregateReportBodyCaptor.capture());
+ verify(mTransaction, times(2)).begin();
+ verify(mTransaction, times(2)).end();
+
+ JSONObject aggregateReportBody = aggregateReportBodyCaptor.getValue();
+ JSONObject sharedInfo =
+ new JSONObject(
+ aggregateReportBody.getString(
+ AggregateReportBody.PayloadBodyKeys.SHARED_INFO));
+ assertEquals(
+ expectedDebugMode,
+ sharedInfo.optString(AggregateReportBody.SharedInfoKeys.DEBUG_MODE));
+ }
+
private static JSONObject createASampleAggregateReportBody(AggregateReport aggregateReport)
throws JSONException {
return new AggregateReportBody.Builder()