Search in sources :

Example 1 with GetUrlResult

use of org.prebid.mobile.rendering.networking.BaseNetworkTask.GetUrlResult in project prebid-mobile-android by prebid.

the class GetOriginalUrlTaskTest method getUrlNullParamsTest.

@Test
public void getUrlNullParamsTest() throws Exception {
    GetOriginalUrlTask getOriginalUrlNetworkTask = new GetOriginalUrlTask(null);
    mParams = null;
    GetUrlResult result = (GetUrlResult) WhiteBox.method(GetOriginalUrlTask.class, "getUrl", BaseNetworkTask.GetUrlParams.class).invoke(getOriginalUrlNetworkTask, mParams);
    assertNotNull("A null params object should generate a result object with Exception", result.getException());
}
Also used : BaseNetworkTask(org.prebid.mobile.rendering.networking.BaseNetworkTask) GetUrlResult(org.prebid.mobile.rendering.networking.BaseNetworkTask.GetUrlResult) Test(org.junit.Test)

Example 2 with GetUrlResult

use of org.prebid.mobile.rendering.networking.BaseNetworkTask.GetUrlResult in project prebid-mobile-android by prebid.

the class GetOriginalUrlTaskTest method getUrlTest.

@Test
public void getUrlTest() throws Exception {
    mServer.enqueue(new MockResponse().setResponseCode(200).setBody("this is a success response"));
    GetOriginalUrlTask getOriginalUrlNetworkTask = new GetOriginalUrlTask(null);
    HttpUrl baseUrl = mServer.url("/first");
    mParams.url = baseUrl.url().toString();
    BaseNetworkTask.GetUrlParams[] params = { mParams };
    GetUrlResult result = (GetUrlResult) WhiteBox.method(GetOriginalUrlTask.class, "getUrl", BaseNetworkTask.GetUrlParams[].class).invoke(getOriginalUrlNetworkTask, (Object) new BaseNetworkTask.GetUrlParams[] { mParams });
    Assert.assertEquals("A successful response should yile a result object with status code 200", result.statusCode, 200);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) BaseNetworkTask(org.prebid.mobile.rendering.networking.BaseNetworkTask) HttpUrl(okhttp3.HttpUrl) GetUrlResult(org.prebid.mobile.rendering.networking.BaseNetworkTask.GetUrlResult) Test(org.junit.Test)

Example 3 with GetUrlResult

use of org.prebid.mobile.rendering.networking.BaseNetworkTask.GetUrlResult in project prebid-mobile-android by prebid.

the class GetOriginalUrlTaskTest method getUrlOriginalUrlShouldBeSetTest.

@Test
public void getUrlOriginalUrlShouldBeSetTest() throws Exception {
    mServer.enqueue(new MockResponse().setResponseCode(301).addHeader("Location: " + mServer.url("/new-path")).setBody("This page has moved!"));
    mServer.enqueue(new MockResponse().setResponseCode(200).setBody("This is the new location"));
    GetOriginalUrlTask getOriginalUrlNetworkTask = new GetOriginalUrlTask(null);
    HttpUrl baseUrl = mServer.url("/first");
    mParams.url = baseUrl.url().toString();
    GetUrlResult result = (GetUrlResult) WhiteBox.method(GetOriginalUrlTask.class, "getUrl", BaseNetworkTask.GetUrlParams[].class).invoke(getOriginalUrlNetworkTask, (Object) new BaseNetworkTask.GetUrlParams[] { mParams });
    Assert.assertNotNull("Original url should not be null", result.originalUrl);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) BaseNetworkTask(org.prebid.mobile.rendering.networking.BaseNetworkTask) HttpUrl(okhttp3.HttpUrl) GetUrlResult(org.prebid.mobile.rendering.networking.BaseNetworkTask.GetUrlResult) Test(org.junit.Test)

Example 4 with GetUrlResult

use of org.prebid.mobile.rendering.networking.BaseNetworkTask.GetUrlResult in project prebid-mobile-android by prebid.

the class GetOriginalUrlTaskTest method processRedirectsMaxOf3RedirectsTest.

@Test
public void processRedirectsMaxOf3RedirectsTest() throws Exception {
    mServer.enqueue(new MockResponse().setResponseCode(301).addHeader("Location: " + mServer.url("/second")).setBody("This page has moved!"));
    mServer.enqueue(new MockResponse().setResponseCode(301).addHeader("Location: " + mServer.url("/third")).setBody("This page has moved!"));
    mServer.enqueue(new MockResponse().setResponseCode(301).addHeader("Location: " + mServer.url("/fourth")).setBody("This page has moved!"));
    mServer.enqueue(new MockResponse().setResponseCode(301).addHeader("Location: " + mServer.url("/fifth")).setBody("This page has moved!"));
    mServer.enqueue(new MockResponse().setResponseCode(200).setBody("This is the new location"));
    GetOriginalUrlTask getOriginalUrlNetworkTask = new GetOriginalUrlTask(null);
    HttpUrl baseUrl = mServer.url("/first");
    mParams.url = baseUrl.url().toString();
    mParams.name = REDIRECT_TASK;
    WhiteBox.method(GetOriginalUrlTask.class, "processRedirects", BaseNetworkTask.GetUrlParams.class).invoke(getOriginalUrlNetworkTask, mParams);
    GetUrlResult result = (GetUrlResult) WhiteBox.getInternalState(getOriginalUrlNetworkTask, "mResult");
    Assert.assertNull("Should not have a valid result.response if over max redirects ", result.responseString);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) HttpUrl(okhttp3.HttpUrl) GetUrlResult(org.prebid.mobile.rendering.networking.BaseNetworkTask.GetUrlResult) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 GetUrlResult (org.prebid.mobile.rendering.networking.BaseNetworkTask.GetUrlResult)4 HttpUrl (okhttp3.HttpUrl)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 BaseNetworkTask (org.prebid.mobile.rendering.networking.BaseNetworkTask)3