use of org.prebid.mobile.BannerAdUnit in project prebid-mobile-android by prebid.
the class ExtraTests method testAppNexusAgeTargeting3.
// Passing year 2018 is valid yob, should send yob and but get back a no bid, since campaign targeting 25-34
@Test
public void testAppNexusAgeTargeting3() throws Exception {
server.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
if (request.getPath().equals("/")) {
String postData = request.getBody().readUtf8();
assertTrue("Post data does not contain yob 2018: " + postData, postData.contains("2018"));
return getAppNexusDemand(postData);
}
return new MockResponse().setResponseCode(404);
}
});
PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
PrebidMobile.setPrebidServerAccountId("bfa84af2-bd16-4d35-96ad-31c6bb888df0");
Host.CUSTOM.setHostUrl(server.url("/").toString());
PrebidMobile.setPrebidServerHost(Host.CUSTOM);
PrebidMobile.setShareGeoLocation(true);
TargetingParams.setYearOfBirth(2018);
final OnCompleteListener[] listener = new OnCompleteListener[1];
mHandler.post(new Runnable() {
@Override
public void run() {
final MoPubView adObject = new MoPubView(m.getActivity());
adObject.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_300x250_APPNEXUS);
adObject.setMinimumHeight(250);
adObject.setMinimumWidth(300);
BannerAdUnit adUnit = new BannerAdUnit("47706260-ee91-4cd7-b656-2185aca89f59", 300, 250);
OnCompleteListener l = new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
adFrame.addView(adObject);
adObject.loadAd();
}
};
listener[0] = spy(l);
adUnit.fetchDemand(adObject, listener[0]);
}
});
Thread.sleep(10000);
verify(listener[0], times(1)).onComplete(ResultCode.NO_BIDS);
onView(withId(R.id.adFrame)).check(matches(isDisplayed()));
onWebView().check(webMatches(getCurrentUrl(), containsString("ads.mopub.com")));
onWebView().check(webContent(containingTextInBody("Hello, I'm not a Prebid ad.")));
}
use of org.prebid.mobile.BannerAdUnit 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.BannerAdUnit 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"));
}
use of org.prebid.mobile.BannerAdUnit in project prebid-mobile-android by prebid.
the class ExtraTests method testPostDataWithContext.
@Test
public void testPostDataWithContext() throws Exception {
server.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) {
if (request.getPath().equals("/testPostData")) {
String postDataString = request.getBody().readUtf8();
try {
JSONObject postData = new JSONObject(postDataString);
JSONObject device = postData.getJSONObject("device");
String ifa = device.getString("ifa");
assertTrue(ifa != null && !ifa.isEmpty());
String ua = device.getString("ua");
assertTrue(ua != null && !ua.isEmpty());
} catch (JSONException e) {
fail("error:" + e);
}
return getAppNexusDemand(postDataString);
}
return new MockResponse().setResponseCode(404);
}
});
PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
PrebidMobile.setPrebidServerAccountId("1001");
PrebidMobile.setPrebidServerHost(Host.CUSTOM);
Host.CUSTOM.setHostUrl(server.url("testPostData").toString());
mHandler.post(new Runnable() {
@Override
public void run() {
BannerAdUnit adUnit = new BannerAdUnit("1001-1", 300, 250);
final MoPubView adObject = new MoPubView(m.getActivity());
adUnit.fetchDemand(adObject, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
}
});
}
});
Thread.sleep(5_000);
}
Aggregations