Java Code Examples for com.google.android.gms.ads.doubleclick.PublisherAdRequest#Builder
The following examples show how to use
com.google.android.gms.ads.doubleclick.PublisherAdRequest#Builder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdsManager.java From text_converter with GNU General Public License v3.0 | 6 votes |
/** * Create {@link PublisherAdView} and add to container * * @param context - android context * @param container - parent view for add ad view * @return true if ads has been added */ public static boolean addBannerAds(Context context, @Nullable ViewGroup container) { if (isPremiumUser(context)) { if (container != null) { container.setVisibility(View.GONE); } return false; } else { if (container == null) return false; container.setVisibility(View.VISIBLE); PublisherAdView publisherAdView = new PublisherAdView(context); publisherAdView.setAdSizes(AdSize.SMART_BANNER, AdSize.FLUID); publisherAdView.setAdUnitId(AdConstants.AdUnitId.AD_UNIT_ID_NATIVE_MAIN_320_50); PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder(); if (BuildConfig.DEBUG) builder.addTestDevice(TEST_DEVICE_ID); publisherAdView.loadAd(builder.build()); container.removeAllViews(); container.addView(publisherAdView); } return false; }
Example 2
Source File: AdsManager.java From text_converter with GNU General Public License v3.0 | 6 votes |
@Nullable public static PublisherAdView addBannerAds(Context context, @Nullable ViewGroup container, AdSize... adSizes) { if (isPremiumUser(context)) { if (container != null) { container.setVisibility(View.GONE); } return null; } else { if (container == null) return null; container.setVisibility(View.VISIBLE); PublisherAdView publisherAdView = new PublisherAdView(context); publisherAdView.setAdSizes(adSizes); publisherAdView.setAdUnitId(AdConstants.AdUnitId.AD_UNIT_ID_NATIVE_MAIN_320_50); PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder(); if (BuildConfig.DEBUG) builder.addTestDevice(TEST_DEVICE_ID); publisherAdView.loadAd(builder.build()); container.removeAllViews(); container.addView(publisherAdView); return publisherAdView; } }
Example 3
Source File: UtilTest.java From prebid-mobile-android with Apache License 2.0 | 6 votes |
@Test public void testApplyBidsToDFOAdObject() throws Exception { PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder(); builder.addCustomTargeting("Key", "Value"); HashMap<String, String> bids = new HashMap<>(); bids.put("hb_pb", "0.50"); bids.put("hb_cache_id", "123456"); PublisherAdRequest request = builder.build(); Util.apply(bids, request); assertEquals(3, request.getCustomTargeting().size()); assertTrue(request.getCustomTargeting().containsKey("Key")); assertEquals("Value", request.getCustomTargeting().get("Key")); assertTrue(request.getCustomTargeting().containsKey("hb_pb")); assertEquals("0.50", request.getCustomTargeting().get("hb_pb")); assertTrue(request.getCustomTargeting().containsKey("hb_cache_id")); assertEquals("123456", request.getCustomTargeting().get("hb_cache_id")); Util.apply(null, request); assertEquals(1, request.getCustomTargeting().size()); assertTrue(request.getCustomTargeting().containsKey("Key")); assertEquals("Value", request.getCustomTargeting().get("Key")); }
Example 4
Source File: DemandFetcherTest.java From prebid-mobile-android with Apache License 2.0 | 6 votes |
@Test public void testBaseConditions() throws Exception { PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder(); PublisherAdRequest request = builder.build(); DemandFetcher demandFetcher = new DemandFetcher(request); demandFetcher.setPeriodMillis(0); HashSet<AdSize> sizes = new HashSet<>(); sizes.add(new AdSize(300, 250)); RequestParams requestParams = new RequestParams("12345", AdType.BANNER, sizes); demandFetcher.setRequestParams(requestParams); assertEquals(DemandFetcher.STATE.STOPPED, FieldUtils.readField(demandFetcher, "state", true)); demandFetcher.start(); assertEquals(DemandFetcher.STATE.RUNNING, FieldUtils.readField(demandFetcher, "state", true)); ShadowLooper fetcherLooper = Shadows.shadowOf(demandFetcher.getHandler().getLooper()); fetcherLooper.runOneTask(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); demandFetcher.destroy(); assertEquals(DemandFetcher.STATE.DESTROYED, FieldUtils.readField(demandFetcher, "state", true)); }
Example 5
Source File: GooglePlayDFPInterstitial.java From mobile-sdk-android with Apache License 2.0 | 6 votes |
private PublisherAdRequest buildRequest(TargetingParameters targetingParameters) { PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder(); Bundle bundle = new Bundle(); if (targetingParameters.getAge() != null) { bundle.putString("Age", targetingParameters.getAge()); } if (targetingParameters.getLocation() != null) { builder.setLocation(targetingParameters.getLocation()); } for (Pair<String, String> p : targetingParameters.getCustomKeywords()) { if (p.first.equals("content_url")) { if (!StringUtil.isEmpty(p.second)) { builder.setContentUrl(p.second); } } else { bundle.putString(p.first, p.second); } } //Since AdMobExtras is deprecated so we need to use below method builder.addNetworkExtrasBundle(com.google.ads.mediation.admob.AdMobAdapter.class, bundle); return builder.build(); }
Example 6
Source File: DemoActivity.java From prebid-mobile-android with Apache License 2.0 | 5 votes |
private void loadAMBanner() { FrameLayout adFrame = findViewById(R.id.adFrame); adFrame.removeAllViews(); adFrame.addView(amBanner); amBanner.setAdListener(new AdListener() { @Override public void onAdLoaded() { super.onAdLoaded(); AdViewUtils.findPrebidCreativeSize(amBanner, new AdViewUtils.PbFindSizeListener() { @Override public void success(int width, int height) { amBanner.setAdSizes(new AdSize(width, height)); } @Override public void failure(@NonNull PbFindSizeError error) { Log.d("MyTag", "error: " + error); } }); } }); final PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder(); final PublisherAdRequest request = builder.build(); //region PrebidMobile Mobile API 1.0 usage int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0); adUnit.setAutoRefreshPeriodMillis(millis); adUnit.fetchDemand(request, new OnCompleteListener() { @Override public void onComplete(ResultCode resultCode) { DemoActivity.this.resultCode = resultCode; amBanner.loadAd(request); refreshCount++; } }); }
Example 7
Source File: DemoActivity.java From prebid-mobile-android with Apache License 2.0 | 5 votes |
private void loadAMInterstitial() { int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0); adUnit.setAutoRefreshPeriodMillis(millis); PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder(); request = builder.build(); adUnit.fetchDemand(request, new OnCompleteListener() { @Override public void onComplete(ResultCode resultCode) { DemoActivity.this.resultCode = resultCode; amInterstitial.loadAd(request); refreshCount++; } }); }
Example 8
Source File: ResultCodeTest.java From prebid-mobile-android with Apache License 2.0 | 5 votes |
@Test public void testSupportMultipleSizesForDFPBanner() throws Exception { PrebidMobile.setPrebidServerAccountId("123456"); BannerAdUnit adUnit = new BannerAdUnit("123456", 320, 50); adUnit.addAdditionalSize(300, 250); OnCompleteListener mockListener = mock(OnCompleteListener.class); PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder(); adUnit.fetchDemand(builder.build(), mockListener); verify(mockListener, never()).onComplete(ResultCode.INVALID_SIZE); }
Example 9
Source File: DemandFetcherTest.java From prebid-mobile-android with Apache License 2.0 | 5 votes |
@Test public void testSingleRequestNoBidsResponse() throws Exception { HttpUrl httpUrl = server.url("/"); PrebidMobile.setApplicationContext(activity); Host.CUSTOM.setHostUrl(httpUrl.toString()); PrebidMobile.setPrebidServerHost(Host.CUSTOM); server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.noBid())); PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder(); PublisherAdRequest request = builder.build(); DemandFetcher demandFetcher = new DemandFetcher(request); PrebidMobile.setTimeoutMillis(Integer.MAX_VALUE); demandFetcher.setPeriodMillis(0); HashSet<AdSize> sizes = new HashSet<>(); sizes.add(new AdSize(300, 250)); RequestParams requestParams = new RequestParams("12345", AdType.BANNER, sizes); demandFetcher.setRequestParams(requestParams); OnCompleteListener mockListener = mock(OnCompleteListener.class); demandFetcher.setListener(mockListener); assertEquals(DemandFetcher.STATE.STOPPED, FieldUtils.readField(demandFetcher, "state", true)); demandFetcher.start(); assertEquals(DemandFetcher.STATE.RUNNING, FieldUtils.readField(demandFetcher, "state", true)); ShadowLooper fetcherLooper = Shadows.shadowOf(demandFetcher.getHandler().getLooper()); fetcherLooper.runOneTask(); ShadowLooper demandLooper = Shadows.shadowOf(demandFetcher.getDemandHandler().getLooper()); demandLooper.runOneTask(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); verify(mockListener).onComplete(ResultCode.NO_BIDS); assertEquals(DemandFetcher.STATE.DESTROYED, FieldUtils.readField(demandFetcher, "state", true)); }
Example 10
Source File: DemandFetcherTest.java From prebid-mobile-android with Apache License 2.0 | 5 votes |
@Test public void testDestroyAutoRefresh() throws Exception { HttpUrl httpUrl = server.url("/"); PrebidMobile.setApplicationContext(activity); Host.CUSTOM.setHostUrl(httpUrl.toString()); PrebidMobile.setPrebidServerHost(Host.CUSTOM); server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.noBid())); server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.noBid())); server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.noBid())); PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder(); PublisherAdRequest request = builder.build(); DemandFetcher demandFetcher = new DemandFetcher(request); PrebidMobile.setTimeoutMillis(Integer.MAX_VALUE); demandFetcher.setPeriodMillis(30); HashSet<AdSize> sizes = new HashSet<>(); sizes.add(new AdSize(300, 250)); RequestParams requestParams = new RequestParams("12345", AdType.BANNER, sizes); demandFetcher.setRequestParams(requestParams); OnCompleteListener mockListener = mock(OnCompleteListener.class); demandFetcher.setListener(mockListener); assertEquals(DemandFetcher.STATE.STOPPED, FieldUtils.readField(demandFetcher, "state", true)); demandFetcher.start(); assertEquals(DemandFetcher.STATE.RUNNING, FieldUtils.readField(demandFetcher, "state", true)); ShadowLooper fetcherLooper = Shadows.shadowOf(demandFetcher.getHandler().getLooper()); fetcherLooper.runOneTask(); ShadowLooper demandLooper = Shadows.shadowOf(demandFetcher.getDemandHandler().getLooper()); demandLooper.runOneTask(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); assertEquals(DemandFetcher.STATE.RUNNING, FieldUtils.readField(demandFetcher, "state", true)); demandFetcher.destroy(); assertTrue(!Robolectric.getForegroundThreadScheduler().areAnyRunnable()); assertTrue(!Robolectric.getBackgroundThreadScheduler().areAnyRunnable()); assertEquals(DemandFetcher.STATE.DESTROYED, FieldUtils.readField(demandFetcher, "state", true)); verify(mockListener, Mockito.times(1)).onComplete(ResultCode.NO_BIDS); }
Example 11
Source File: RNPublisherBannerViewManager.java From react-native-admob with BSD 2-Clause "Simplified" License | 5 votes |
public void loadBanner() { ArrayList<AdSize> adSizes = new ArrayList<AdSize>(); if (this.adSize != null) { adSizes.add(this.adSize); } if (this.validAdSizes != null) { for (int i = 0; i < this.validAdSizes.length; i++) { adSizes.add(this.validAdSizes[i]); } } if (adSizes.size() == 0) { adSizes.add(AdSize.BANNER); } AdSize[] adSizesArray = adSizes.toArray(new AdSize[adSizes.size()]); this.adView.setAdSizes(adSizesArray); PublisherAdRequest.Builder adRequestBuilder = new PublisherAdRequest.Builder(); if (testDevices != null) { for (int i = 0; i < testDevices.length; i++) { String testDevice = testDevices[i]; if (testDevice == "SIMULATOR") { testDevice = PublisherAdRequest.DEVICE_ID_EMULATOR; } adRequestBuilder.addTestDevice(testDevice); } } PublisherAdRequest adRequest = adRequestBuilder.build(); this.adView.loadAd(adRequest); }
Example 12
Source File: DemoActivity.java From prebid-mobile-android with Apache License 2.0 | 4 votes |
void createDFPNative() { FrameLayout adFrame = (FrameLayout) findViewById(R.id.adFrame); adFrame.removeAllViews(); final PublisherAdView nativeAdView = new PublisherAdView(this); nativeAdView.setAdListener(new AdListener() { @Override public void onAdLoaded() { super.onAdLoaded(); LogUtil.d("ad loaded"); } }); nativeAdView.setAdUnitId(Constants.DFP_IN_BANNER_NATIVE_ADUNIT_ID_APPNEXUS); nativeAdView.setAdSizes(AdSize.FLUID); adFrame.addView(nativeAdView); final PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder(); request = builder.build(); NativeAdUnit nativeAdUnit = (NativeAdUnit) adUnit; nativeAdUnit.setContextType(NativeAdUnit.CONTEXT_TYPE.SOCIAL_CENTRIC); nativeAdUnit.setPlacementType(NativeAdUnit.PLACEMENTTYPE.CONTENT_FEED); nativeAdUnit.setContextSubType(NativeAdUnit.CONTEXTSUBTYPE.GENERAL_SOCIAL); ArrayList<NativeEventTracker.EVENT_TRACKING_METHOD> methods = new ArrayList<>(); methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.IMAGE); try { NativeEventTracker tracker = new NativeEventTracker(NativeEventTracker.EVENT_TYPE.IMPRESSION, methods); nativeAdUnit.addEventTracker(tracker); } catch (Exception e) { e.printStackTrace(); } NativeTitleAsset title = new NativeTitleAsset(); title.setLength(90); title.setRequired(true); nativeAdUnit.addAsset(title); NativeImageAsset icon = new NativeImageAsset(); icon.setImageType(NativeImageAsset.IMAGE_TYPE.ICON); icon.setWMin(20); icon.setHMin(20); icon.setRequired(true); nativeAdUnit.addAsset(icon); NativeImageAsset image = new NativeImageAsset(); image.setImageType(NativeImageAsset.IMAGE_TYPE.MAIN); image.setHMin(200); image.setWMin(200); image.setRequired(true); nativeAdUnit.addAsset(image); NativeDataAsset data = new NativeDataAsset(); data.setLen(90); data.setDataType(NativeDataAsset.DATA_TYPE.SPONSORED); data.setRequired(true); nativeAdUnit.addAsset(data); NativeDataAsset body = new NativeDataAsset(); body.setRequired(true); body.setDataType(NativeDataAsset.DATA_TYPE.DESC); nativeAdUnit.addAsset(body); NativeDataAsset cta = new NativeDataAsset(); cta.setRequired(true); cta.setDataType(NativeDataAsset.DATA_TYPE.CTATEXT); nativeAdUnit.addAsset(cta); int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0); nativeAdUnit.setAutoRefreshPeriodMillis(millis); nativeAdUnit.fetchDemand(request, new OnCompleteListener() { @Override public void onComplete(ResultCode resultCode) { DemoActivity.this.resultCode = resultCode; nativeAdView.loadAd(request); DemoActivity.this.request = request; refreshCount++; } }); }
Example 13
Source File: DemandFetcherTest.java From prebid-mobile-android with Apache License 2.0 | 4 votes |
@Test public void testSingleRequestOneBidResponseForDFPAdObject() throws Exception { HttpUrl httpUrl = server.url("/"); PrebidMobile.setApplicationContext(activity); Host.CUSTOM.setHostUrl(httpUrl.toString()); PrebidMobile.setPrebidServerHost(Host.CUSTOM); server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.oneBidFromAppNexus())); PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder(); PublisherAdRequest request = builder.build(); DemandFetcher demandFetcher = new DemandFetcher(request); PrebidMobile.setTimeoutMillis(Integer.MAX_VALUE); demandFetcher.setPeriodMillis(0); HashSet<AdSize> sizes = new HashSet<>(); sizes.add(new AdSize(300, 250)); RequestParams requestParams = new RequestParams("12345", AdType.BANNER, sizes); demandFetcher.setRequestParams(requestParams); OnCompleteListener mockListener = mock(OnCompleteListener.class); demandFetcher.setListener(mockListener); assertEquals(DemandFetcher.STATE.STOPPED, FieldUtils.readField(demandFetcher, "state", true)); demandFetcher.start(); assertEquals(DemandFetcher.STATE.RUNNING, FieldUtils.readField(demandFetcher, "state", true)); ShadowLooper fetcherLooper = Shadows.shadowOf(demandFetcher.getHandler().getLooper()); fetcherLooper.runOneTask(); ShadowLooper demandLooper = Shadows.shadowOf(demandFetcher.getDemandHandler().getLooper()); demandLooper.runOneTask(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); verify(mockListener).onComplete(ResultCode.SUCCESS); assertEquals(DemandFetcher.STATE.DESTROYED, FieldUtils.readField(demandFetcher, "state", true)); Bundle bundle = request.getCustomTargeting(); assertEquals(10, bundle.size()); assertTrue(bundle.containsKey("hb_pb")); assertEquals("0.50", bundle.get("hb_pb")); assertTrue(bundle.containsKey("hb_bidder")); assertEquals("appnexus", bundle.get("hb_bidder")); assertTrue(bundle.containsKey("hb_bidder_appnexus")); assertEquals("appnexus", bundle.get("hb_bidder_appnexus")); assertTrue(bundle.containsKey("hb_cache_id")); assertEquals("df4aba04-5e69-44b8-8608-058ab21600b8", bundle.get("hb_cache_id")); assertTrue(bundle.containsKey("hb_cache_id_appnexus")); assertEquals("df4aba04-5e69-44b8-8608-058ab21600b8", bundle.get("hb_cache_id_appnexus")); assertTrue(bundle.containsKey("hb_env")); assertEquals("mobile-app", bundle.get("hb_env")); assertTrue(bundle.containsKey("hb_env_appnexus")); assertEquals("mobile-app", bundle.get("hb_env_appnexus")); assertTrue(bundle.containsKey("hb_pb_appnexus")); assertEquals("0.50", bundle.get("hb_pb_appnexus")); assertTrue(bundle.containsKey("hb_size")); assertEquals("300x250", bundle.get("hb_size")); assertTrue(bundle.containsKey("hb_size_appnexus")); assertEquals("300x250", bundle.get("hb_size_appnexus")); }
Example 14
Source File: DemandFetcherTest.java From prebid-mobile-android with Apache License 2.0 | 4 votes |
@Test public void testSingleRequestOneBidRubiconResponseForDFPAdObject() throws Exception { HttpUrl httpUrl = server.url("/"); PrebidMobile.setApplicationContext(activity); Host.CUSTOM.setHostUrl(httpUrl.toString()); PrebidMobile.setPrebidServerHost(Host.CUSTOM); server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.oneBidFromRubicon())); PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder(); PublisherAdRequest request = builder.build(); DemandFetcher demandFetcher = new DemandFetcher(request); PrebidMobile.setTimeoutMillis(Integer.MAX_VALUE); demandFetcher.setPeriodMillis(0); HashSet<AdSize> sizes = new HashSet<>(); sizes.add(new AdSize(300, 250)); RequestParams requestParams = new RequestParams("12345", AdType.BANNER, sizes); demandFetcher.setRequestParams(requestParams); OnCompleteListener mockListener = mock(OnCompleteListener.class); demandFetcher.setListener(mockListener); assertEquals(DemandFetcher.STATE.STOPPED, FieldUtils.readField(demandFetcher, "state", true)); demandFetcher.start(); assertEquals(DemandFetcher.STATE.RUNNING, FieldUtils.readField(demandFetcher, "state", true)); ShadowLooper fetcherLooper = Shadows.shadowOf(demandFetcher.getHandler().getLooper()); fetcherLooper.runOneTask(); ShadowLooper demandLooper = Shadows.shadowOf(demandFetcher.getDemandHandler().getLooper()); demandLooper.runOneTask(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); verify(mockListener).onComplete(ResultCode.SUCCESS); assertEquals(DemandFetcher.STATE.DESTROYED, FieldUtils.readField(demandFetcher, "state", true)); Bundle bundle = request.getCustomTargeting(); Assert.assertEquals(16, bundle.size()); String hb_pb = "hb_pb"; Assert.assertTrue(bundle.containsKey(hb_pb)); Assert.assertEquals("1.20", bundle.get(hb_pb)); String hb_pb_rubicon = "hb_pb_rubicon"; Assert.assertTrue(bundle.containsKey(hb_pb_rubicon)); Assert.assertEquals("1.20", bundle.get(hb_pb_rubicon)); String hb_bidder = "hb_bidder"; Assert.assertTrue(bundle.containsKey(hb_bidder)); Assert.assertEquals("rubicon", bundle.get(hb_bidder)); String hb_bidder_rubicon = "hb_bidder_rubicon"; Assert.assertTrue(bundle.containsKey(hb_bidder_rubicon)); Assert.assertEquals("rubicon", bundle.get(hb_bidder_rubicon)); String hb_cache_id = "hb_cache_id"; Assert.assertTrue(bundle.containsKey(hb_cache_id)); Assert.assertEquals("a2f41588-4727-425c-9ef0-3b382debef1e", bundle.get(hb_cache_id)); String hb_cache_id_rubicon = "hb_cache_id_rubicon"; Assert.assertTrue(bundle.containsKey(hb_cache_id_rubicon)); Assert.assertEquals("a2f41588-4727-425c-9ef0-3b382debef1e", bundle.get(hb_cache_id_rubicon)); String hb_env = "hb_env"; Assert.assertTrue(bundle.containsKey(hb_env)); Assert.assertEquals("mobile-app", bundle.get(hb_env)); String hb_env_rubicon = "hb_env_rubicon"; Assert.assertTrue(bundle.containsKey(hb_env_rubicon)); Assert.assertEquals("mobile-app", bundle.get(hb_env_rubicon)); String hb_size = "hb_size"; Assert.assertTrue(bundle.containsKey(hb_size)); Assert.assertEquals("300x250", bundle.get(hb_size)); String hb_size_rubicon = "hb_size_rubicon"; Assert.assertTrue(bundle.containsKey(hb_size_rubicon)); Assert.assertEquals("300x250", bundle.get(hb_size_rubicon)); String hb_cache_hostpath = "hb_cache_hostpath"; Assert.assertTrue(bundle.containsKey(hb_cache_hostpath)); Assert.assertEquals("https://prebid-cache-europe.rubiconproject.com/cache", bundle.get(hb_cache_hostpath)); String hb_cache_hostpath_rubicon = "hb_cache_hostpath_rubicon"; Assert.assertTrue(bundle.containsKey(hb_cache_hostpath_rubicon)); Assert.assertEquals("https://prebid-cache-europe.rubiconproject.com/cache", bundle.get(hb_cache_hostpath_rubicon)); String hb_cache_path = "hb_cache_path"; Assert.assertTrue(bundle.containsKey(hb_cache_path)); Assert.assertEquals("/cache", bundle.get(hb_cache_path)); String hb_cache_path_rubicon = "hb_cache_path_rubicon"; Assert.assertTrue(bundle.containsKey(hb_cache_path_rubicon)); Assert.assertEquals("/cache", bundle.get(hb_cache_path_rubicon)); String hb_cache_host = "hb_cache_host"; Assert.assertTrue(bundle.containsKey(hb_cache_host)); Assert.assertEquals("prebid-cache-europe.rubiconproject.com", bundle.get(hb_cache_host)); String hb_cache_host_rubicon = "hb_cache_host_rubicon"; Assert.assertTrue(bundle.containsKey(hb_cache_host_rubicon)); Assert.assertEquals("prebid-cache-europe.rubiconproject.com", bundle.get(hb_cache_host_rubicon)); }
Example 15
Source File: DemandFetcherTest.java From prebid-mobile-android with Apache License 2.0 | 4 votes |
@Test public void testAutoRefreshForDFPAdObject() throws Exception { HttpUrl httpUrl = server.url("/"); PrebidMobile.setApplicationContext(activity); Host.CUSTOM.setHostUrl(httpUrl.toString()); PrebidMobile.setPrebidServerHost(Host.CUSTOM); server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.oneBidFromAppNexus())); server.enqueue(new MockResponse().setResponseCode(200).setBody("{}")); PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder(); PublisherAdRequest request = builder.build(); DemandFetcher demandFetcher = new DemandFetcher(request); PrebidMobile.setTimeoutMillis(Integer.MAX_VALUE); demandFetcher.setPeriodMillis(2000); HashSet<AdSize> sizes = new HashSet<>(); sizes.add(new AdSize(300, 250)); RequestParams requestParams = new RequestParams("12345", AdType.BANNER, sizes); demandFetcher.setRequestParams(requestParams); OnCompleteListener mockListener = mock(OnCompleteListener.class); demandFetcher.setListener(mockListener); assertEquals(DemandFetcher.STATE.STOPPED, FieldUtils.readField(demandFetcher, "state", true)); demandFetcher.start(); assertEquals(DemandFetcher.STATE.RUNNING, FieldUtils.readField(demandFetcher, "state", true)); ShadowLooper fetcherLooper = Shadows.shadowOf(demandFetcher.getHandler().getLooper()); fetcherLooper.runOneTask(); ShadowLooper demandLooper = Shadows.shadowOf(demandFetcher.getDemandHandler().getLooper()); demandLooper.runOneTask(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); verify(mockListener).onComplete(ResultCode.SUCCESS); assertEquals(DemandFetcher.STATE.RUNNING, FieldUtils.readField(demandFetcher, "state", true)); Bundle bundle = request.getCustomTargeting(); assertEquals(10, bundle.size()); assertTrue(bundle.containsKey("hb_pb")); assertEquals("0.50", bundle.get("hb_pb")); assertTrue(bundle.containsKey("hb_bidder")); assertEquals("appnexus", bundle.get("hb_bidder")); assertTrue(bundle.containsKey("hb_bidder_appnexus")); assertEquals("appnexus", bundle.get("hb_bidder_appnexus")); assertTrue(bundle.containsKey("hb_cache_id")); assertEquals("df4aba04-5e69-44b8-8608-058ab21600b8", bundle.get("hb_cache_id")); assertTrue(bundle.containsKey("hb_cache_id_appnexus")); assertEquals("df4aba04-5e69-44b8-8608-058ab21600b8", bundle.get("hb_cache_id_appnexus")); assertTrue(bundle.containsKey("hb_env")); assertEquals("mobile-app", bundle.get("hb_env")); assertTrue(bundle.containsKey("hb_env_appnexus")); assertEquals("mobile-app", bundle.get("hb_env_appnexus")); assertTrue(bundle.containsKey("hb_pb_appnexus")); assertEquals("0.50", bundle.get("hb_pb_appnexus")); assertTrue(bundle.containsKey("hb_size")); assertEquals("300x250", bundle.get("hb_size")); assertTrue(bundle.containsKey("hb_size_appnexus")); assertEquals("300x250", bundle.get("hb_size_appnexus")); fetcherLooper.runOneTask(); demandLooper.runOneTask(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); verify(mockListener).onComplete(ResultCode.NO_BIDS); assertEquals(DemandFetcher.STATE.RUNNING, FieldUtils.readField(demandFetcher, "state", true)); bundle = request.getCustomTargeting(); assertEquals(0, bundle.size()); }
Example 16
Source File: GooglePlayDFPBanner.java From mobile-sdk-android with Apache License 2.0 | 4 votes |
private PublisherAdRequest buildRequest(DFBBannerSSParameters ssparm, TargetingParameters targetingParameters) { PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder(); if ((ssparm.test_device != null) && (ssparm.test_device.length() > 0)) { adListener.printToClog("test device " + ssparm.test_device); builder.addTestDevice(ssparm.test_device); } Bundle bundle = new Bundle(); if (!StringUtil.isEmpty(ssparm.secondPrice)) { try { double secondPriceCents = Double.parseDouble(ssparm.secondPrice) * 100; if (secondPriceCents >= 0) { String secondPriceString = "anhb_" + Math.round(secondPriceCents); builder.addCustomTargeting(SECOND_PRICE_KEY, secondPriceString); adListener.printToClog("second price " + secondPriceString); } } catch (NumberFormatException e) { adListener.printToClogError("While parsing secondPrice value: " + e.getMessage()); } } if (targetingParameters.getAge() != null) { bundle.putString("Age", targetingParameters.getAge()); } if (targetingParameters.getLocation() != null) { builder.setLocation(targetingParameters.getLocation()); } for (Pair<String, String> p : targetingParameters.getCustomKeywords()) { if (p.first.equals("content_url")) { if (!StringUtil.isEmpty(p.second)) { builder.setContentUrl(p.second); } } else { bundle.putString(p.first, p.second); } } //Since AdMobExtras is deprecated so we need to use below method builder.addNetworkExtrasBundle(com.google.ads.mediation.admob.AdMobAdapter.class, bundle); return builder.build(); }