com.mopub.mobileads.MoPubView Java Examples

The following examples show how to use com.mopub.mobileads.MoPubView. 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: ResultCodeTest.java    From prebid-mobile-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoBidsRubicon() throws Exception {
    HttpUrl httpUrl = server.url("/");
    Host.CUSTOM.setHostUrl(httpUrl.toString());
    PrebidMobile.setPrebidServerHost(Host.CUSTOM);
    PrebidMobile.setApplicationContext(activity.getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("123456");
    server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.noBidFromRubicon()));
    BannerAdUnit adUnit = new BannerAdUnit("123456", 300, 250);
    MoPubView testView = new MoPubView(activity);
    OnCompleteListener mockListener = mock(OnCompleteListener.class);
    adUnit.fetchDemand(testView, mockListener);
    DemandFetcher fetcher = (DemandFetcher) FieldUtils.readField(adUnit, "fetcher", true);
    PrebidMobile.setTimeoutMillis(Integer.MAX_VALUE);
    ShadowLooper fetcherLooper = shadowOf(fetcher.getHandler().getLooper());
    fetcherLooper.runOneTask();
    ShadowLooper demandLooper = shadowOf(fetcher.getDemandHandler().getLooper());
    demandLooper.runOneTask();
    Robolectric.flushBackgroundThreadScheduler();
    Robolectric.flushForegroundThreadScheduler();
    verify(mockListener).onComplete(ResultCode.NO_BIDS);

    assertNull(testView.getKeywords());
}
 
Example #2
Source File: ResultCodeTest.java    From prebid-mobile-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoBids() throws Exception {
    HttpUrl httpUrl = server.url("/");
    Host.CUSTOM.setHostUrl(httpUrl.toString());
    PrebidMobile.setPrebidServerHost(Host.CUSTOM);
    PrebidMobile.setApplicationContext(activity.getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("123456");
    server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.noBid()));
    BannerAdUnit adUnit = new BannerAdUnit("123456", 300, 250);
    MoPubView testView = new MoPubView(activity);
    OnCompleteListener mockListener = mock(OnCompleteListener.class);
    adUnit.fetchDemand(testView, mockListener);
    DemandFetcher fetcher = (DemandFetcher) FieldUtils.readField(adUnit, "fetcher", true);
    PrebidMobile.setTimeoutMillis(Integer.MAX_VALUE);
    ShadowLooper fetcherLooper = shadowOf(fetcher.getHandler().getLooper());
    fetcherLooper.runOneTask();
    ShadowLooper demandLooper = shadowOf(fetcher.getDemandHandler().getLooper());
    demandLooper.runOneTask();
    Robolectric.flushBackgroundThreadScheduler();
    Robolectric.flushForegroundThreadScheduler();
    verify(mockListener).onComplete(ResultCode.NO_BIDS);
    assertEquals(null, testView.getKeywords());
}
 
Example #3
Source File: ResultCodeTest.java    From prebid-mobile-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testSuccessForMoPub() throws Exception {

    HttpUrl httpUrl = server.url("/");
    Host.CUSTOM.setHostUrl(httpUrl.toString());
    PrebidMobile.setPrebidServerHost(Host.CUSTOM);
    PrebidMobile.setApplicationContext(activity.getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("123456");
    server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.oneBidFromAppNexus()));
    BannerAdUnit adUnit = new BannerAdUnit("123456", 300, 250);
    MoPubView testView = new MoPubView(activity);
    OnCompleteListener mockListener = mock(OnCompleteListener.class);
    adUnit.fetchDemand(testView, mockListener);
    DemandFetcher fetcher = (DemandFetcher) FieldUtils.readField(adUnit, "fetcher", true);
    PrebidMobile.setTimeoutMillis(Integer.MAX_VALUE);
    ShadowLooper fetcherLooper = shadowOf(fetcher.getHandler().getLooper());
    fetcherLooper.runOneTask();
    ShadowLooper demandLooper = shadowOf(fetcher.getDemandHandler().getLooper());
    demandLooper.runOneTask();
    Robolectric.flushBackgroundThreadScheduler();
    Robolectric.flushForegroundThreadScheduler();
    verify(mockListener).onComplete(ResultCode.SUCCESS);
    assertEquals("hb_pb:0.50,hb_env:mobile-app,hb_pb_appnexus:0.50,hb_size:300x250,hb_bidder_appnexus:appnexus,hb_bidder:appnexus,hb_cache_id:df4aba04-5e69-44b8-8608-058ab21600b8,hb_env_appnexus:mobile-app,hb_size_appnexus:300x250,hb_cache_id_appnexus:df4aba04-5e69-44b8-8608-058ab21600b8,", testView.getKeywords());

}
 
