Search in sources :

Example 6 with AdUnit

use of org.prebid.mobile.AdUnit in project prebid-mobile-android by prebid.

the class ExtraTests method testSameConfigIdOnDifferentAdObjects.

@Test
public void testSameConfigIdOnDifferentAdObjects() throws Exception {
    final ArrayList<AdUnit> adUnits = new ArrayList<AdUnit>();
    final ArrayList<OnCompleteListener> spies = new ArrayList<>();
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("bfa84af2-bd16-4d35-96ad-31c6bb888df0");
    PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
    PrebidMobile.setShareGeoLocation(true);
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            final MoPubView adObject1 = new MoPubView(m.getActivity());
            adObject1.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_320x50_APPNEXUS);
            adObject1.setMinimumWidth(320);
            adObject1.setMinimumHeight(50);
            BannerAdUnit adUnit1 = new BannerAdUnit(Constants.PBS_CONFIG_ID_320x50_APPNEXUS, 320, 50);
            adUnits.add(adUnit1);
            OnCompleteListener l1 = new OnCompleteListener() {

                @Override
                public void onComplete(ResultCode resultCode) {
                    assertTrue(adObject1.getKeywords().contains("hb_pb:0.50"));
                    assertTrue(adObject1.getKeywords().contains("hb_cache_id:"));
                    FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
                    adFrame.addView(adObject1);
                    adObject1.loadAd();
                }
            };
            l1 = spy(l1);
            spies.add(l1);
            adUnit1.fetchDemand(adObject1, l1);
            AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
            final AdManagerAdRequest adObject2 = builder.build();
            BannerAdUnit adUnit2 = new BannerAdUnit(Constants.PBS_CONFIG_ID_320x50_APPNEXUS, 320, 50);
            adUnits.add(adUnit2);
            OnCompleteListener l2 = new OnCompleteListener() {

                @Override
                public void onComplete(ResultCode resultCode) {
                    assertEquals(10, adObject2.getCustomTargeting().size());
                    assertTrue(adObject2.getCustomTargeting().keySet().contains("hb_pb"));
                    assertTrue(adObject2.getCustomTargeting().keySet().contains("hb_cache_id"));
                    assertEquals("0.50", adObject2.getCustomTargeting().getString("hb_pb"));
                    FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
                    AdManagerAdView adView = new AdManagerAdView(m.getActivity());
                    adView.setAdSizes(AdSize.BANNER);
                    adView.setAdUnitId(Constants.DFP_BANNER_ADUNIT_ID_ALL_SIZES_APPNEXUS);
                    adFrame.addView(adView);
                    adView.setId(1);
                    adView.loadAd(adObject2);
                }
            };
            l2 = spy(l2);
            spies.add(l2);
            adUnit1.fetchDemand(adObject2, l2);
        }
    });
    Thread.sleep(10000);
    verify(spies.get(0), times(1)).onComplete(ResultCode.SUCCESS);
    verify(spies.get(1), times(1)).onComplete(ResultCode.SUCCESS);
}
Also used : ArrayList(java.util.ArrayList) BannerAdUnit(org.prebid.mobile.BannerAdUnit) OnCompleteListener(org.prebid.mobile.OnCompleteListener) BannerAdUnit(org.prebid.mobile.BannerAdUnit) AdUnit(org.prebid.mobile.AdUnit) InterstitialAdUnit(org.prebid.mobile.InterstitialAdUnit) AdManagerAdView(com.google.android.gms.ads.admanager.AdManagerAdView) FrameLayout(android.widget.FrameLayout) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView) Test(org.junit.Test)

Example 7 with AdUnit

use of org.prebid.mobile.AdUnit in project prebid-mobile-android by prebid.

the class AdManagerComplexTest method testFetchDemand.

