Search in sources :

Example 1 with AdRequestInput

use of org.prebid.mobile.rendering.networking.parameters.AdRequestInput in project prebid-mobile-android by prebid.

the class URLComponentsTest method testEncoding.

/**
 * Test urlencoding of keys
 */
@Test
public void testEncoding() throws Exception {
    BidRequest bidRequest = new BidRequest();
    AdRequestInput mockAdRequestInput = new AdRequestInput();
    Device device = new Device();
    device.carrier = "tmobile";
    bidRequest.setId("123");
    bidRequest.setDevice(device);
    mockAdRequestInput.setBidRequest(bidRequest);
    URLComponents urlComponents = new URLComponents("", mockAdRequestInput);
    String expected = "openrtb=%7B%22id%22%3A%22123%22%2C%22device%22%3A%7B%22carrier%22%3A%22tmobile%22%7D%7D";
    assertEquals(expected, urlComponents.getQueryArgString());
}
Also used : AdRequestInput(org.prebid.mobile.rendering.networking.parameters.AdRequestInput) Device(org.prebid.mobile.rendering.models.openrtb.bidRequests.Device) BidRequest(org.prebid.mobile.rendering.models.openrtb.BidRequest) Test(org.junit.Test)

Example 2 with AdRequestInput

use of org.prebid.mobile.rendering.networking.parameters.AdRequestInput in project prebid-mobile-android by prebid.

the class URLComponentsTest method getQueryArgStringThrowsException_EmptyString.

/**
 * Tests when JSONException is thrown and the OpenRTB object is not appended to query arg string and the result query is empty
 */
@Test
public void getQueryArgStringThrowsException_EmptyString() throws Exception {
    BidRequest mockBidRequest = mock(BidRequest.class);
    when(mockBidRequest.getJsonObject()).thenThrow(new JSONException((String) null));
    when(mockBidRequest.getApp()).thenCallRealMethod();
    mockBidRequest.getApp().name = "ignored";
    AdRequestInput mockAdRequestInput = mock(AdRequestInput.class);
    when(mockAdRequestInput.getBidRequest()).thenReturn(mockBidRequest);
    URLComponents urlComponents = new URLComponents("", mockAdRequestInput);
    assertTrue(urlComponents.getQueryArgString().isEmpty());
}
Also used : AdRequestInput(org.prebid.mobile.rendering.networking.parameters.AdRequestInput) JSONException(org.json.JSONException) BidRequest(org.prebid.mobile.rendering.models.openrtb.BidRequest) Test(org.junit.Test)

Example 3 with AdRequestInput

use of org.prebid.mobile.rendering.networking.parameters.AdRequestInput in project prebid-mobile-android by prebid.

the class AutoDetectedOpenRtbTest method overwrittenGeoLocationParameterBuilderTest.

@Test
public void overwrittenGeoLocationParameterBuilderTest() {
    mOriginalOpenRtbParams.getDevice().getGeo().lat = 0f;
    mOriginalOpenRtbParams.getDevice().getGeo().lon = 0f;
    mOriginalOpenRtbParams.getDevice().getGeo().type = 0;
    mOriginalAdRequestInput.setBidRequest(mOriginalOpenRtbParams);
    mParamBuilderArray.add(new GeoLocationParameterBuilder());
    AdRequestInput newAdRequestInput = URLBuilder.buildParameters(mParamBuilderArray, mOriginalAdRequestInput);
    BidRequest newOpenRtbParams = newAdRequestInput.getBidRequest();
    assertNotEquals(mOriginalOpenRtbParams.getDevice().getGeo().lat, newOpenRtbParams.getDevice().getGeo().lat);
    assertNotEquals(mOriginalOpenRtbParams.getDevice().getGeo().lon, newOpenRtbParams.getDevice().getGeo().lon);
    assertNotEquals(mOriginalOpenRtbParams.getDevice().getGeo().type, newOpenRtbParams.getDevice().getGeo().type);
}
Also used : AdRequestInput(org.prebid.mobile.rendering.networking.parameters.AdRequestInput) GeoLocationParameterBuilder(org.prebid.mobile.rendering.networking.parameters.GeoLocationParameterBuilder) BidRequest(org.prebid.mobile.rendering.models.openrtb.BidRequest) Test(org.junit.Test)

Example 4 with AdRequestInput

use of org.prebid.mobile.rendering.networking.parameters.AdRequestInput in project prebid-mobile-android by prebid.

the class AutoDetectedOpenRtbTest method setup.