Example #4
Source File: ResultCodeTest.java    From prebid-mobile-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidContext() throws Exception {

    HttpUrl httpUrl = server.url("/");
    Host.CUSTOM.setHostUrl(httpUrl.toString());
    PrebidMobile.setPrebidServerHost(Host.CUSTOM);
    PrebidMobile.setPrebidServerAccountId("123456");
    PrebidMobile.setApplicationContext(null);
    server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.oneBidFromAppNexus()));
    InterstitialAdUnit adUnit = new InterstitialAdUnit("123456");
    MoPubView testView = new MoPubView(activity);
    OnCompleteListener mockListener = mock(OnCompleteListener.class);
    adUnit.fetchDemand(testView, mockListener);
    verify(mockListener).onComplete(ResultCode.INVALID_CONTEXT);

}
 
Example #5
Source File: UtilTest.java    From prebid-mobile-android with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #6
Source File: MoPubBannerAdView.java    From mobile-sdk-android with Apache License 2.0 6 votes vote down vote up
@Override
public View requestAd(MediatedBannerAdViewController mBC, Activity activity, String parameter, String uid,
                      int width, int height, TargetingParameters targetingParameters) {
    mpListener = new MoPubListener(mBC, this.getClass().getSimpleName());
    adView = new MoPubView(activity);
    adView.setAdUnitId(uid);
    adView.setBannerAdListener(mpListener);
    adView.setAutorefreshEnabled(false);

    if (targetingParameters != null) {
        if (targetingParameters.getLocation() != null) {
            adView.setLocation(targetingParameters.getLocation());
        }

        String keywords = MoPubListener.keywordsFromTargetingParameters(targetingParameters);
        adView.setKeywords(keywords);
    }

    adView.setMinimumWidth(width);
    adView.setMinimumHeight(height);
    adView.loadAd(MoPubView.MoPubAdSize.valueOf(height));
    return adView;
}
 
Example #7
Source File: DemoActivity.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
void setupMPBanner(String adUnitId, int width, int height) {
    FrameLayout adFrame = findViewById(R.id.adFrame);
    adFrame.removeAllViews();
    adView = new MoPubView(this);
    adView.setAdUnitId(adUnitId);

    adView.setMinimumWidth(width);
    adView.setMinimumHeight(height);
    adFrame.addView(adView);
}
 
Example #8
Source File: MoPubAdapter.java    From googleads-mobile-android-mediation with Apache License 2.0 5 votes vote down vote up
@Override
public void onBannerFailed(MoPubView moPubView, MoPubErrorCode moPubErrorCode) {
  String errorSDKMessage = createSDKError(moPubErrorCode);
  Log.w(TAG, errorSDKMessage);
  mMediationBannerListener
      .onAdFailedToLoad(MoPubAdapter.this, getMediationErrorCode(moPubErrorCode));
}
 
Example #9
Source File: DemandFetcherTest.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleRequestOneBidRubiconResponseForMoPubAdObject() 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()));
    MoPubView adView = new MoPubView(activity);
    adView.setAdUnitId("123456789");
    DemandFetcher demandFetcher = new DemandFetcher(adView);
    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));
    String adViewKeywords = adView.getKeywords();
    assertEquals("hb_env:mobile-app,hb_cache_hostpath:https://prebid-cache-europe.rubiconproject.com/cache,hb_size_rubicon:300x250,hb_cache_id:a2f41588-4727-425c-9ef0-3b382debef1e,hb_cache_path_rubicon:/cache,hb_cache_host_rubicon:prebid-cache-europe.rubiconproject.com,hb_pb:1.20,hb_pb_rubicon:1.20,hb_cache_id_rubicon:a2f41588-4727-425c-9ef0-3b382debef1e,hb_cache_path:/cache,hb_size:300x250,hb_cache_hostpath_rubicon:https://prebid-cache-europe.rubiconproject.com/cache,hb_env_rubicon:mobile-app,hb_bidder:rubicon,hb_bidder_rubicon:rubicon,hb_cache_host:prebid-cache-europe.rubiconproject.com,", adViewKeywords);
}
 
