summaryrefslogtreecommitdiff
path: root/adservices/tests/unittest/service-core/src/com/android/adservices/data/adselection
diff options
context:
space:
mode:
Diffstat (limited to 'adservices/tests/unittest/service-core/src/com/android/adservices/data/adselection')
-rw-r--r--adservices/tests/unittest/service-core/src/com/android/adservices/data/adselection/AdSelectionEntryDaoTest.java83
-rw-r--r--adservices/tests/unittest/service-core/src/com/android/adservices/data/adselection/DBAdSelectionTest.java2
2 files changed, 84 insertions, 1 deletions
diff --git a/adservices/tests/unittest/service-core/src/com/android/adservices/data/adselection/AdSelectionEntryDaoTest.java b/adservices/tests/unittest/service-core/src/com/android/adservices/data/adselection/AdSelectionEntryDaoTest.java
index 7359d0f6d1..2ce00fcc9d 100644
--- a/adservices/tests/unittest/service-core/src/com/android/adservices/data/adselection/AdSelectionEntryDaoTest.java
+++ b/adservices/tests/unittest/service-core/src/com/android/adservices/data/adselection/AdSelectionEntryDaoTest.java
@@ -56,6 +56,7 @@ public class AdSelectionEntryDaoTest {
private static final long AD_SELECTION_ID_1 = 1;
private static final long AD_SELECTION_ID_2 = 2;
private static final long AD_SELECTION_ID_3 = 3;
+ private static final long AD_SELECTION_ID_4 = 4;
private static final String CONTEXTUAL_SIGNALS = "contextual_signals";
private static final double BID = 5;
@@ -554,6 +555,88 @@ public class AdSelectionEntryDaoTest {
assertEquals(adSelectionEntry, expected);
}
+ @Test
+ public void testRemoveExpiredAdSelection() {
+ DBAdSelection expiredDBAdSelection =
+ new DBAdSelection.Builder()
+ .setAdSelectionId(AD_SELECTION_ID_4)
+ .setCustomAudienceSignals(CUSTOM_AUDIENCE_SIGNALS)
+ .setContextualSignals(CONTEXTUAL_SIGNALS)
+ .setBiddingLogicUri(BIDDING_LOGIC_URI_1)
+ .setWinningAdRenderUri(RENDER_URI)
+ .setWinningAdBid(BID)
+ .setCreationTimestamp(ACTIVATION_TIME.minusSeconds(10))
+ .setCallerPackageName(CALLER_PACKAGE_NAME_1)
+ .build();
+
+ mAdSelectionEntryDao.persistAdSelection(DB_AD_SELECTION_1);
+ mAdSelectionEntryDao.persistAdSelection(expiredDBAdSelection);
+
+ assertTrue(
+ mAdSelectionEntryDao.doesAdSelectionIdExist(DB_AD_SELECTION_1.getAdSelectionId()));
+ assertTrue(
+ mAdSelectionEntryDao.doesAdSelectionIdExist(
+ expiredDBAdSelection.getAdSelectionId()));
+
+ mAdSelectionEntryDao.removeExpiredAdSelection(ACTIVATION_TIME.minusSeconds(5));
+
+ assertTrue(
+ mAdSelectionEntryDao.doesAdSelectionIdExist(DB_AD_SELECTION_1.getAdSelectionId()));
+ assertFalse(
+ mAdSelectionEntryDao.doesAdSelectionIdExist(
+ expiredDBAdSelection.getAdSelectionId()));
+ }
+
+ @Test
+ public void testDoesBuyerDecisionLogicExist() {
+ assertFalse(
+ mAdSelectionEntryDao.doesBuyerDecisionLogicExist(
+ DB_BUYER_DECISION_LOGIC_1.getBiddingLogicUri()));
+
+ mAdSelectionEntryDao.persistBuyerDecisionLogic(DB_BUYER_DECISION_LOGIC_1);
+
+ assertTrue(
+ mAdSelectionEntryDao.doesBuyerDecisionLogicExist(
+ DB_BUYER_DECISION_LOGIC_1.getBiddingLogicUri()));
+ }
+
+ @Test
+ public void testRemoveExpiredBuyerDecisionLogic() {
+ assertFalse(
+ mAdSelectionEntryDao.doesBuyerDecisionLogicExist(
+ DB_BUYER_DECISION_LOGIC_1.getBiddingLogicUri()));
+ assertFalse(
+ mAdSelectionEntryDao.doesBuyerDecisionLogicExist(
+ DB_BUYER_DECISION_LOGIC_2.getBiddingLogicUri()));
+
+ mAdSelectionEntryDao.persistBuyerDecisionLogic(DB_BUYER_DECISION_LOGIC_1);
+ mAdSelectionEntryDao.persistAdSelection(DB_AD_SELECTION_1);
+ mAdSelectionEntryDao.persistBuyerDecisionLogic(DB_BUYER_DECISION_LOGIC_2);
+
+ assertTrue(
+ mAdSelectionEntryDao.doesBuyerDecisionLogicExist(
+ DB_BUYER_DECISION_LOGIC_1.getBiddingLogicUri()));
+ assertTrue(
+ mAdSelectionEntryDao.doesAdSelectionIdExist(DB_AD_SELECTION_1.getAdSelectionId()));
+ assertTrue(
+ mAdSelectionEntryDao.doesBuyerDecisionLogicExist(
+ DB_BUYER_DECISION_LOGIC_2.getBiddingLogicUri()));
+
+ mAdSelectionEntryDao.removeExpiredBuyerDecisionLogic();
+
+ assertTrue(
+ mAdSelectionEntryDao.doesBuyerDecisionLogicExist(
+ DB_BUYER_DECISION_LOGIC_1.getBiddingLogicUri()));
+ assertTrue(
+ mAdSelectionEntryDao.doesAdSelectionIdExist(DB_AD_SELECTION_1.getAdSelectionId()));
+
+ // DB_BUYER_DECISION_LOGIC_2 will be removed because there is no instance of
+ // DB_BUYER_DECISION_LOGIC_2.getBiddingLogicUri() in the DBAdSelection table
+ assertFalse(
+ mAdSelectionEntryDao.doesBuyerDecisionLogicExist(
+ DB_BUYER_DECISION_LOGIC_2.getBiddingLogicUri()));
+ }
+
/**
* Creates expected DBAdSelectionEntry to be used for testing from DBAdSelection and
* DBBuyerDecisionLogic. Remarketing Case
diff --git a/adservices/tests/unittest/service-core/src/com/android/adservices/data/adselection/DBAdSelectionTest.java b/adservices/tests/unittest/service-core/src/com/android/adservices/data/adselection/DBAdSelectionTest.java
index f561ab61b6..807be001cb 100644
--- a/adservices/tests/unittest/service-core/src/com/android/adservices/data/adselection/DBAdSelectionTest.java
+++ b/adservices/tests/unittest/service-core/src/com/android/adservices/data/adselection/DBAdSelectionTest.java
@@ -35,7 +35,7 @@ public class DBAdSelectionTest {
private static final Uri BIDDING_LOGIC_URI = Uri.parse("http://www.domain.com/logic");
private static final Uri RENDER_URI = Uri.parse("http://www.domain.com/advert");
private static final Instant ACTIVATION_TIME = CLOCK.instant().truncatedTo(ChronoUnit.MILLIS);
- ;
+
private static final long AD_SELECTION_ID = 1;
private static final String CONTEXTUAL_SIGNALS = "contextual_signals";