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 android.adservices.adselection;
18 
19 import android.adservices.common.AdData;
20 import android.adservices.common.AdTechIdentifier;
21 import android.net.Uri;
22 import android.util.Pair;
23 
24 import com.android.adservices.service.adselection.AdBiddingOutcome;
25 import com.android.adservices.service.adselection.BuyerContextualSignals;
26 import com.android.adservices.service.adselection.CustomAudienceBiddingInfo;
27 
28 import java.util.List;
29 import java.util.stream.Collectors;
30 
31 public class AdBiddingOutcomeFixture {
32 
anAdBiddingOutcomeBuilder( AdTechIdentifier buyer, Double bid)33     public static AdBiddingOutcome.Builder anAdBiddingOutcomeBuilder(
34             AdTechIdentifier buyer, Double bid) {
35 
36         final AdData adData =
37                 new AdData.Builder()
38                         .setRenderUri(
39                                 new Uri.Builder()
40                                         .path("valid.example.com/testing/hello/" + buyer.toString())
41                                         .build())
42                         .setMetadata("{'example': 'metadata', 'valid': true}")
43                         .build();
44         final double testBid = bid;
45 
46         return AdBiddingOutcome.builder()
47                 .setAdWithBid(new AdWithBid(adData, testBid))
48                 .setCustomAudienceBiddingInfo(
49                         CustomAudienceBiddingInfo.builder()
50                                 .setBiddingLogicUri(
51                                         CustomAudienceBiddingInfoFixture.getValidBiddingLogicUri(
52                                                 buyer))
53                                 .setBuyerDecisionLogicJs(
54                                         CustomAudienceBiddingInfoFixture.BUYER_DECISION_LOGIC_JS)
55                                 .setCustomAudienceSignals(
56                                         CustomAudienceSignalsFixture.aCustomAudienceSignalsBuilder()
57                                                 .setBuyer(buyer)
58                                                 .build())
59                                 .build());
60     }
61 
anAdBiddingOutcomeBuilderWithBuyerContextualSignals( AdTechIdentifier buyer, Double bid, BuyerContextualSignals buyerContextualSignals)62     public static AdBiddingOutcome.Builder anAdBiddingOutcomeBuilderWithBuyerContextualSignals(
63             AdTechIdentifier buyer, Double bid, BuyerContextualSignals buyerContextualSignals) {
64 
65         final AdData adData =
66                 new AdData.Builder()
67                         .setRenderUri(
68                                 new Uri.Builder()
69                                         .path("valid.example.com/testing/hello/" + buyer.toString())
70                                         .build())
71                         .setMetadata("{'example': 'metadata', 'valid': true}")
72                         .build();
73         final double testBid = bid;
74 
75         return AdBiddingOutcome.builder()
76                 .setAdWithBid(new AdWithBid(adData, testBid))
77                 .setCustomAudienceBiddingInfo(
78                         CustomAudienceBiddingInfo.builder()
79                                 .setBiddingLogicUri(
80                                         CustomAudienceBiddingInfoFixture.getValidBiddingLogicUri(
81                                                 buyer))
82                                 .setBuyerDecisionLogicJs(
83                                         CustomAudienceBiddingInfoFixture.BUYER_DECISION_LOGIC_JS)
84                                 .setCustomAudienceSignals(
85                                         CustomAudienceSignalsFixture.aCustomAudienceSignalsBuilder()
86                                                 .setBuyer(buyer)
87                                                 .build())
88                                 .setBuyerContextualSignals(buyerContextualSignals)
89                                 .build());
90     }
91 
getListOfAdBiddingOutcomes( List<Pair<AdTechIdentifier, Double>> buyersAndBids)92     public static List<AdBiddingOutcome> getListOfAdBiddingOutcomes(
93             List<Pair<AdTechIdentifier, Double>> buyersAndBids) {
94         return buyersAndBids.stream()
95                 .map(
96                         a ->
97                                 AdBiddingOutcomeFixture.anAdBiddingOutcomeBuilder(a.first, a.second)
98                                         .build())
99                 .collect(Collectors.toList());
100     }
101 }
102