use of org.robolectric.shadows.ShadowLooper in project prebid-mobile-android by prebid.
the class PrebidServerAdapterTest method testNoBidRubiconResponse.
@Test
public void testNoBidRubiconResponse() {
server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.noBidFromRubicon()));
HttpUrl hostUrl = server.url("/");
Host.CUSTOM.setHostUrl(hostUrl.toString());
PrebidMobile.setPrebidServerHost(Host.CUSTOM);
PrebidMobile.setPrebidServerAccountId("12345");
PrebidMobile.setShareGeoLocation(true);
PrebidMobile.setApplicationContext(activity.getApplicationContext());
DemandAdapter.DemandAdapterListener mockListener = mock(DemandAdapter.DemandAdapterListener.class);
PrebidServerAdapter adapter = new PrebidServerAdapter();
HashSet<AdSize> sizes = new HashSet<>();
sizes.add(new AdSize(320, 50));
RequestParams requestParams = new RequestParams("67890", AdType.BANNER, sizes);
String uuid = UUID.randomUUID().toString();
adapter.requestDemand(requestParams, mockListener, uuid);
ShadowLooper bgLooper = Shadows.shadowOf(((BackgroundThreadExecutor) TasksManager.getInstance().backgroundThreadExecutor).getBackgroundHandler().getLooper());
bgLooper.runToEndOfTasks();
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
verify(mockListener).onDemandFailed(ResultCode.NO_BIDS, uuid);
}
use of org.robolectric.shadows.ShadowLooper in project prebid-mobile-android by prebid.
the class PrebidServerAdapterTest method testBlankResponseReturnsNoBid.
@Test
public void testBlankResponseReturnsNoBid() {
server.enqueue(new MockResponse().setResponseCode(204).setBody(""));
HttpUrl hostUrl = server.url("/");
Host.CUSTOM.setHostUrl(hostUrl.toString());
PrebidMobile.setPrebidServerHost(Host.CUSTOM);
PrebidMobile.setPrebidServerAccountId("12345");
PrebidMobile.setShareGeoLocation(true);
PrebidMobile.setApplicationContext(activity.getApplicationContext());
DemandAdapter.DemandAdapterListener mockListener = mock(DemandAdapter.DemandAdapterListener.class);
PrebidServerAdapter adapter = new PrebidServerAdapter();
HashSet<AdSize> sizes = new HashSet<>();
sizes.add(new AdSize(320, 50));
RequestParams requestParams = new RequestParams("67890", AdType.BANNER, sizes);
String uuid = UUID.randomUUID().toString();
adapter.requestDemand(requestParams, mockListener, uuid);
ShadowLooper bgLooper = Shadows.shadowOf(((BackgroundThreadExecutor) TasksManager.getInstance().backgroundThreadExecutor).getBackgroundHandler().getLooper());
bgLooper.runToEndOfTasks();
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
verify(mockListener).onDemandFailed(ResultCode.NO_BIDS, uuid);
}
use of org.robolectric.shadows.ShadowLooper in project prebid-mobile-android by prebid.
the class PrebidServerAdapterTest method testSuccessfulBidResponseWithoutCacheId3.
@Test
public void testSuccessfulBidResponseWithoutCacheId3() {
server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.invalidBidResponseTopBidNoCacheId()));
HttpUrl hostUrl = server.url("/");
Host.CUSTOM.setHostUrl(hostUrl.toString());
PrebidMobile.setPrebidServerHost(Host.CUSTOM);
PrebidMobile.setPrebidServerAccountId("12345");
PrebidMobile.setShareGeoLocation(true);
PrebidMobile.setApplicationContext(activity.getApplicationContext());
DemandAdapter.DemandAdapterListener mockListener = mock(DemandAdapter.DemandAdapterListener.class);
PrebidServerAdapter adapter = new PrebidServerAdapter();
HashSet<AdSize> sizes = new HashSet<>();
sizes.add(new AdSize(300, 250));
RequestParams requestParams = new RequestParams("67890", AdType.BANNER, sizes);
String uuid = UUID.randomUUID().toString();
adapter.requestDemand(requestParams, mockListener, uuid);
ShadowLooper bgLooper = Shadows.shadowOf(((BackgroundThreadExecutor) TasksManager.getInstance().backgroundThreadExecutor).getBackgroundHandler().getLooper());
bgLooper.runToEndOfTasks();
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
verify(mockListener).onDemandFailed(ResultCode.NO_BIDS, uuid);
}
use of org.robolectric.shadows.ShadowLooper in project prebid-mobile-android by prebid.
the class ResultCodeTest method testNoBids.
@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.runToEndOfTasks();
ShadowLooper demandLooper = shadowOf(fetcher.getDemandHandler().getLooper());
demandLooper.runToEndOfTasks();
ShadowLooper bgLooper = Shadows.shadowOf(((BackgroundThreadExecutor) TasksManager.getInstance().backgroundThreadExecutor).getBackgroundHandler().getLooper());
bgLooper.runToEndOfTasks();
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
verify(mockListener).onComplete(ResultCode.NO_BIDS);
assertEquals(null, testView.getKeywords());
}
use of org.robolectric.shadows.ShadowLooper in project prebid-mobile-android by prebid.
the class ResultCodeTest method testSuccessRubiconForDFP.
@Test
public void testSuccessRubiconForDFP() 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.oneBidFromRubicon()));
BannerAdUnit adUnit = new BannerAdUnit("123456", 300, 250);
AdManagerAdRequest testRequest = new AdManagerAdRequest.Builder().build();
OnCompleteListener mockListener = mock(OnCompleteListener.class);
adUnit.fetchDemand(testRequest, 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);
Bundle bundle = testRequest.getCustomTargeting();
assertEquals(16, bundle.size());
String hb_pb = "hb_pb";
assertTrue(bundle.containsKey(hb_pb));
assertEquals("1.20", bundle.get(hb_pb));
String hb_pb_rubicon = "hb_pb_rubicon";
assertTrue(bundle.containsKey(hb_pb_rubicon));
assertEquals("1.20", bundle.get(hb_pb_rubicon));
String hb_bidder = "hb_bidder";
assertTrue(bundle.containsKey(hb_bidder));
assertEquals("rubicon", bundle.get(hb_bidder));
String hb_bidder_rubicon = "hb_bidder_rubicon";
assertTrue(bundle.containsKey(hb_bidder_rubicon));
assertEquals("rubicon", bundle.get(hb_bidder_rubicon));
String hb_cache_id = "hb_cache_id";
assertTrue(bundle.containsKey(hb_cache_id));
assertEquals("a2f41588-4727-425c-9ef0-3b382debef1e", bundle.get(hb_cache_id));
String hb_cache_id_rubicon = "hb_cache_id_rubicon";
assertTrue(bundle.containsKey(hb_cache_id_rubicon));
assertEquals("a2f41588-4727-425c-9ef0-3b382debef1e", bundle.get(hb_cache_id_rubicon));
String hb_env = "hb_env";
assertTrue(bundle.containsKey(hb_env));
assertEquals("mobile-app", bundle.get(hb_env));
String hb_env_rubicon = "hb_env_rubicon";
assertTrue(bundle.containsKey(hb_env_rubicon));
assertEquals("mobile-app", bundle.get(hb_env_rubicon));
String hb_size = "hb_size";
assertTrue(bundle.containsKey(hb_size));
assertEquals("300x250", bundle.get(hb_size));
String hb_size_rubicon = "hb_size_rubicon";
assertTrue(bundle.containsKey(hb_size_rubicon));
assertEquals("300x250", bundle.get(hb_size_rubicon));
String hb_cache_hostpath = "hb_cache_hostpath";
assertTrue(bundle.containsKey(hb_cache_hostpath));
assertEquals("https://prebid-cache-europe.rubiconproject.com/cache", bundle.get(hb_cache_hostpath));
String hb_cache_hostpath_rubicon = "hb_cache_hostpath_rubicon";
assertTrue(bundle.containsKey(hb_cache_hostpath_rubicon));
assertEquals("https://prebid-cache-europe.rubiconproject.com/cache", bundle.get(hb_cache_hostpath_rubicon));
String hb_cache_path = "hb_cache_path";
assertTrue(bundle.containsKey(hb_cache_path));
assertEquals("/cache", bundle.get(hb_cache_path));
String hb_cache_path_rubicon = "hb_cache_path_rubicon";
assertTrue(bundle.containsKey(hb_cache_path_rubicon));
assertEquals("/cache", bundle.get(hb_cache_path_rubicon));
String hb_cache_host_rubicon = "hb_cache_host_rubicon";
assertTrue(bundle.containsKey(hb_cache_host_rubicon));
assertEquals("prebid-cache-europe.rubiconproject.com", bundle.get(hb_cache_host_rubicon));
String hb_cache_host = "hb_cache_host";
assertTrue(bundle.containsKey(hb_cache_host));
assertEquals("prebid-cache-europe.rubiconproject.com", bundle.get(hb_cache_host));
}
Aggregations