use of org.prebid.mobile.AdUnit in project prebid-mobile-android by prebid.
the class ExtraTests method testSameConfigIdOnDifferentAdObjects.
@Test
public void testSameConfigIdOnDifferentAdObjects() throws Exception {
final ArrayList<AdUnit> adUnits = new ArrayList<AdUnit>();
final ArrayList<OnCompleteListener> spies = new ArrayList<>();
PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
PrebidMobile.setPrebidServerAccountId("bfa84af2-bd16-4d35-96ad-31c6bb888df0");
PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
PrebidMobile.setShareGeoLocation(true);
mHandler.post(new Runnable() {
@Override
public void run() {
final MoPubView adObject1 = new MoPubView(m.getActivity());
adObject1.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_320x50_APPNEXUS);
adObject1.setMinimumWidth(320);
adObject1.setMinimumHeight(50);
BannerAdUnit adUnit1 = new BannerAdUnit(Constants.PBS_CONFIG_ID_320x50_APPNEXUS, 320, 50);
adUnits.add(adUnit1);
OnCompleteListener l1 = new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
assertTrue(adObject1.getKeywords().contains("hb_pb:0.50"));
assertTrue(adObject1.getKeywords().contains("hb_cache_id:"));
FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
adFrame.addView(adObject1);
adObject1.loadAd();
}
};
l1 = spy(l1);
spies.add(l1);
adUnit1.fetchDemand(adObject1, l1);
AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
final AdManagerAdRequest adObject2 = builder.build();
BannerAdUnit adUnit2 = new BannerAdUnit(Constants.PBS_CONFIG_ID_320x50_APPNEXUS, 320, 50);
adUnits.add(adUnit2);
OnCompleteListener l2 = new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
assertEquals(10, adObject2.getCustomTargeting().size());
assertTrue(adObject2.getCustomTargeting().keySet().contains("hb_pb"));
assertTrue(adObject2.getCustomTargeting().keySet().contains("hb_cache_id"));
assertEquals("0.50", adObject2.getCustomTargeting().getString("hb_pb"));
FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
AdManagerAdView adView = new AdManagerAdView(m.getActivity());
adView.setAdSizes(AdSize.BANNER);
adView.setAdUnitId(Constants.DFP_BANNER_ADUNIT_ID_ALL_SIZES_APPNEXUS);
adFrame.addView(adView);
adView.setId(1);
adView.loadAd(adObject2);
}
};
l2 = spy(l2);
spies.add(l2);
adUnit1.fetchDemand(adObject2, l2);
}
});
Thread.sleep(10000);
verify(spies.get(0), times(1)).onComplete(ResultCode.SUCCESS);
verify(spies.get(1), times(1)).onComplete(ResultCode.SUCCESS);
}
use of org.prebid.mobile.AdUnit in project prebid-mobile-android by prebid.
the class AdManagerComplexTest method testFetchDemand.
@Test
public void testFetchDemand() throws Exception {
final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
fetchDemandHelper(0, new FetchDemandCompleteListener() {
@Override
public void preFetchDemand() {
}
@Override
public void executeFetchDemand(AdUnit adUnit, final List<Map<String, String>> resultList) {
adUnit.fetchDemand(builder, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
Bundle customTargetingBundle = builder.build().getCustomTargeting();
Map<String, String> map = new HashMap<>(customTargetingBundle.keySet().size());
for (String key : customTargetingBundle.keySet()) {
map.put(key, customTargetingBundle.get(key).toString());
}
resultList.add(map);
}
});
}
@Override
public void postFetchDemand(List<Map<String, String>> resultList) {
}
});
}
use of org.prebid.mobile.AdUnit in project prebid-mobile-android by prebid.
the class AdManagerComplexTest method testFetchDemandAutoRefresh.
@Test
public void testFetchDemandAutoRefresh() throws Exception {
final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
final IntegerWrapper requestCountWrapper = new IntegerWrapper();
fetchDemandHelper(31_000, new FetchDemandCompleteListener() {
@Override
public void preFetchDemand() {
mockServer.enqueue(new MockResponse().setResponseCode(200).setBody("{\n" + " \"seatbid\": [\n" + " {\n" + " \"bid\": [\n" + " {\n" + " \"ext\": {\n" + " \"prebid\": {\n" + " \"targeting\": {\n" + " \"hb_cache_id\": \"top_bid_1\",\n" + " \"key1\": \"value1\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + "}"));
}
@Override
public void executeFetchDemand(AdUnit adUnit, final List<Map<String, String>> resultList) {
adUnit.fetchDemand(builder, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
requestCountWrapper.value++;
AdManagerAdRequest adManagerAdRequest = builder.build();
Bundle customTargetingBundle = adManagerAdRequest.getCustomTargeting();
Map<String, String> map = new HashMap<>(customTargetingBundle.keySet().size());
for (String key : customTargetingBundle.keySet()) {
map.put(key, customTargetingBundle.get(key).toString());
}
resultList.add(map);
}
});
}
@Override
public void postFetchDemand(List<Map<String, String>> resultList) {
Map<String, String> result = resultList.get(1);
assertEquals("top_bid_1", result.get("hb_cache_id"));
assertEquals("value1", result.get("key1"));
}
});
assertEquals(2, requestCountWrapper.value);
}
use of org.prebid.mobile.AdUnit in project prebid-mobile-android by prebid.
the class AdManagerComplexTest method fetchDemandHelper.
public void fetchDemandHelper(int autoRefreshMillis, FetchDemandCompleteListener listener) throws Exception {
// given
PrebidMobile.setPrebidServerHost(Host.CUSTOM);
HttpUrl httpUrl = mockServer.url("/fetchDemandHelper");
Host.CUSTOM.setHostUrl(httpUrl.toString());
PrebidMobile.setPrebidServerAccountId("1001");
mockServer.enqueue(new MockResponse().setResponseCode(200).setBody("{\n" + " \"seatbid\": [\n" + " {\n" + " \"bid\": [\n" + " {\n" + " \"ext\": {\n" + " \"prebid\": {\n" + " \"targeting\": {\n" + " \"hb_env\": \"mobile-app\",\n" + " \"hb_cache_hostpath\": \"https://prebid-cache-europe.rubiconproject.com/cache\",\n" + " \"hb_size_rubicon\": \"300x250\",\n" + " \"hb_cache_id\": \"a2f41588-4727-425c-9ef0-3b382debef1e\",\n" + " \"hb_cache_path_rubicon\": \"/cache\",\n" + " \"hb_cache_host_rubicon\": \"prebid-cache-europe.rubiconproject.com\",\n" + " \"hb_pb\": \"1.20\",\n" + " \"hb_pb_rubicon\": \"1.20\",\n" + " \"hb_cache_id_rubicon\": \"a2f41588-4727-425c-9ef0-3b382debef1e\",\n" + " \"hb_cache_path\": \"/cache\",\n" + " \"hb_size\": \"300x250\",\n" + " \"hb_cache_hostpath_rubicon\": \"https://prebid-cache-europe.rubiconproject.com/cache\",\n" + " \"hb_env_rubicon\": \"mobile-app\",\n" + " \"hb_bidder\": \"rubicon\",\n" + " \"hb_bidder_rubicon\": \"rubicon\",\n" + " \"hb_cache_host\": \"prebid-cache-europe.rubiconproject.com\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + "}"));
listener.preFetchDemand();
final List<Map<String, String>> resultList = new ArrayList<>();
// when
AdUnit adUnit = new BannerAdUnit("1001-1", 300, 250);
adUnit.setAutoRefreshPeriodMillis(autoRefreshMillis);
listener.executeFetchDemand(adUnit, resultList);
try {
Thread.sleep(autoRefreshMillis + 1_000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// then
Map<String, String> map = resultList.get(0);
assertEquals("mobile-app", map.get("hb_env"));
assertEquals("https://prebid-cache-europe.rubiconproject.com/cache", map.get("hb_cache_hostpath"));
assertEquals("300x250", map.get("hb_size_rubicon"));
assertEquals("a2f41588-4727-425c-9ef0-3b382debef1e", map.get("hb_cache_id"));
assertEquals("/cache", map.get("hb_cache_path_rubicon"));
assertEquals("prebid-cache-europe.rubiconproject.com", map.get("hb_cache_host_rubicon"));
assertEquals("1.20", map.get("hb_pb"));
assertEquals("1.20", map.get("hb_pb_rubicon"));
assertEquals("a2f41588-4727-425c-9ef0-3b382debef1e", map.get("hb_cache_id_rubicon"));
assertEquals("/cache", map.get("hb_cache_path"));
assertEquals("300x250", map.get("hb_size"));
assertEquals("https://prebid-cache-europe.rubiconproject.com/cache", map.get("hb_cache_hostpath_rubicon"));
assertEquals("mobile-app", map.get("hb_env_rubicon"));
assertEquals("rubicon", map.get("hb_bidder"));
assertEquals("rubicon", map.get("hb_bidder_rubicon"));
assertEquals("prebid-cache-europe.rubiconproject.com", map.get("hb_cache_host"));
listener.postFetchDemand(resultList);
}
use of org.prebid.mobile.AdUnit in project prebid-mobile-android by prebid.
the class AdManagerComplexTest method testAdManagerAdRequestBuilderUseCase.
@Test
public void testAdManagerAdRequestBuilderUseCase() throws Exception {
// given
mockServer.enqueue(new MockResponse().setResponseCode(200).setBody("{\n" + " \"seatbid\": [\n" + " {\n" + " \"bid\": [\n" + " {\n" + " \"ext\": {\n" + " \"prebid\": {\n" + " \"targeting\": {\n" + " \"hb_cache_id\": \"top_bid_1\",\n" + " \"key1\": \"value1\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + "}"));
// important line
PrebidMobile.setPrebidServerHost(Host.CUSTOM);
HttpUrl httpUrl = mockServer.url("/testAdManagerAdRequestBuilderUseCase");
Host.CUSTOM.setHostUrl(httpUrl.toString());
PrebidMobile.setPrebidServerAccountId("1001");
final ReferenceWrapper<Bundle> customTargetingBundleWrapper1 = new ReferenceWrapper<>();
// when
final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
AdUnit adUnit = new BannerAdUnit("1001-1", 300, 250);
adUnit.fetchDemand(builder, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
builder.addCustomTargeting("key2", "value2");
AdManagerAdRequest adManagerAdRequest = builder.build();
Bundle customTargetingBundle = adManagerAdRequest.getCustomTargeting();
customTargetingBundleWrapper1.value = (Bundle) customTargetingBundle.clone();
}
});
try {
Thread.sleep(1_000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// then
Bundle customTargetingBundle = customTargetingBundleWrapper1.value;
assertEquals(3, customTargetingBundle.keySet().size());
assertEquals("top_bid_1", customTargetingBundle.getString("hb_cache_id"));
assertEquals("value1", customTargetingBundle.getString("key1"));
assertEquals("value2", customTargetingBundle.getString("key2"));
}
Aggregations