Example #10
Source File: DemandFetcherTest.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleRequestOneBidResponseForMoPubAdObject() 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()));
    MoPubView adView = new MoPubView(activity);
    adView.setAdUnitId("123456789");
    DemandFetcher demandFetcher = new DemandFetcher(adView);
    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));
    String adViewKeywords = adView.getKeywords();
    assertEquals("hb_pb:0.50,hb_env:mobile-app,hb_pb_appnexus:0.50,hb_size:300x250,hb_bidder_appnexus:appnexus,hb_bidder:appnexus,hb_cache_id:df4aba04-5e69-44b8-8608-058ab21600b8,hb_env_appnexus:mobile-app,hb_size_appnexus:300x250,hb_cache_id_appnexus:df4aba04-5e69-44b8-8608-058ab21600b8,", adViewKeywords);
}
 
Example #11
Source File: ResultCodeTest.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoNegativeSizeForBanner() {
    PrebidMobile.setPrebidServerAccountId("123456");
    BannerAdUnit adUnit = new BannerAdUnit("123456", 320, 50);
    adUnit.addAdditionalSize(-1, 250);
    MoPubView testView = new MoPubView(activity);
    OnCompleteListener mockListener = mock(OnCompleteListener.class);
    adUnit.fetchDemand(testView, mockListener);
    verify(mockListener).onComplete(ResultCode.INVALID_SIZE);
}
 
Example #12
Source File: ResultCodeTest.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyHostUrl() throws Exception {
    PrebidMobile.setPrebidServerAccountId("123456");
    Host.CUSTOM.setHostUrl("");
    PrebidMobile.setPrebidServerHost(Host.CUSTOM);
    BannerAdUnit adUnit = new BannerAdUnit("123456", 320, 50);
    MoPubView testView = new MoPubView(activity);
    OnCompleteListener mockListener = mock(OnCompleteListener.class);
    adUnit.fetchDemand(testView, mockListener);
    verify(mockListener).onComplete(ResultCode.INVALID_HOST_URL);
}
 
Example #13
Source File: ResultCodeTest.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyConfigId() throws Exception {
    PrebidMobile.setPrebidServerAccountId("123456");
    BannerAdUnit adUnit = new BannerAdUnit("", 320, 50);
    MoPubView testView = new MoPubView(activity);
    OnCompleteListener mockListener = mock(OnCompleteListener.class);
    adUnit.fetchDemand(testView, mockListener);
    verify(mockListener).onComplete(ResultCode.INVALID_CONFIG_ID);
}
 
Example #14
Source File: ResultCodeTest.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyAccountId() throws Exception {
    PrebidMobile.setPrebidServerAccountId("");
    BannerAdUnit adUnit = new BannerAdUnit("123456", 320, 50);
    MoPubView testView = new MoPubView(activity);
    OnCompleteListener mockListener = mock(OnCompleteListener.class);
    adUnit.fetchDemand(testView, mockListener);
    verify(mockListener).onComplete(ResultCode.INVALID_ACCOUNT_ID);
}
 
Example #15
Source File: ResultCodeTest.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testNetworkError() {
    PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
    PrebidMobile.setApplicationContext(activity.getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("123456");
    ConnectivityManager connectivityManager = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
    ShadowNetworkInfo shadowOfActiveNetworkInfo = shadowOf(connectivityManager.getActiveNetworkInfo());
    shadowOfActiveNetworkInfo.setConnectionStatus(false);
    BannerAdUnit adUnit = new BannerAdUnit("123456", 300, 250);
    MoPubView testView = new MoPubView(activity);
    OnCompleteListener mockListener = mock(OnCompleteListener.class);
    adUnit.fetchDemand(testView, mockListener);
    verify(mockListener).onComplete(ResultCode.NETWORK_ERROR);
}
 
Example #16
Source File: UtilTest.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testSupportedAdObject() throws Exception {
    MoPubView testView = new MoPubView(activity);
    assertTrue(Util.supportedAdObject(testView));
    assertFalse(Util.supportedAdObject(null));
    MoPubInterstitial interstitial = new MoPubInterstitial(activity, "");
    assertTrue(Util.supportedAdObject(interstitial));
    PublisherAdRequest request = new PublisherAdRequest.Builder().build();
    assertTrue(Util.supportedAdObject(request));
    Object object = new Object();
    assertFalse(Util.supportedAdObject(object));
}
 
Example #17
Source File: ExtraTests.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testRubiconInvalidPrebidServerConfigId() throws Exception {
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("1001");
    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_ERROR", 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_CONFIG_ID);
}
 
Example #18
Source File: ExtraTests.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testAppNexusInvalidPrebidServerConfigId() 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("6ace8c7d-88c0-4623-8117-ffffffffffff", 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.INVALID_CONFIG_ID);
}
 