@Test
public void testFetchDemand() throws Exception {
    final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
    fetchDemandHelper(0, new FetchDemandCompleteListener() {

        @Override
        public void preFetchDemand() {
        }

        @Override
        public void executeFetchDemand(AdUnit adUnit, final List<Map<String, String>> resultList) {
            adUnit.fetchDemand(builder, new OnCompleteListener() {

                @Override
                public void onComplete(ResultCode resultCode) {
                    Bundle customTargetingBundle = builder.build().getCustomTargeting();
                    Map<String, String> map = new HashMap<>(customTargetingBundle.keySet().size());
                    for (String key : customTargetingBundle.keySet()) {
                        map.put(key, customTargetingBundle.get(key).toString());
                    }
                    resultList.add(map);
                }
            });
        }

        @Override
        public void postFetchDemand(List<Map<String, String>> resultList) {
        }
    });
}
Also used : HashMap(java.util.HashMap) Bundle(android.os.Bundle) OnCompleteListener(org.prebid.mobile.OnCompleteListener) BannerAdUnit(org.prebid.mobile.BannerAdUnit) AdUnit(org.prebid.mobile.AdUnit) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) HashMap(java.util.HashMap) Map(java.util.Map) ResultCode(org.prebid.mobile.ResultCode) Test(org.junit.Test)

Example 8 with AdUnit

use of org.prebid.mobile.AdUnit in project prebid-mobile-android by prebid.

the class AdManagerComplexTest method testFetchDemandAutoRefresh.

@Test
public void testFetchDemandAutoRefresh() throws Exception {
    final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
    final IntegerWrapper requestCountWrapper = new IntegerWrapper();
    fetchDemandHelper(31_000, new FetchDemandCompleteListener() {

        @Override
        public void preFetchDemand() {
            mockServer.enqueue(new MockResponse().setResponseCode(200).setBody("{\n" + "  \"seatbid\": [\n" + "    {\n" + "      \"bid\": [\n" + "        {\n" + "          \"ext\": {\n" + "            \"prebid\": {\n" + "              \"targeting\": {\n" + "                \"hb_cache_id\": \"top_bid_1\",\n" + "                \"key1\": \"value1\"\n" + "              }\n" + "            }\n" + "          }\n" + "        }\n" + "      ]\n" + "    }\n" + "  ]\n" + "}"));
        }

        @Override
        public void executeFetchDemand(AdUnit adUnit, final List<Map<String, String>> resultList) {
            adUnit.fetchDemand(builder, new OnCompleteListener() {

                @Override
                public void onComplete(ResultCode resultCode) {
                    requestCountWrapper.value++;
                    AdManagerAdRequest adManagerAdRequest = builder.build();
                    Bundle customTargetingBundle = adManagerAdRequest.getCustomTargeting();
                    Map<String, String> map = new HashMap<>(customTargetingBundle.keySet().size());
                    for (String key : customTargetingBundle.keySet()) {
                        map.put(key, customTargetingBundle.get(key).toString());
                    }
                    resultList.add(map);
                }
            });
        }

        @Override
        public void postFetchDemand(List<Map<String, String>> resultList) {
            Map<String, String> result = resultList.get(1);
            assertEquals("top_bid_1", result.get("hb_cache_id"));
            assertEquals("value1", result.get("key1"));
        }
    });
    assertEquals(2, requestCountWrapper.value);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) HashMap(java.util.HashMap) Bundle(android.os.Bundle) OnCompleteListener(org.prebid.mobile.OnCompleteListener) BannerAdUnit(org.prebid.mobile.BannerAdUnit) AdUnit(org.prebid.mobile.AdUnit) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) HashMap(java.util.HashMap) Map(java.util.Map) ResultCode(org.prebid.mobile.ResultCode) Test(org.junit.Test)

Example 9 with AdUnit

use of org.prebid.mobile.AdUnit in project prebid-mobile-android by prebid.

the class AdManagerComplexTest method fetchDemandHelper.

