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());
}
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);
}
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);
}
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);
}
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);
}
Aggregations