Example #19
Source File: ExtraTests.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testRubiconEmptyInvalidPrebidServerConfigId() throws Exception {
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("1001");
    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("", 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_CONFIG_ID);
}
 
Example #20
Source File: ExtraTests.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyInvalidPrebidServerConfigId() 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("", 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_CONFIG_ID);
}
 
Example #21
Source File: ExtraTests.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #22
Source File: ExtraTests.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testAppNexusInvalidPrebidServerAccountId() throws Exception {
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("bfa84af2-bd16-4d35-96ad-ffffffffffff");
    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("6ace8c7d-88c0-4623-8117-75bc3f0a2e45", 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.INVALID_ACCOUNT_ID);
}
 
Example #23
Source File: ExtraTests.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testRubiconEmptyInvalidPrebidServerAccountId() throws Exception {
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("");
    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);
}
 
Example #24
Source File: ExtraTests.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #25
Source File: ExtraTests.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testAppNexusKeyValueTargeting2() 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);
            adUnit.addUserKeyword("pbm_key", "pbm_value2");
            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.NO_BIDS);
    onView(withId(R.id.adFrame)).check(matches(isDisplayed()));
    onWebView().check(webMatches(getCurrentUrl(), containsString("ads.mopub.com")));
    onWebView().check(webContent(containingTextInBody("Hello, I'm not a Prebid ad.")));
}
 
Example #26
Source File: ExtraTests.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@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);
            adUnit.addUserKeyword("pbm_key", "pbm_value1");
            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")));
}
 
Example #27
Source File: ExtraTests.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testRubiconDemand() throws Exception {
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("1001");
    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_APPNEXUS);
            adObject.setMinimumHeight(250);
            adObject.setMinimumWidth(300);
            BannerAdUnit adUnit = new BannerAdUnit("1001-2", 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")));
}
 
Example #28
Source File: MoPubAdapter.java    From googleads-mobile-android-mediation with Apache License 2.0 4 votes vote down vote up
@Override
public void requestBannerAd(final Context context,
    MediationBannerListener mediationBannerListener,
    Bundle bundle,
    final AdSize adSize,
    MediationAdRequest mediationAdRequest,
    final Bundle mediationExtras) {
  mContext = context;
  mAdSize = adSize;
  mExtras = mediationExtras;

  String adUnit = bundle.getString(MOPUB_AD_UNIT_KEY);
  if (TextUtils.isEmpty(adUnit)) {
    String errorMessage = createAdapterError(ERROR_INVALID_SERVER_PARAMETERS,
        "Missing or Invalid MoPub Ad Unit ID.");
    Log.w(TAG, errorMessage);
    mediationBannerListener.onAdFailedToLoad(MoPubAdapter.this,
        ERROR_INVALID_SERVER_PARAMETERS);
    return;
  }

  mMoPubView = new MoPubView(context);
  mMoPubView.setBannerAdListener(new MBannerListener(mediationBannerListener));
  mMoPubView.setAdUnitId(adUnit);

  //If test mode is enabled
  if (mediationAdRequest.isTesting()) {
    mMoPubView.setTesting(true);
  }

  //If location is available
  if (mediationAdRequest.getLocation() != null) {
    mMoPubView.setLocation(mediationAdRequest.getLocation());
  }

  mMoPubView.setKeywords(getKeywords(mediationAdRequest, false));
  mMoPubView.setUserDataKeywords(getKeywords(mediationAdRequest, true));

  SdkConfiguration sdkConfiguration = new SdkConfiguration.Builder(adUnit).build();
  MoPubSingleton.getInstance().initializeMoPubSDK(context, sdkConfiguration,
      new SdkInitializationListener() {
        @Override
        public void onInitializationFinished() {
          mMoPubView.loadAd();
        }
      });
}
 
Example #29
Source File: MoPubBannerAdListener.java    From aptoide-client-v8 with GNU General Public License v3.0 4 votes vote down vote up
@Override public void onBannerLoaded(MoPubView banner) {
  banner.setVisibility(VISIBLE);
  Logger.getInstance()
      .d("Mopub", "Banner loaded");
}
 
Example #30
Source File: MoPubBannerAdListener.java    From aptoide-client-v8 with GNU General Public License v3.0 4 votes vote down vote up
@Override public void onBannerCollapsed(MoPubView banner) {
  Logger.getInstance()
      .d("Mopub", "Banner collapsed");
}