public void fetchDemandHelper(int autoRefreshMillis, FetchDemandCompleteListener listener) throws Exception {
    // given
    PrebidMobile.setPrebidServerHost(Host.CUSTOM);
    HttpUrl httpUrl = mockServer.url("/fetchDemandHelper");
    Host.CUSTOM.setHostUrl(httpUrl.toString());
    PrebidMobile.setPrebidServerAccountId("1001");
    mockServer.enqueue(new MockResponse().setResponseCode(200).setBody("{\n" + "  \"seatbid\": [\n" + "    {\n" + "      \"bid\": [\n" + "        {\n" + "          \"ext\": {\n" + "            \"prebid\": {\n" + "              \"targeting\": {\n" + "                \"hb_env\": \"mobile-app\",\n" + "                \"hb_cache_hostpath\": \"https://prebid-cache-europe.rubiconproject.com/cache\",\n" + "                \"hb_size_rubicon\": \"300x250\",\n" + "                \"hb_cache_id\": \"a2f41588-4727-425c-9ef0-3b382debef1e\",\n" + "                \"hb_cache_path_rubicon\": \"/cache\",\n" + "                \"hb_cache_host_rubicon\": \"prebid-cache-europe.rubiconproject.com\",\n" + "                \"hb_pb\": \"1.20\",\n" + "                \"hb_pb_rubicon\": \"1.20\",\n" + "                \"hb_cache_id_rubicon\": \"a2f41588-4727-425c-9ef0-3b382debef1e\",\n" + "                \"hb_cache_path\": \"/cache\",\n" + "                \"hb_size\": \"300x250\",\n" + "                \"hb_cache_hostpath_rubicon\": \"https://prebid-cache-europe.rubiconproject.com/cache\",\n" + "                \"hb_env_rubicon\": \"mobile-app\",\n" + "                \"hb_bidder\": \"rubicon\",\n" + "                \"hb_bidder_rubicon\": \"rubicon\",\n" + "                \"hb_cache_host\": \"prebid-cache-europe.rubiconproject.com\"\n" + "              }\n" + "            }\n" + "          }\n" + "        }\n" + "      ]\n" + "    }\n" + "  ]\n" + "}"));
    listener.preFetchDemand();
    final List<Map<String, String>> resultList = new ArrayList<>();
    // when
    AdUnit adUnit = new BannerAdUnit("1001-1", 300, 250);
    adUnit.setAutoRefreshPeriodMillis(autoRefreshMillis);
    listener.executeFetchDemand(adUnit, resultList);
    try {
        Thread.sleep(autoRefreshMillis + 1_000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    // then
    Map<String, String> map = resultList.get(0);
    assertEquals("mobile-app", map.get("hb_env"));
    assertEquals("https://prebid-cache-europe.rubiconproject.com/cache", map.get("hb_cache_hostpath"));
    assertEquals("300x250", map.get("hb_size_rubicon"));
    assertEquals("a2f41588-4727-425c-9ef0-3b382debef1e", map.get("hb_cache_id"));
    assertEquals("/cache", map.get("hb_cache_path_rubicon"));
    assertEquals("prebid-cache-europe.rubiconproject.com", map.get("hb_cache_host_rubicon"));
    assertEquals("1.20", map.get("hb_pb"));
    assertEquals("1.20", map.get("hb_pb_rubicon"));
    assertEquals("a2f41588-4727-425c-9ef0-3b382debef1e", map.get("hb_cache_id_rubicon"));
    assertEquals("/cache", map.get("hb_cache_path"));
    assertEquals("300x250", map.get("hb_size"));
    assertEquals("https://prebid-cache-europe.rubiconproject.com/cache", map.get("hb_cache_hostpath_rubicon"));
    assertEquals("mobile-app", map.get("hb_env_rubicon"));
    assertEquals("rubicon", map.get("hb_bidder"));
    assertEquals("rubicon", map.get("hb_bidder_rubicon"));
    assertEquals("prebid-cache-europe.rubiconproject.com", map.get("hb_cache_host"));
    listener.postFetchDemand(resultList);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) BannerAdUnit(org.prebid.mobile.BannerAdUnit) AdUnit(org.prebid.mobile.AdUnit) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) HttpUrl(okhttp3.HttpUrl) BannerAdUnit(org.prebid.mobile.BannerAdUnit)

Example 10 with AdUnit

use of org.prebid.mobile.AdUnit in project prebid-mobile-android by prebid.

the class AdManagerComplexTest method testAdManagerAdRequestBuilderUseCase.

@Test
public void testAdManagerAdRequestBuilderUseCase() throws Exception {
    // given
    mockServer.enqueue(new MockResponse().setResponseCode(200).setBody("{\n" + "  \"seatbid\": [\n" + "    {\n" + "      \"bid\": [\n" + "        {\n" + "          \"ext\": {\n" + "            \"prebid\": {\n" + "              \"targeting\": {\n" + "                \"hb_cache_id\": \"top_bid_1\",\n" + "                \"key1\": \"value1\"\n" + "              }\n" + "            }\n" + "          }\n" + "        }\n" + "      ]\n" + "    }\n" + "  ]\n" + "}"));
    // important line
    PrebidMobile.setPrebidServerHost(Host.CUSTOM);
    HttpUrl httpUrl = mockServer.url("/testAdManagerAdRequestBuilderUseCase");
    Host.CUSTOM.setHostUrl(httpUrl.toString());
    PrebidMobile.setPrebidServerAccountId("1001");
    final ReferenceWrapper<Bundle> customTargetingBundleWrapper1 = new ReferenceWrapper<>();
    // when
    final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
    AdUnit adUnit = new BannerAdUnit("1001-1", 300, 250);
    adUnit.fetchDemand(builder, new OnCompleteListener() {

        @Override
        public void onComplete(ResultCode resultCode) {
            builder.addCustomTargeting("key2", "value2");
            AdManagerAdRequest adManagerAdRequest = builder.build();
            Bundle customTargetingBundle = adManagerAdRequest.getCustomTargeting();
            customTargetingBundleWrapper1.value = (Bundle) customTargetingBundle.clone();
        }
    });
    try {
        Thread.sleep(1_000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    // then
    Bundle customTargetingBundle = customTargetingBundleWrapper1.value;
    assertEquals(3, customTargetingBundle.keySet().size());
    assertEquals("top_bid_1", customTargetingBundle.getString("hb_cache_id"));
    assertEquals("value1", customTargetingBundle.getString("key1"));
    assertEquals("value2", customTargetingBundle.getString("key2"));
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Bundle(android.os.Bundle) HttpUrl(okhttp3.HttpUrl) BannerAdUnit(org.prebid.mobile.BannerAdUnit) OnCompleteListener(org.prebid.mobile.OnCompleteListener) BannerAdUnit(org.prebid.mobile.BannerAdUnit) AdUnit(org.prebid.mobile.AdUnit) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) ResultCode(org.prebid.mobile.ResultCode) Test(org.junit.Test)

Aggregations

AdUnit (org.prebid.mobile.AdUnit)10 BannerAdUnit (org.prebid.mobile.BannerAdUnit)9 Test (org.junit.Test)7 ResultCode (org.prebid.mobile.ResultCode)7 OnCompleteListener (org.prebid.mobile.OnCompleteListener)6 InterstitialAdUnit (org.prebid.mobile.InterstitialAdUnit)5 AdManagerAdRequest (com.google.android.gms.ads.admanager.AdManagerAdRequest)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 MockResponse (okhttp3.mockwebserver.MockResponse)4 Bundle (android.os.Bundle)3 FrameLayout (android.widget.FrameLayout)3 MoPubView (com.mopub.mobileads.MoPubView)3 HttpUrl (okhttp3.HttpUrl)2 AdSize (org.prebid.mobile.drprebid.model.AdSize)2 Point (android.graphics.Point)1 Display (android.view.Display)1 AdManagerAdView (com.google.android.gms.ads.admanager.AdManagerAdView)1 MoPubInterstitial (com.mopub.mobileads.MoPubInterstitial)1