@Before
public void setup() {
    mActivity = Robolectric.buildActivity(Activity.class).create().get();
    ShadowActivity shadowActivity = shadowOf(mActivity);
    shadowActivity.grantPermissions("android.permission.ACCESS_FINE_LOCATION");
    LocationManager locationManager = (LocationManager) mActivity.getSystemService(Context.LOCATION_SERVICE);
    ShadowLocationManager shadowLocationManager = shadowOf(locationManager);
    Location location = new Location("");
    location.setLatitude(1);
    location.setLongitude(1);
    shadowLocationManager.setLastKnownLocation("gps", location);
    ShadowTelephonyManager shadowTelephonyManager = shadowOf((TelephonyManager) mActivity.getSystemService(Context.TELEPHONY_SERVICE));
    shadowTelephonyManager.setNetworkOperatorName("carrier");
    shadowTelephonyManager.setNetworkOperator("carrier");
    ManagersResolver.getInstance().prepare(mActivity);
    mParamBuilderArray = new ArrayList<>();
    mOriginalAdRequestInput = new AdRequestInput();
    mOriginalOpenRtbParams = new BidRequest();
}
Also used : ShadowLocationManager(org.robolectric.shadows.ShadowLocationManager) LocationManager(android.location.LocationManager) AdRequestInput(org.prebid.mobile.rendering.networking.parameters.AdRequestInput) ShadowTelephonyManager(org.robolectric.shadows.ShadowTelephonyManager) ShadowLocationManager(org.robolectric.shadows.ShadowLocationManager) ShadowActivity(org.robolectric.shadows.ShadowActivity) Activity(android.app.Activity) ShadowActivity(org.robolectric.shadows.ShadowActivity) Location(android.location.Location) BidRequest(org.prebid.mobile.rendering.models.openrtb.BidRequest) Before(org.junit.Before)

Example 5 with AdRequestInput

use of org.prebid.mobile.rendering.networking.parameters.AdRequestInput in project prebid-mobile-android by prebid.

the class AutoDetectedOpenRtbTest method overwrittenNetworkParameterBuilder.

@Test
public void overwrittenNetworkParameterBuilder() {
    mOriginalOpenRtbParams.getDevice().mccmnc = "foo";
    mOriginalOpenRtbParams.getDevice().carrier = "foo";
    mOriginalOpenRtbParams.getDevice().connectiontype = 0;
    mParamBuilderArray.add(new NetworkParameterBuilder());
    AdRequestInput newAdRequestInput = URLBuilder.buildParameters(mParamBuilderArray, mOriginalAdRequestInput);
    BidRequest newOpenRtbParams = newAdRequestInput.getBidRequest();
    assertNotEquals(mOriginalOpenRtbParams.getDevice().mccmnc, newOpenRtbParams.getDevice().mccmnc);
    assertNotEquals(mOriginalOpenRtbParams.getDevice().carrier, newOpenRtbParams.getDevice().carrier);
    assertNotEquals(mOriginalOpenRtbParams.getDevice().connectiontype, newOpenRtbParams.getDevice().connectiontype);
}
Also used : AdRequestInput(org.prebid.mobile.rendering.networking.parameters.AdRequestInput) NetworkParameterBuilder(org.prebid.mobile.rendering.networking.parameters.NetworkParameterBuilder) BidRequest(org.prebid.mobile.rendering.models.openrtb.BidRequest) Test(org.junit.Test)

Aggregations

AdRequestInput (org.prebid.mobile.rendering.networking.parameters.AdRequestInput)14 Test (org.junit.Test)10 BidRequest (org.prebid.mobile.rendering.models.openrtb.BidRequest)8 AdConfiguration (org.prebid.mobile.rendering.models.AdConfiguration)3 Activity (android.app.Activity)2 Before (org.junit.Before)2 Location (android.location.Location)1 LocationManager (android.location.LocationManager)1 ArrayList (java.util.ArrayList)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 Device (org.prebid.mobile.rendering.models.openrtb.bidRequests.Device)1 BidRequester (org.prebid.mobile.rendering.networking.modelcontrollers.BidRequester)1 AppInfoParameterBuilder (org.prebid.mobile.rendering.networking.parameters.AppInfoParameterBuilder)1 DeviceInfoParameterBuilder (org.prebid.mobile.rendering.networking.parameters.DeviceInfoParameterBuilder)1 GeoLocationParameterBuilder (org.prebid.mobile.rendering.networking.parameters.GeoLocationParameterBuilder)1 NetworkParameterBuilder (org.prebid.mobile.rendering.networking.parameters.NetworkParameterBuilder)1 ParameterBuilder (org.prebid.mobile.rendering.networking.parameters.ParameterBuilder)1 ShadowActivity (org.robolectric.shadows.ShadowActivity)1 ShadowLocationManager (org.robolectric.shadows.ShadowLocationManager)1