Search in sources :

Example 6 with ResultCode

use of org.prebid.mobile.ResultCode in project prebid-mobile-android by prebid.

the class ExtraTests method testAppNexusAgeTargeting4.

@Test
public void testAppNexusAgeTargeting4() 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 1989: " + postData, postData.contains("1989"));
                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(1989);
    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.SUCCESS);
    onView(withId(R.id.adFrame)).check(matches(isDisplayed()));
    onWebView().check(webMatches(getCurrentUrl(), containsString("ads.mopub.com")));
    onWebView().check(webContent(containingTextInBody("ucTag.renderAd")));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Dispatcher(okhttp3.mockwebserver.Dispatcher) BannerAdUnit(org.prebid.mobile.BannerAdUnit) OnCompleteListener(org.prebid.mobile.OnCompleteListener) FrameLayout(android.widget.FrameLayout) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView) Test(org.junit.Test)

Example 7 with ResultCode

use of org.prebid.mobile.ResultCode in project prebid-mobile-android by prebid.

the class ExtraTests method testLocationTargeting.

// This test should be run with a real device located in New York City, New York, USA
@Test
public void testLocationTargeting() throws Exception {
    if (!TestUtil.isEmulator()) {
        server.setDispatcher(new Dispatcher() {

            int lastfix = -1;

            @Override
            public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
                String postData = request.getBody().readUtf8();
                if (request.getPath().equals("/sharerealgeo")) {
                    assertTrue(postData.contains("geo"));
                    try {
                        JSONObject data = new JSONObject(postData);
                        lastfix = data.getJSONObject("device").getJSONObject("geo").getInt("lastfix");
                    } catch (JSONException e) {
                    }
                    return getAppNexusDemand(postData);
                } else if (request.getPath().equals("/sharefakegeo")) {
                    assertTrue(!postData.contains("geo"));
                    // add a shanghai location to the request
                    try {
                        JSONObject data = new JSONObject(postData);
                        JSONObject device = data.getJSONObject("device");
                        JSONObject geo = new JSONObject();
                        geo.put("lat", 31.2304);
                        geo.put("lon", 121.4737);
                        geo.put("accuracy", 19);
                        if (lastfix > 0) {
                            geo.put("lastfix", lastfix);
                        }
                        device.put("geo", geo);
                        data.put("device", device);
                        return getAppNexusDemand(data.toString());
                    } catch (JSONException e) {
                    }
                }
                return new MockResponse().setResponseCode(404);
            }
        });
        // Global Settings
        PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
        PrebidMobile.setPrebidServerAccountId("bfa84af2-bd16-4d35-96ad-31c6bb888df0");
        // Share location
        PrebidMobile.setShareGeoLocation(true);
        Host.CUSTOM.setHostUrl(server.url("/sharerealgeo").toString());
        PrebidMobile.setPrebidServerHost(Host.CUSTOM);
        final OnCompleteListener[] listener = new OnCompleteListener[2];
        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("8522cead-1eb4-4f09-b6e2-083fa3a6e6ce", 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.SUCCESS);
        onWebView().check(webContent(containingTextInBody("ucTag.renderAd")));
        // Do not share location
        PrebidMobile.setShareGeoLocation(false);
        Host.CUSTOM.setHostUrl(server.url("/sharefakegeo").toString());
        PrebidMobile.setPrebidServerHost(Host.CUSTOM);
        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("8522cead-1eb4-4f09-b6e2-083fa3a6e6ce", 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[1] = spy(l);
                adUnit.fetchDemand(adObject, listener[1]);
            }
        });
        Thread.sleep(10000);
    // TODO uncomment below two lines when https://jira.corp.appnexus.com/browse/ROR-481 is resolved
    // verify(listener[1], times(1)).onComplete(ResultCode.NO_BIDS);
    // onWebView().check(webContent(containingTextInBody("Hello, I'm not a Prebid ad.")));
    }
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) JSONException(org.json.JSONException) Matchers.containsString(org.hamcrest.Matchers.containsString) Dispatcher(okhttp3.mockwebserver.Dispatcher) BannerAdUnit(org.prebid.mobile.BannerAdUnit) OnCompleteListener(org.prebid.mobile.OnCompleteListener) JSONObject(org.json.JSONObject) FrameLayout(android.widget.FrameLayout) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView) Test(org.junit.Test)

