1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.adservices.customaudience;
18 
19 import static android.adservices.customaudience.CustomAudience.FLAG_AUCTION_SERVER_REQUEST_OMIT_ADS;
20 
21 import android.adservices.common.AdTechIdentifier;
22 import android.adservices.common.CommonFixture;
23 import android.adservices.customaudience.CustomAudienceFixture;
24 
25 import com.android.adservices.common.DBAdDataFixture;
26 import com.android.adservices.data.customaudience.DBCustomAudience;
27 
28 import java.util.List;
29 import java.util.stream.Collectors;
30 
31 public class DBCustomAudienceFixture {
32     private static final String AD_URI_PREFIX = "http://www.domain.com/adverts/123/";
33     public static final DBCustomAudience VALID_DB_CUSTOM_AUDIENCE_NO_FILTERS =
34             getValidBuilderByBuyerNoFilters(CommonFixture.VALID_BUYER_1).build();
35 
getValidBuilderByBuyer(AdTechIdentifier buyer)36     public static DBCustomAudience.Builder getValidBuilderByBuyer(AdTechIdentifier buyer) {
37         return new DBCustomAudience.Builder()
38                 .setOwner(CustomAudienceFixture.VALID_OWNER)
39                 .setBuyer(buyer)
40                 .setName(CustomAudienceFixture.VALID_NAME)
41                 .setActivationTime(CustomAudienceFixture.VALID_ACTIVATION_TIME)
42                 .setExpirationTime(CustomAudienceFixture.VALID_EXPIRATION_TIME)
43                 .setCreationTime(CommonFixture.FIXED_NOW_TRUNCATED_TO_MILLI)
44                 .setLastAdsAndBiddingDataUpdatedTime(CommonFixture.FIXED_NOW_TRUNCATED_TO_MILLI)
45                 .setUserBiddingSignals(CustomAudienceFixture.VALID_USER_BIDDING_SIGNALS)
46                 .setTrustedBiddingData(
47                         DBTrustedBiddingDataFixture.getValidBuilderByBuyer(buyer).build())
48                 .setBiddingLogicUri(CustomAudienceFixture.getValidBiddingLogicUriByBuyer(buyer))
49                 .setAds(DBAdDataFixture.getValidDbAdDataListByBuyer(buyer));
50     }
51 
getValidBuilderByBuyer( AdTechIdentifier buyer, String name)52     public static DBCustomAudience.Builder getValidBuilderByBuyer(
53             AdTechIdentifier buyer, String name) {
54         return new DBCustomAudience.Builder()
55                 .setOwner(CustomAudienceFixture.VALID_OWNER)
56                 .setBuyer(buyer)
57                 .setName(name)
58                 .setActivationTime(CustomAudienceFixture.VALID_ACTIVATION_TIME)
59                 .setExpirationTime(CustomAudienceFixture.VALID_EXPIRATION_TIME)
60                 .setCreationTime(CommonFixture.FIXED_NOW_TRUNCATED_TO_MILLI)
61                 .setLastAdsAndBiddingDataUpdatedTime(CommonFixture.FIXED_NOW_TRUNCATED_TO_MILLI)
62                 .setUserBiddingSignals(CustomAudienceFixture.VALID_USER_BIDDING_SIGNALS)
63                 .setTrustedBiddingData(
64                         DBTrustedBiddingDataFixture.getValidBuilderByBuyer(buyer).build())
65                 .setBiddingLogicUri(CustomAudienceFixture.getValidBiddingLogicUriByBuyer(buyer))
66                 .setAds(DBAdDataFixture.getValidDbAdDataListByBuyer(buyer));
67     }
68 
getValidBuilderByBuyerWithAdRenderId( AdTechIdentifier buyer, String name)69     public static DBCustomAudience.Builder getValidBuilderByBuyerWithAdRenderId(
70             AdTechIdentifier buyer, String name) {
71         return getValidBuilderByBuyerWithAdRenderId(buyer, name, CustomAudienceFixture.VALID_OWNER);
72     }
73 
getValidBuilderByBuyerWithAdRenderId( AdTechIdentifier buyer, String name, String owner)74     public static DBCustomAudience.Builder getValidBuilderByBuyerWithAdRenderId(
75             AdTechIdentifier buyer, String name, String owner) {
76         return new DBCustomAudience.Builder()
77                 .setOwner(owner)
78                 .setBuyer(buyer)
79                 .setName(name)
80                 .setActivationTime(CustomAudienceFixture.VALID_ACTIVATION_TIME)
81                 .setExpirationTime(CustomAudienceFixture.VALID_EXPIRATION_TIME)
82                 .setCreationTime(CommonFixture.FIXED_NOW_TRUNCATED_TO_MILLI)
83                 .setLastAdsAndBiddingDataUpdatedTime(CommonFixture.FIXED_NOW_TRUNCATED_TO_MILLI)
84                 .setUserBiddingSignals(CustomAudienceFixture.VALID_USER_BIDDING_SIGNALS)
85                 .setTrustedBiddingData(
86                         DBTrustedBiddingDataFixture.getValidBuilderByBuyer(buyer).build())
87                 .setBiddingLogicUri(CustomAudienceFixture.getValidBiddingLogicUriByBuyer(buyer))
88                 .setAds(DBAdDataFixture.getValidDbAdDataListByBuyerWithAdRenderId(buyer));
89     }
90 
getValidBuilderByBuyerNoFilters(AdTechIdentifier buyer)91     public static DBCustomAudience.Builder getValidBuilderByBuyerNoFilters(AdTechIdentifier buyer) {
92         return new DBCustomAudience.Builder()
93                 .setOwner(CustomAudienceFixture.VALID_OWNER)
94                 .setBuyer(buyer)
95                 .setName(CustomAudienceFixture.VALID_NAME)
96                 .setActivationTime(CustomAudienceFixture.VALID_ACTIVATION_TIME)
97                 .setExpirationTime(CustomAudienceFixture.VALID_EXPIRATION_TIME)
98                 .setCreationTime(CommonFixture.FIXED_NOW_TRUNCATED_TO_MILLI)
99                 .setLastAdsAndBiddingDataUpdatedTime(CommonFixture.FIXED_NOW_TRUNCATED_TO_MILLI)
100                 .setUserBiddingSignals(CustomAudienceFixture.VALID_USER_BIDDING_SIGNALS)
101                 .setTrustedBiddingData(
102                         DBTrustedBiddingDataFixture.getValidBuilderByBuyer(buyer).build())
103                 .setBiddingLogicUri(CustomAudienceFixture.getValidBiddingLogicUriByBuyer(buyer))
104                 .setAds(DBAdDataFixture.getValidDbAdDataListByBuyerNoFilters(buyer));
105     }
106 
getListOfBuyersCustomAudiences( List<AdTechIdentifier> buyers)107     public static List<DBCustomAudience> getListOfBuyersCustomAudiences(
108             List<AdTechIdentifier> buyers) {
109         return buyers.stream()
110                 .map(a -> DBCustomAudienceFixture.getValidBuilderByBuyer(a).build())
111                 .collect(Collectors.toList());
112     }
113 
114     /** Build valid DB CA with server auction flags */
getValidBuilderByBuyerWithOmitAdsEnabled( AdTechIdentifier buyer)115     public static DBCustomAudience.Builder getValidBuilderByBuyerWithOmitAdsEnabled(
116             AdTechIdentifier buyer) {
117         return getValidBuilderByBuyerNoFilters(buyer)
118                 .setAuctionServerRequestFlags(FLAG_AUCTION_SERVER_REQUEST_OMIT_ADS);
119     }
120 
121     /** Build valid DB CA with server auction flags and name */
getValidBuilderByBuyerWithOmitAdsEnabled( AdTechIdentifier buyer, String name)122     public static DBCustomAudience.Builder getValidBuilderByBuyerWithOmitAdsEnabled(
123             AdTechIdentifier buyer, String name) {
124         return getValidBuilderByBuyerWithAdRenderId(buyer, name, CustomAudienceFixture.VALID_OWNER)
125                 .setAuctionServerRequestFlags(FLAG_AUCTION_SERVER_REQUEST_OMIT_ADS);
126     }
127 }
128