Search in sources :

Example 11 with MoPubView

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

the class ResultCodeTest method testSuccessForMoPub.

@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();
    ShadowLooper bgLooper = Shadows.shadowOf(((BackgroundThreadExecutor) TasksManager.getInstance().backgroundThreadExecutor).getBackgroundHandler().getLooper());
    bgLooper.runToEndOfTasks();
    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());
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) ShadowLooper(org.robolectric.shadows.ShadowLooper) BackgroundThreadExecutor(org.prebid.mobile.tasksmanager.BackgroundThreadExecutor) HttpUrl(okhttp3.HttpUrl) MoPubView(com.mopub.mobileads.MoPubView) Test(org.junit.Test)

Example 12 with MoPubView

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

the class ResultCodeTest method testEmptyConfigId.

@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);
}
Also used : MoPubView(com.mopub.mobileads.MoPubView) Test(org.junit.Test)

Example 13 with MoPubView

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

the class DemandFetcherTest method testAutoRefreshForMoPubAdObject.

@Test
public void testAutoRefreshForMoPubAdObject() 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("{}"));
    MoPubView adView = new MoPubView(activity);
    adView.setAdUnitId("123456789");
    DemandFetcher demandFetcher = new DemandFetcher(adView);
    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();
    ShadowLooper bgLooper = Shadows.shadowOf(((BackgroundThreadExecutor) TasksManager.getInstance().backgroundThreadExecutor).getBackgroundHandler().getLooper());
    bgLooper.runToEndOfTasks();
    Robolectric.flushBackgroundThreadScheduler();
    Robolectric.flushForegroundThreadScheduler();
    verify(mockListener).onComplete(ResultCode.SUCCESS);
    assertNotSame(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);
    fetcherLooper.runOneTask();
    demandLooper.runOneTask();
    bgLooper.runToEndOfTasks();
    Robolectric.flushBackgroundThreadScheduler();
    Robolectric.flushForegroundThreadScheduler();
    verify(mockListener).onComplete(ResultCode.NO_BIDS);
    assertNotSame(DemandFetcher.STATE.DESTROYED, FieldUtils.readField(demandFetcher, "state", true));
    adViewKeywords = adView.getKeywords();
    assertEquals("", adViewKeywords);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) ShadowLooper(org.robolectric.shadows.ShadowLooper) BackgroundThreadExecutor(org.prebid.mobile.tasksmanager.BackgroundThreadExecutor) HttpUrl(okhttp3.HttpUrl) MoPubView(com.mopub.mobileads.MoPubView) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with MoPubView

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

the class DemandFetcherTest method testSingleRequestOneBidResponseForMoPubAdObject.

@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();
    ShadowLooper bgLooper = Shadows.shadowOf(((BackgroundThreadExecutor) TasksManager.getInstance().backgroundThreadExecutor).getBackgroundHandler().getLooper());
    bgLooper.runToEndOfTasks();
    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);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) ShadowLooper(org.robolectric.shadows.ShadowLooper) BackgroundThreadExecutor(org.prebid.mobile.tasksmanager.BackgroundThreadExecutor) HttpUrl(okhttp3.HttpUrl) MoPubView(com.mopub.mobileads.MoPubView) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with MoPubView

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

the class DemandFetcherTest method testSingleRequestOneBidRubiconResponseForMoPubAdObject.

@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();
    ShadowLooper bgLooper = Shadows.shadowOf(((BackgroundThreadExecutor) TasksManager.getInstance().backgroundThreadExecutor).getBackgroundHandler().getLooper());
    bgLooper.runToEndOfTasks();
    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);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) ShadowLooper(org.robolectric.shadows.ShadowLooper) BackgroundThreadExecutor(org.prebid.mobile.tasksmanager.BackgroundThreadExecutor) HttpUrl(okhttp3.HttpUrl) MoPubView(com.mopub.mobileads.MoPubView) HashSet(java.util.HashSet) 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