use of org.prebid.mobile.tasksmanager.BackgroundThreadExecutor 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.prebid.mobile.tasksmanager.BackgroundThreadExecutor 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));
}
use of org.prebid.mobile.tasksmanager.BackgroundThreadExecutor in project prebid-mobile-android by prebid.
the class PrebidNativeNativeTest method testSuccessfulPrebidNativeAdExpiry.
@Test
public void testSuccessfulPrebidNativeAdExpiry() {
server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.validResponsePrebidNativeNative()));
HttpUrl hostUrl = server.url("/");
Host.CUSTOM.setHostUrl(hostUrl.toString());
PrebidMobile.setPrebidServerHost(Host.CUSTOM);
PrebidMobile.setPrebidServerAccountId(PBS_ACCOUNT_ID_APPNEXUS);
PrebidMobile.setShareGeoLocation(true);
PrebidMobile.setApplicationContext(activity.getApplicationContext());
DemandAdapter.DemandAdapterListener mockListener = mock(DemandAdapter.DemandAdapterListener.class);
PrebidServerAdapter adapter = new PrebidServerAdapter();
RequestParams requestParams = new RequestParams(PBS_CONFIG_ID_NATIVE_APPNEXUS, AdType.NATIVE, null, new HashMap<String, Set<String>>(), new HashSet<String>(), null, null, null, null, null, new ArrayList<DataObject>());
requestParams.setNativeRequestParams(new NativeRequestParams());
String uuid = UUID.randomUUID().toString();
adapter.requestDemand(requestParams, mockListener, uuid);
ShadowLooper bgLooper = Shadows.shadowOf(((BackgroundThreadExecutor) TasksManager.getInstance().backgroundThreadExecutor).getBackgroundHandler().getLooper());
bgLooper.runOneTask();
bgLooper.runOneTask();
runAllMainThreadExecutorTasks();
Robolectric.getBackgroundThreadScheduler().runOneTask();
Robolectric.getBackgroundThreadScheduler().runOneTask();
String cacheId = "";
try {
Class clazz = Class.forName(CacheManager.class.getName());
Field field = clazz.getDeclaredField("savedValues");
field.setAccessible(true);
HashMap<String, String> map = (HashMap<String, String>) field.get(clazz);
for (String key : map.keySet()) {
cacheId = key;
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
HashMap<String, String> bids = new HashMap<String, String>();
bids.put("hb_bidder", "appnexus");
bids.put("hb_bidder_appnexus", "appnexus");
bids.put("hb_cache_id", "dfad62f2-8ed5-4cf8-a597-f702147b7c98");
bids.put("hb_cache_id_appnexus", "dfad62f2-8ed5-4cf8-a597-f702147b7c98");
bids.put("hb_env", "mobile-app");
bids.put("hb_env_appnexus", "mobile-app");
bids.put("hb_pb", "0.00");
bids.put("hb_pb_appnexus", "0.00");
bids.put("hb_cache_host_appnex", "prebid.sin3.adnxs.com");
bids.put("hb_cache_path_appnex", "/pbc/v1/cache");
bids.put("hb_cache_path", "/pbc/v1/cache");
bids.put("hb_cache_host", "prebid.sin3.adnxs.com");
bids.put("hb_cache_id_local", cacheId);
verify(mockListener).onDemandReady(bids, uuid);
// Test findNative on responded cacheId local
NativeCustomTemplateAd nativeCustomTemplateAd = Mockito.mock(NativeCustomTemplateAd.class);
Mockito.when(nativeCustomTemplateAd.getText("isPrebid")).thenReturn("1");
Mockito.when(nativeCustomTemplateAd.getText("hb_cache_id_local")).thenReturn(cacheId);
AdViewUtils.findNative(nativeCustomTemplateAd, new PrebidNativeAdListener() {
@Override
public void onPrebidNativeLoaded(PrebidNativeAd ad) {
assertTrue(ad != null);
View view = new View(activity);
view.setLayoutParams(new ViewGroup.LayoutParams(200, 200));
ad.registerPrebidNativeAdEventListener(new PrebidNativeAdEventListener() {
@Override
public void onAdClicked() {
fail();
}
@Override
public void onAdImpression() {
fail();
}
@Override
public void onAdExpired() {
adExpired = true;
}
});
assertFalse(adExpired);
Robolectric.getBackgroundThreadScheduler().advanceBy(302, TimeUnit.SECONDS);
Robolectric.getForegroundThreadScheduler().advanceBy(302, TimeUnit.SECONDS);
assertTrue(adExpired);
}
@Override
public void onPrebidNativeNotFound() {
fail();
}
@Override
public void onPrebidNativeNotValid() {
fail();
}
});
}
use of org.prebid.mobile.tasksmanager.BackgroundThreadExecutor in project prebid-mobile-android by prebid.
the class PrebidNativeNativeTest method testSuccessfulPrebidNativeAdClick.
@Test
public void testSuccessfulPrebidNativeAdClick() {
server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.validResponsePrebidNativeNative()));
HttpUrl hostUrl = server.url("/");
Host.CUSTOM.setHostUrl(hostUrl.toString());
PrebidMobile.setPrebidServerHost(Host.CUSTOM);
PrebidMobile.setPrebidServerAccountId(PBS_ACCOUNT_ID_APPNEXUS);
PrebidMobile.setShareGeoLocation(true);
PrebidMobile.setApplicationContext(activity.getApplicationContext());
DemandAdapter.DemandAdapterListener mockListener = mock(DemandAdapter.DemandAdapterListener.class);
PrebidServerAdapter adapter = new PrebidServerAdapter();
RequestParams requestParams = new RequestParams(PBS_CONFIG_ID_NATIVE_APPNEXUS, AdType.NATIVE, null, new HashMap<String, Set<String>>(), new HashSet<String>(), null, null, null, null, null, new ArrayList<DataObject>());
requestParams.setNativeRequestParams(new NativeRequestParams());
String uuid = UUID.randomUUID().toString();
adapter.requestDemand(requestParams, mockListener, uuid);
ShadowLooper bgLooper = Shadows.shadowOf(((BackgroundThreadExecutor) TasksManager.getInstance().backgroundThreadExecutor).getBackgroundHandler().getLooper());
bgLooper.runOneTask();
bgLooper.runOneTask();
runAllMainThreadExecutorTasks();
Robolectric.getBackgroundThreadScheduler().runOneTask();
Robolectric.getBackgroundThreadScheduler().runOneTask();
String cacheId = "";
try {
Class clazz = Class.forName(CacheManager.class.getName());
Field field = clazz.getDeclaredField("savedValues");
field.setAccessible(true);
HashMap<String, String> map = (HashMap<String, String>) field.get(clazz);
for (String key : map.keySet()) {
cacheId = key;
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
HashMap<String, String> bids = new HashMap<String, String>();
bids.put("hb_bidder", "appnexus");
bids.put("hb_bidder_appnexus", "appnexus");
bids.put("hb_cache_id", "dfad62f2-8ed5-4cf8-a597-f702147b7c98");
bids.put("hb_cache_id_appnexus", "dfad62f2-8ed5-4cf8-a597-f702147b7c98");
bids.put("hb_env", "mobile-app");
bids.put("hb_env_appnexus", "mobile-app");
bids.put("hb_pb", "0.00");
bids.put("hb_pb_appnexus", "0.00");
bids.put("hb_cache_host_appnex", "prebid.sin3.adnxs.com");
bids.put("hb_cache_path_appnex", "/pbc/v1/cache");
bids.put("hb_cache_path", "/pbc/v1/cache");
bids.put("hb_cache_host", "prebid.sin3.adnxs.com");
bids.put("hb_cache_id_local", cacheId);
verify(mockListener).onDemandReady(bids, uuid);
// Test findNative on responded cacheId local
NativeCustomTemplateAd nativeCustomTemplateAd = Mockito.mock(NativeCustomTemplateAd.class);
Mockito.when(nativeCustomTemplateAd.getText("isPrebid")).thenReturn("1");
Mockito.when(nativeCustomTemplateAd.getText("hb_cache_id_local")).thenReturn(cacheId);
AdViewUtils.findNative(nativeCustomTemplateAd, new PrebidNativeAdListener() {
@Override
public void onPrebidNativeLoaded(PrebidNativeAd ad) {
assertTrue(ad != null);
View view = new View(activity);
view.setLayoutParams(new ViewGroup.LayoutParams(200, 200));
ad.registerView(view, new PrebidNativeAdEventListener() {
@Override
public void onAdClicked() {
adClicked = true;
}
@Override
public void onAdImpression() {
fail();
}
@Override
public void onAdExpired() {
fail();
}
});
activity.addContentView(view, new ViewGroup.LayoutParams(200, 200));
view.setVisibility(View.VISIBLE);
assertFalse(adClicked);
view.performClick();
assertTrue(adClicked);
}
@Override
public void onPrebidNativeNotFound() {
fail();
}
@Override
public void onPrebidNativeNotValid() {
fail();
}
});
}
use of org.prebid.mobile.tasksmanager.BackgroundThreadExecutor in project prebid-mobile-android by prebid.
the class PrebidNativeNativeTest method testSuccessfulPrebidNativeResponse.
@Test
public void testSuccessfulPrebidNativeResponse() {
server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.validResponsePrebidNativeNative()));
HttpUrl hostUrl = server.url("/");
Host.CUSTOM.setHostUrl(hostUrl.toString());
PrebidMobile.setPrebidServerHost(Host.CUSTOM);
PrebidMobile.setPrebidServerAccountId(PBS_ACCOUNT_ID_APPNEXUS);
PrebidMobile.setShareGeoLocation(true);
PrebidMobile.setApplicationContext(activity.getApplicationContext());
DemandAdapter.DemandAdapterListener mockListener = mock(DemandAdapter.DemandAdapterListener.class);
PrebidServerAdapter adapter = new PrebidServerAdapter();
RequestParams requestParams = new RequestParams(PBS_CONFIG_ID_NATIVE_APPNEXUS, AdType.NATIVE, null, new HashMap<String, Set<String>>(), new HashSet<String>(), null, null, null, null, null, new ArrayList<DataObject>());
requestParams.setNativeRequestParams(new NativeRequestParams());
String uuid = UUID.randomUUID().toString();
adapter.requestDemand(requestParams, mockListener, uuid);
ShadowLooper bgLooper = Shadows.shadowOf(((BackgroundThreadExecutor) TasksManager.getInstance().backgroundThreadExecutor).getBackgroundHandler().getLooper());
bgLooper.runOneTask();
bgLooper.runOneTask();
runAllMainThreadExecutorTasks();
Robolectric.getBackgroundThreadScheduler().runOneTask();
Robolectric.getBackgroundThreadScheduler().runOneTask();
String cacheId = "";
try {
Class clazz = Class.forName(CacheManager.class.getName());
Field field = clazz.getDeclaredField("savedValues");
field.setAccessible(true);
HashMap<String, String> map = (HashMap<String, String>) field.get(clazz);
for (String key : map.keySet()) {
cacheId = key;
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
HashMap<String, String> bids = new HashMap<String, String>();
bids.put("hb_bidder", "appnexus");
bids.put("hb_bidder_appnexus", "appnexus");
bids.put("hb_cache_id", "dfad62f2-8ed5-4cf8-a597-f702147b7c98");
bids.put("hb_cache_id_appnexus", "dfad62f2-8ed5-4cf8-a597-f702147b7c98");
bids.put("hb_env", "mobile-app");
bids.put("hb_env_appnexus", "mobile-app");
bids.put("hb_pb", "0.00");
bids.put("hb_pb_appnexus", "0.00");
bids.put("hb_cache_host_appnex", "prebid.sin3.adnxs.com");
bids.put("hb_cache_path_appnex", "/pbc/v1/cache");
bids.put("hb_cache_path", "/pbc/v1/cache");
bids.put("hb_cache_host", "prebid.sin3.adnxs.com");
bids.put("hb_cache_id_local", cacheId);
verify(mockListener).onDemandReady(bids, uuid);
// Test findNative on responded cacheId local
NativeCustomTemplateAd nativeCustomTemplateAd = Mockito.mock(NativeCustomTemplateAd.class);
Mockito.when(nativeCustomTemplateAd.getText("isPrebid")).thenReturn("1");
Mockito.when(nativeCustomTemplateAd.getText("hb_cache_id_local")).thenReturn(cacheId);
AdViewUtils.findNative(nativeCustomTemplateAd, new PrebidNativeAdListener() {
@Override
public void onPrebidNativeLoaded(PrebidNativeAd ad) {
assertTrue(ad != null);
}
@Override
public void onPrebidNativeNotFound() {
fail();
}
@Override
public void onPrebidNativeNotValid() {
fail();
}
});
}
Aggregations