Search in sources :

Example 1 with NativeCustomTemplateAd

use of com.google.android.gms.ads.formats.NativeCustomTemplateAd 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();
        }
    });
}
Also used : ShadowLooper(org.robolectric.shadows.ShadowLooper) BackgroundThreadExecutor(org.prebid.mobile.tasksmanager.BackgroundThreadExecutor) Field(java.lang.reflect.Field) MockResponse(okhttp3.mockwebserver.MockResponse) View(android.view.View) HttpUrl(okhttp3.HttpUrl) NativeCustomTemplateAd(com.google.android.gms.ads.formats.NativeCustomTemplateAd) Test(org.junit.Test)

Example 2 with NativeCustomTemplateAd

use of com.google.android.gms.ads.formats.NativeCustomTemplateAd 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();
        }
    });
}
Also used : ShadowLooper(org.robolectric.shadows.ShadowLooper) BackgroundThreadExecutor(org.prebid.mobile.tasksmanager.BackgroundThreadExecutor) Field(java.lang.reflect.Field) MockResponse(okhttp3.mockwebserver.MockResponse) View(android.view.View) HttpUrl(okhttp3.HttpUrl) NativeCustomTemplateAd(com.google.android.gms.ads.formats.NativeCustomTemplateAd) Test(org.junit.Test)

Example 3 with NativeCustomTemplateAd

use of com.google.android.gms.ads.formats.NativeCustomTemplateAd 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();
        }
    });
}
Also used : ShadowLooper(org.robolectric.shadows.ShadowLooper) BackgroundThreadExecutor(org.prebid.mobile.tasksmanager.BackgroundThreadExecutor) Field(java.lang.reflect.Field) MockResponse(okhttp3.mockwebserver.MockResponse) HttpUrl(okhttp3.HttpUrl) NativeCustomTemplateAd(com.google.android.gms.ads.formats.NativeCustomTemplateAd) Test(org.junit.Test)

Example 4 with NativeCustomTemplateAd

use of com.google.android.gms.ads.formats.NativeCustomTemplateAd in project prebid-mobile-android by prebid.

the class UtilTest method testFindNativeNotFoundDFP.

@Test
public void testFindNativeNotFoundDFP() {
    String mockedResponse = MockPrebidServerResponses.validResponsePrebidNativeNativeBid();
    String cacheId = CacheManager.save(mockedResponse);
    NativeCustomTemplateAd nativeCustomTemplateAd = Mockito.mock(NativeCustomTemplateAd.class);
    Mockito.when(nativeCustomTemplateAd.getText("isPrebid")).thenReturn("0");
    Mockito.when(nativeCustomTemplateAd.getText("hb_cache_id_local")).thenReturn(cacheId);
    AdViewUtils.findNative(nativeCustomTemplateAd, new PrebidNativeAdListener() {

        @Override
        public void onPrebidNativeLoaded(PrebidNativeAd ad) {
            fail();
        }

        @Override
        public void onPrebidNativeNotFound() {
            assertTrue(true);
        }

        @Override
        public void onPrebidNativeNotValid() {
            fail();
        }
    });
}
Also used : NativeCustomTemplateAd(com.google.android.gms.ads.formats.NativeCustomTemplateAd) Test(org.junit.Test)

Example 5 with NativeCustomTemplateAd

use of com.google.android.gms.ads.formats.NativeCustomTemplateAd in project prebid-mobile-android by prebid.

the class UtilTest method testFindNativeNotValidDFP.

@Test
public void testFindNativeNotValidDFP() {
    String mockedResponse = MockPrebidServerResponses.validResponsePrebidNativeNativeBid();
    String cacheId = CacheManager.save(mockedResponse);
    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) {
            fail();
        }

        @Override
        public void onPrebidNativeNotFound() {
            fail();
        }

        @Override
        public void onPrebidNativeNotValid() {
            assertTrue(true);
        }
    });
}
Also used : NativeCustomTemplateAd(com.google.android.gms.ads.formats.NativeCustomTemplateAd) Test(org.junit.Test)

Aggregations

NativeCustomTemplateAd (com.google.android.gms.ads.formats.NativeCustomTemplateAd)7 Test (org.junit.Test)6 Field (java.lang.reflect.Field)3 HttpUrl (okhttp3.HttpUrl)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 BackgroundThreadExecutor (org.prebid.mobile.tasksmanager.BackgroundThreadExecutor)3 ShadowLooper (org.robolectric.shadows.ShadowLooper)3 View (android.view.View)2 FrameLayout (android.widget.FrameLayout)1 AdListener (com.google.android.gms.ads.AdListener)1 LoadAdError (com.google.android.gms.ads.LoadAdError)1 AdManagerAdView (com.google.android.gms.ads.admanager.AdManagerAdView)1 OnAdManagerAdViewLoadedListener (com.google.android.gms.ads.formats.OnAdManagerAdViewLoadedListener)1 UnifiedNativeAd (com.google.android.gms.ads.formats.UnifiedNativeAd)1 PrebidNativeAd (org.prebid.mobile.PrebidNativeAd)1 PrebidNativeAdListener (org.prebid.mobile.PrebidNativeAdListener)1