Search in sources :

Example 16 with MoPubView

use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.

the class UtilTest method testApplyBidsToMoPubAdobject.

@Test
public void testApplyBidsToMoPubAdobject() throws Exception {
    MoPubView adView = new MoPubView(activity);
    adView.setKeywords("key1:value1,key2:value2");
    HashMap<String, String> bids = new HashMap<>();
    bids.put("hb_pb", "0.50");
    bids.put("hb_cache_id", "123456");
    Util.apply(bids, adView);
    String adViewKeywords = adView.getKeywords();
    assertEquals("hb_pb:0.50,hb_cache_id:123456,key1:value1,key2:value2", adViewKeywords);
    Util.apply(null, adView);
    assertEquals("key1:value1,key2:value2", adView.getKeywords());
    MoPubInterstitial instl = new MoPubInterstitial(activity, "123456");
    instl.setKeywords("key1:value1,key2:value2");
    Util.apply(bids, instl);
    assertEquals("hb_pb:0.50,hb_cache_id:123456,key1:value1,key2:value2", instl.getKeywords());
    Util.apply(null, instl);
    assertEquals("key1:value1,key2:value2", instl.getKeywords());
}
Also used : MoPubInterstitial(com.mopub.mobileads.MoPubInterstitial) HashMap(java.util.HashMap) MoPubView(com.mopub.mobileads.MoPubView) Test(org.junit.Test)

Example 17 with MoPubView

use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.

the class ExtraTests method testAppNexusKeyValueTargeting.

@Test
public void testAppNexusKeyValueTargeting() throws Exception {
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("bfa84af2-bd16-4d35-96ad-31c6bb888df0");
    PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
    PrebidMobile.setShareGeoLocation(true);
    final OnCompleteListener[] listener = new OnCompleteListener[1];
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            final MoPubView adObject = new MoPubView(m.getActivity());
            adObject.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_300x250_APPNEXUS);
            adObject.setMinimumHeight(250);
            adObject.setMinimumWidth(300);
            BannerAdUnit adUnit = new BannerAdUnit("67bac530-9832-4f78-8c94-fbf88ac7bd14", 300, 250);
            OnCompleteListener l = new OnCompleteListener() {

                @Override
                public void onComplete(ResultCode resultCode) {
                    FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
                    adFrame.addView(adObject);
                    adObject.loadAd();
                }
            };
            listener[0] = spy(l);
            adUnit.fetchDemand(adObject, listener[0]);
        }
    });
    Thread.sleep(10000);
    verify(listener[0], times(1)).onComplete(ResultCode.SUCCESS);
    onView(withId(R.id.adFrame)).check(matches(isDisplayed()));
    onWebView().check(webMatches(getCurrentUrl(), containsString("ads.mopub.com")));
    onWebView().check(webContent(containingTextInBody("ucTag.renderAd")));
}
Also used : OnCompleteListener(org.prebid.mobile.OnCompleteListener) FrameLayout(android.widget.FrameLayout) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView) BannerAdUnit(org.prebid.mobile.BannerAdUnit) Test(org.junit.Test)

Example 18 with MoPubView

use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.

the class ExtraTests method testEmptyInvalidPrebidServerAccountId.

@Test
public void testEmptyInvalidPrebidServerAccountId() throws Exception {
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("");
    PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
    PrebidMobile.setShareGeoLocation(true);
    final OnCompleteListener[] listener = new OnCompleteListener[1];
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            final MoPubView adObject = new MoPubView(m.getActivity());
            adObject.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_300x250_APPNEXUS);
            adObject.setMinimumHeight(250);
            adObject.setMinimumWidth(300);
            BannerAdUnit adUnit = new BannerAdUnit("67bac530-9832-4f78-8c94-fbf88ac7bd14", 300, 250);
            OnCompleteListener l = new OnCompleteListener() {

                @Override
                public void onComplete(ResultCode resultCode) {
                    FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
                    adFrame.addView(adObject);
                    adObject.loadAd();
                }
            };
            listener[0] = spy(l);
            adUnit.fetchDemand(adObject, listener[0]);
        }
    });
    Thread.sleep(1000);
    verify(listener[0], times(1)).onComplete(ResultCode.INVALID_ACCOUNT_ID);
}
Also used : OnCompleteListener(org.prebid.mobile.OnCompleteListener) FrameLayout(android.widget.FrameLayout) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView) BannerAdUnit(org.prebid.mobile.BannerAdUnit) Test(org.junit.Test)

Example 19 with MoPubView

use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.

the class ExtraTests method testRubiconInvalidPrebidServerAccountId.

