use of org.prebid.mobile.rendering.models.internal.MacrosModel in project prebid-mobile-android by prebid.
the class Bid method substituteMacros.
private static void substituteMacros(Bid bid) {
Map<String, MacrosModel> macrosModelMap = new HashMap<>();
String priceText = String.valueOf(bid.getPrice());
String base64PriceText = Base64.encodeToString(priceText.getBytes(), Base64.NO_WRAP);
macrosModelMap.put(MacrosModel.MACROS_AUCTION_PRICE, new MacrosModel(priceText));
macrosModelMap.put(MacrosModel.MACROS_AUCTION_PRICE_BASE_64, new MacrosModel(base64PriceText));
bid.mAdm = MacrosResolutionHelper.resolveAuctionMacros(bid.mAdm, macrosModelMap);
bid.mNurl = MacrosResolutionHelper.resolveAuctionMacros(bid.mNurl, macrosModelMap);
}
use of org.prebid.mobile.rendering.models.internal.MacrosModel in project prebid-mobile-android by prebid.
the class MacrosResolutionHelperTest method resolveAuctionMacros_ReplaceValueIsNull_LocatedMacrosAreReplacedWithEmptyString.
@Test
public void resolveAuctionMacros_ReplaceValueIsNull_LocatedMacrosAreReplacedWithEmptyString() throws IOException {
String actualResponseWithMacros = ResourceUtils.convertResourceToString("native_bid_response_macros.json");
String expectedResponseWithMacros = ResourceUtils.convertResourceToString("native_bid_response_macros_expected_empty.json");
Map<String, MacrosModel> macrosModelMap = new HashMap<>();
macrosModelMap.put(MACROS_AUCTION_BID_ID, new MacrosModel(null));
macrosModelMap.put(MacrosModel.MACROS_AUCTION_PRICE, new MacrosModel(null));
macrosModelMap.put(MacrosModel.MACROS_AUCTION_PRICE_BASE_64, new MacrosModel(null));
String macrosAfterResolution = MacrosResolutionHelper.resolveAuctionMacros(actualResponseWithMacros, macrosModelMap);
assertEquals(expectedResponseWithMacros, macrosAfterResolution);
}
use of org.prebid.mobile.rendering.models.internal.MacrosModel in project prebid-mobile-android by prebid.
the class MacrosResolutionHelperTest method resolveAuctionMacros_MultipleMatch_LocatedMacrosAreReplaced.
@Test
public void resolveAuctionMacros_MultipleMatch_LocatedMacrosAreReplaced() throws IOException, JSONException {
String actualResponseWithMacros = ResourceUtils.convertResourceToString("native_bid_response_macros.json");
String expectedResponseWithMacros = ResourceUtils.convertResourceToString("native_bid_response_macros_expected.json");
Map<String, MacrosModel> macrosModelMap = new HashMap<>();
Bid bid = Bid.fromJSONObject(new JSONObject(actualResponseWithMacros));
String id = bid.getId();
String price = String.valueOf(bid.getPrice());
String base64Price = Base64.getEncoder().encodeToString(price.getBytes());
macrosModelMap.put(MACROS_AUCTION_BID_ID, new MacrosModel(id));
macrosModelMap.put(MacrosModel.MACROS_AUCTION_PRICE, new MacrosModel(price));
macrosModelMap.put(MacrosModel.MACROS_AUCTION_PRICE_BASE_64, new MacrosModel(base64Price));
String macrosAfterResolution = MacrosResolutionHelper.resolveAuctionMacros(actualResponseWithMacros, macrosModelMap);
assertEquals(expectedResponseWithMacros, macrosAfterResolution);
}
Aggregations