use of com.google.android.gms.ads.admanager.AdManagerAdRequest in project prebid-mobile-android by prebid.
the class GamUtilsTest method prepare_AddReservedKeys.
@Test
public void prepare_AddReservedKeys() {
final AdManagerAdRequest publisherAdRequest = new AdManagerAdRequest.Builder().build();
Bundle extras = new Bundle();
extras.putString("key1", "param1");
extras.putString("key2", "param2");
extras.putString("key3", "param3");
extras.putString(NativeAdUnit.BUNDLE_KEY_CACHE_ID, "param4");
GamUtils.prepare(publisherAdRequest, extras);
Bundle actualTargeting = publisherAdRequest.getCustomTargeting();
assertEquals(3, actualTargeting.size());
assertEquals("Bundle[{key1=param1, key2=param2, key3=param3}]", actualTargeting.toString());
}
use of com.google.android.gms.ads.admanager.AdManagerAdRequest in project prebid-mobile-android by prebid.
the class DemandFetcherTest method testBaseConditions.
@Test
public void testBaseConditions() throws Exception {
AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
AdManagerAdRequest request = builder.build();
DemandFetcher demandFetcher = new DemandFetcher(request);
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);
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 bgLooper = Shadows.shadowOf(((BackgroundThreadExecutor) TasksManager.getInstance().backgroundThreadExecutor).getBackgroundHandler().getLooper());
bgLooper.runToEndOfTasks();
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
demandFetcher.destroy();
assertEquals(DemandFetcher.STATE.DESTROYED, FieldUtils.readField(demandFetcher, "state", true));
}
use of com.google.android.gms.ads.admanager.AdManagerAdRequest 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 com.google.android.gms.ads.admanager.AdManagerAdRequest in project prebid-mobile-android by prebid.
the class UtilTest method testSupportedAdObject.
@Test
public void testSupportedAdObject() throws Exception {
MoPubView testView = new MoPubView(activity);
assertTrue(Util.supportedAdObject(testView));
assertFalse(Util.supportedAdObject(null));
MoPubInterstitial interstitial = new MoPubInterstitial(activity, "");
assertTrue(Util.supportedAdObject(interstitial));
AdManagerAdRequest request = new AdManagerAdRequest.Builder().build();
assertTrue(Util.supportedAdObject(request));
AdManagerAdRequest.Builder requestBuilder = new AdManagerAdRequest.Builder();
assertTrue(Util.supportedAdObject(requestBuilder));
Object object = new Object();
assertFalse(Util.supportedAdObject(object));
}
use of com.google.android.gms.ads.admanager.AdManagerAdRequest in project prebid-mobile-android by prebid.
the class XandrNativeInAppGAMDemoActivity method loadInAppNative.
private void loadInAppNative() {
removePreviousAds();
PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
PrebidMobile.setPrebidServerAccountId(Constants.PBS_ACCOUNT_ID_APPNEXUS);
NativeAdUnit nativeAdUnit = new NativeAdUnit(Constants.PBS_CONFIG_ID_NATIVE_APPNEXUS);
nativeAdUnit.setContextType(NativeAdUnit.CONTEXT_TYPE.SOCIAL_CENTRIC);
nativeAdUnit.setPlacementType(NativeAdUnit.PLACEMENTTYPE.CONTENT_FEED);
nativeAdUnit.setContextSubType(NativeAdUnit.CONTEXTSUBTYPE.GENERAL_SOCIAL);
adUnit = nativeAdUnit;
ArrayList<NativeEventTracker.EVENT_TRACKING_METHOD> methods = new ArrayList<>();
methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.IMAGE);
methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.JS);
try {
NativeEventTracker tracker = new NativeEventTracker(NativeEventTracker.EVENT_TYPE.IMPRESSION, methods);
nativeAdUnit.addEventTracker(tracker);
} catch (Exception e) {
e.printStackTrace();
}
NativeTitleAsset title = new NativeTitleAsset();
title.setLength(90);
title.setRequired(true);
nativeAdUnit.addAsset(title);
NativeImageAsset icon = new NativeImageAsset();
icon.setImageType(NativeImageAsset.IMAGE_TYPE.ICON);
icon.setWMin(20);
icon.setHMin(20);
icon.setRequired(true);
nativeAdUnit.addAsset(icon);
NativeImageAsset image = new NativeImageAsset();
image.setImageType(NativeImageAsset.IMAGE_TYPE.MAIN);
image.setHMin(200);
image.setWMin(200);
image.setRequired(true);
nativeAdUnit.addAsset(image);
NativeDataAsset data = new NativeDataAsset();
data.setLen(90);
data.setDataType(NativeDataAsset.DATA_TYPE.SPONSORED);
data.setRequired(true);
nativeAdUnit.addAsset(data);
NativeDataAsset body = new NativeDataAsset();
body.setRequired(true);
body.setDataType(NativeDataAsset.DATA_TYPE.DESC);
nativeAdUnit.addAsset(body);
NativeDataAsset cta = new NativeDataAsset();
cta.setRequired(true);
cta.setDataType(NativeDataAsset.DATA_TYPE.CTATEXT);
nativeAdUnit.addAsset(cta);
final AdManagerAdRequest adManagerAdRequest = new AdManagerAdRequest.Builder().build();
// Fetching the demannd using OnCompleteListener
nativeAdUnit.fetchDemand(adManagerAdRequest, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
if (resultCode == ResultCode.SUCCESS) {
loadDfp(adManagerAdRequest);
} else {
Toast.makeText(XandrNativeInAppGAMDemoActivity.this, "Native Ad Unit: " + resultCode.name(), Toast.LENGTH_SHORT).show();
}
refreshCount++;
XandrNativeInAppGAMDemoActivity.this.resultCode = resultCode;
request = adManagerAdRequest;
}
});
// ================================================================================
// SAMPLE CODE: Fetching the demand using OnCompleteListener2
// ================================================================================
/*
nativeAdUnit.fetchDemand(new OnCompleteListener2() {
@Override
public void onComplete(ResultCode resultCode, Map<String, String> unmodifiableMap) {
if (resultCode == ResultCode.SUCCESS) {
final AdManagerAdRequest.Builder adManagerAdRequestBuilder = new AdManagerAdRequest.Builder();
for (String key: unmodifiableMap.keySet()) {
adManagerAdRequestBuilder.addCustomTargeting(key, unmodifiableMap.get(key));
}
loadDfp(adManagerAdRequestBuilder.build());
}
Toast.makeText(XandrNativeInAppGAMDemoActivity.this, "Native Ad Unit: " + resultCode.name(), Toast.LENGTH_SHORT).show();
}
});
*/
// ================================================================================
// SAMPLE CODE: END
// ================================================================================
}
Aggregations