@Test
public void testRubiconInvalidPrebidServerAccountId() throws Exception {
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("1001_ERROR");
    PrebidMobile.setPrebidServerHost(Host.RUBICON);
    PrebidMobile.setShareGeoLocation(true);
    final OnCompleteListener[] listener = new OnCompleteListener[1];
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            final MoPubView adObject = new MoPubView(m.getActivity());
            adObject.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_300x250_RUBICON);
            adObject.setMinimumHeight(250);
            adObject.setMinimumWidth(300);
            BannerAdUnit adUnit = new BannerAdUnit("1001-1", 300, 250);
            OnCompleteListener l = new OnCompleteListener() {

                @Override
                public void onComplete(ResultCode resultCode) {
                    FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
                    adFrame.addView(adObject);
                    adObject.loadAd();
                }
            };
            listener[0] = spy(l);
            adUnit.fetchDemand(adObject, listener[0]);
        }
    });
    Thread.sleep(2000);
    verify(listener[0], times(1)).onComplete(ResultCode.INVALID_ACCOUNT_ID);
}
Also used : OnCompleteListener(org.prebid.mobile.OnCompleteListener) FrameLayout(android.widget.FrameLayout) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView) BannerAdUnit(org.prebid.mobile.BannerAdUnit) Test(org.junit.Test)

Example 20 with MoPubView

use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.

the class ExtraTests method testMultipleDemand.

@Test
public void testMultipleDemand() 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 adObject = new MoPubView(m.getActivity());
            adObject.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_300x250_APPNEXUS);
            adObject.setMinimumWidth(300);
            adObject.setMinimumHeight(250);
            BannerAdUnit adUnit = new BannerAdUnit("1cfdfe39-18f2-45b9-964f-63d64cdc0399", 300, 250);
            adUnits.add(adUnit);
            OnCompleteListener l = new OnCompleteListener() {

                @Override
                public void onComplete(ResultCode resultCode) {
                    String keywords = adObject.getKeywords();
                    String[] keywordsArray = keywords.split(",");
                    assertEquals(15, keywordsArray.length);
                    assertTrue(keywords.contains("hb_pb:1.20"));
                    assertTrue(keywords.contains("hb_pb_rubicon:1.20"));
                    assertTrue(keywords.contains("hb_cache_id:"));
                    assertTrue(keywords.contains("hb_pb_appnexus:0.50"));
                    assertTrue(keywords.contains("hb_cache_id_appnexus:"));
                    FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
                    adFrame.addView(adObject);
                    adObject.loadAd();
                }
            };
            l = spy(l);
            spies.add(l);
            adUnit.fetchDemand(adObject, l);
        }
    });
    Thread.sleep(10000);
    verify(spies.get(0), times(1)).onComplete(ResultCode.SUCCESS);
    onWebView().check(webContent(containingTextInBody("ucTag.renderAd")));
}
Also used : OnCompleteListener(org.prebid.mobile.OnCompleteListener) BannerAdUnit(org.prebid.mobile.BannerAdUnit) AdUnit(org.prebid.mobile.AdUnit) InterstitialAdUnit(org.prebid.mobile.InterstitialAdUnit) FrameLayout(android.widget.FrameLayout) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView) BannerAdUnit(org.prebid.mobile.BannerAdUnit) Test(org.junit.Test)

Aggregations

MoPubView (com.mopub.mobileads.MoPubView)48 Test (org.junit.Test)38 FrameLayout (android.widget.FrameLayout)26 BannerAdUnit (org.prebid.mobile.BannerAdUnit)23 OnCompleteListener (org.prebid.mobile.OnCompleteListener)23 ResultCode (org.prebid.mobile.ResultCode)23 MockResponse (okhttp3.mockwebserver.MockResponse)15 HttpUrl (okhttp3.HttpUrl)8 Dispatcher (okhttp3.mockwebserver.Dispatcher)8 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)8 Matchers.containsString (org.hamcrest.Matchers.containsString)7 BackgroundThreadExecutor (org.prebid.mobile.tasksmanager.BackgroundThreadExecutor)7 ShadowLooper (org.robolectric.shadows.ShadowLooper)7 MoPubInterstitial (com.mopub.mobileads.MoPubInterstitial)5 JSONException (org.json.JSONException)5 ArrayList (java.util.ArrayList)4 JSONObject (org.json.JSONObject)4 AdUnit (org.prebid.mobile.AdUnit)4 InterstitialAdUnit (org.prebid.mobile.InterstitialAdUnit)4 MoPubErrorCode (com.mopub.mobileads.MoPubErrorCode)3