Example 8 with ResultCode

use of org.prebid.mobile.ResultCode in project prebid-mobile-android by prebid.

the class ExtraTests method testRubiconInvalidPrebidServerConfigId.

@Test
public void testRubiconInvalidPrebidServerConfigId() throws Exception {
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("1001");
    PrebidMobile.setPrebidServerHost(Host.RUBICON);
    PrebidMobile.setShareGeoLocation(true);
    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_RUBICON);
            adObject.setMinimumHeight(250);
            adObject.setMinimumWidth(300);
            BannerAdUnit adUnit = new BannerAdUnit("1001-1_ERROR", 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(2000);
    verify(listener[0], times(1)).onComplete(ResultCode.INVALID_CONFIG_ID);
}
Also used : OnCompleteListener(org.prebid.mobile.OnCompleteListener) FrameLayout(android.widget.FrameLayout) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView) BannerAdUnit(org.prebid.mobile.BannerAdUnit) Test(org.junit.Test)

Example 9 with ResultCode

use of org.prebid.mobile.ResultCode in project prebid-mobile-android by prebid.

the class ExtraTests method testAppNexusInvalidPrebidServerConfigId.

@Test
public void testAppNexusInvalidPrebidServerConfigId() throws Exception {
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("bfa84af2-bd16-4d35-96ad-31c6bb888df0");
    PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
    PrebidMobile.setShareGeoLocation(true);
    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("6ace8c7d-88c0-4623-8117-ffffffffffff", 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.INVALID_CONFIG_ID);
}
Also used : OnCompleteListener(org.prebid.mobile.OnCompleteListener) FrameLayout(android.widget.FrameLayout) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView) BannerAdUnit(org.prebid.mobile.BannerAdUnit) Test(org.junit.Test)

Example 10 with ResultCode

use of org.prebid.mobile.ResultCode in project prebid-mobile-android by prebid.

the class ExtraTests method testRubiconDemand.

@Test
public void testRubiconDemand() throws Exception {
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("1001");
    PrebidMobile.setPrebidServerHost(Host.RUBICON);
    PrebidMobile.setShareGeoLocation(true);
    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("1001-2", 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.SUCCESS);
    onView(withId(R.id.adFrame)).check(matches(isDisplayed()));
    onWebView().check(webMatches(getCurrentUrl(), containsString("ads.mopub.com")));
    onWebView().check(webContent(containingTextInBody("ucTag.renderAd")));
}
Also used : OnCompleteListener(org.prebid.mobile.OnCompleteListener) FrameLayout(android.widget.FrameLayout) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView) BannerAdUnit(org.prebid.mobile.BannerAdUnit) Test(org.junit.Test)

Aggregations

ResultCode (org.prebid.mobile.ResultCode)42 OnCompleteListener (org.prebid.mobile.OnCompleteListener)41 BannerAdUnit (org.prebid.mobile.BannerAdUnit)29 FrameLayout (android.widget.FrameLayout)27 Test (org.junit.Test)25 MoPubView (com.mopub.mobileads.MoPubView)23 AdManagerAdRequest (com.google.android.gms.ads.admanager.AdManagerAdRequest)14 MockResponse (okhttp3.mockwebserver.MockResponse)9 NonNull (androidx.annotation.NonNull)7 ArrayList (java.util.ArrayList)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 AdUnit (org.prebid.mobile.AdUnit)7 InterstitialAdUnit (org.prebid.mobile.InterstitialAdUnit)7 AdManagerAdView (com.google.android.gms.ads.admanager.AdManagerAdView)6 Dispatcher (okhttp3.mockwebserver.Dispatcher)6 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)6 AdListener (com.google.android.gms.ads.AdListener)5 LoadAdError (com.google.android.gms.ads.LoadAdError)5 VideoBaseAdUnit (org.prebid.mobile.VideoBaseAdUnit)5 AdSize (com.google.android.gms.ads.AdSize)4