Search in sources :

Example 1 with AdResponseParserBase

use of org.prebid.mobile.rendering.parser.AdResponseParserBase in project prebid-mobile-android by prebid.

the class VastParserExtractor method performVastUnwrap.

private void performVastUnwrap(String vast) {
    if (!vast.contains("VAST version")) {
        final AdException adException = new AdException(AdException.INTERNAL_ERROR, VASTErrorCodes.VAST_SCHEMA_ERROR.toString());
        mListener.onResult(createExtractorFailureResult(adException));
        return;
    }
    mVastWrapperCount++;
    // A new response has come back, either from the initial VAST request or a wrapper request.
    // Parse the response.
    AdResponseParserVast adResponseParserVast;
    try {
        adResponseParserVast = new AdResponseParserVast(vast);
    } catch (VastParseError e) {
        LogUtil.error(TAG, "AdResponseParserVast creation failed: " + Log.getStackTraceString(e));
        final AdException adException = new AdException(AdException.INTERNAL_ERROR, e.getMessage());
        mListener.onResult(createExtractorFailureResult(adException));
        return;
    }
    // Check if this is the response from the initial request or from unwrapping a wrapper
    if (mRootVastParser == null) {
        // If mRootVastParser doesn't exist then it is the initial VAST request
        LogUtil.debug(TAG, "Initial VAST Request");
        mRootVastParser = adResponseParserVast;
    } else {
        // Otherwise, this is the result of unwrapping a Wrapper.
        LogUtil.debug(TAG, "Unwrapping VAST Wrapper");
        mLatestVastWrapperParser.setWrapper(adResponseParserVast);
    }
    mLatestVastWrapperParser = adResponseParserVast;
    // Check if this response is a wrapper
    String vastUrl = mLatestVastWrapperParser.getVastUrl();
    if (!TextUtils.isEmpty(vastUrl)) {
        if (mVastWrapperCount >= WRAPPER_NESTING_LIMIT) {
            final AdException adException = new AdException(AdException.INTERNAL_ERROR, VASTErrorCodes.WRAPPER_LIMIT_REACH_ERROR.toString());
            final VastExtractorResult extractorFailureResult = createExtractorFailureResult(adException);
            mListener.onResult(extractorFailureResult);
            mVastWrapperCount = 0;
            return;
        }
        mAsyncVastLoader.loadVast(vastUrl, mResponseHandler);
    } else {
        final AdResponseParserBase[] parserArray = { mRootVastParser, mLatestVastWrapperParser };
        mListener.onResult(new VastExtractorResult(parserArray));
    }
}
Also used : VastParseError(org.prebid.mobile.rendering.errors.VastParseError) AdResponseParserBase(org.prebid.mobile.rendering.parser.AdResponseParserBase) AdResponseParserVast(org.prebid.mobile.rendering.parser.AdResponseParserVast) VastExtractorResult(org.prebid.mobile.rendering.models.internal.VastExtractorResult) AdException(org.prebid.mobile.rendering.errors.AdException)

Example 2 with AdResponseParserBase

use of org.prebid.mobile.rendering.parser.AdResponseParserBase in project prebid-mobile-android by prebid.

the class CreativeModelsMakerVastTest method testMakeModelsWrapper.

// To test wrappers, we use a mock server to handle the vast wrapper redirect
@Test
public void testMakeModelsWrapper() throws Exception {
    String testWrapperFileName = "test_ad_response_vast_wrapper_macro_ad_tag";
    String testInlineFileName = "vast_inline_linear.xml";
    AppInfoManager.setUserAgent("user-agent");
    // Set mock server response as inline vast
    String inlineVastString = ResourceUtils.convertResourceToString(testInlineFileName);
    MockWebServer mockWebServer = new MockWebServer();
    mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(inlineVastString));
    // Replace vast ad tag macro inside wrapper with mock server URL
    HttpUrl baseUrl = mockWebServer.url("/vast_wrapper");
    String urlString = baseUrl.url().toString();
    String responseString = ResourceUtils.convertResourceToString(testWrapperFileName);
    responseString = responseString.replace("%%VAST_AD_TAG%%", urlString);
    // Set wrapper ad response as parameter for makeModels()
    BaseNetworkTask.GetUrlResult adResponse = new BaseNetworkTask.GetUrlResult();
    adResponse.responseString = responseString;
    List<AdResponseParserBase> parsers = getVastParsers(adResponse);
    AdResponseParserVast rootParser = (AdResponseParserVast) parsers.get(0);
    AdResponseParserVast latestParser = (AdResponseParserVast) parsers.get(1);
    // Execute makeModels()
    CreativeModelsMakerVast creativeModelsMakerVast = new CreativeModelsMakerVast(null, mMockListener);
    creativeModelsMakerVast.makeModels(mAdConfiguration, rootParser, latestParser);
    // Get result
    ArgumentCaptor<CreativeModelsMaker.Result> argumentCaptor = ArgumentCaptor.forClass(CreativeModelsMaker.Result.class);
    verify(mMockListener).onCreativeModelReady(argumentCaptor.capture());
    CreativeModelsMaker.Result result = argumentCaptor.getValue();
    VideoCreativeModel model = (VideoCreativeModel) result.creativeModels.get(0);
    // Assert wrapper specific events
    HashMap<VideoAdEvent.Event, ArrayList<String>> videoEventUrls = model.getVideoEventUrls();
    assertEquals("http://myTrackingURL/wrapper/click", videoEventUrls.get(VideoAdEvent.Event.AD_CLICK).get(0));
    videoEventUrls.get(VideoAdEvent.Event.AD_CLICK).remove(0);
    assertEquals("http://myTrackingURL/wrapper/impression", videoEventUrls.get(VideoAdEvent.Event.AD_IMPRESSION).get(0));
    videoEventUrls.get(VideoAdEvent.Event.AD_IMPRESSION).remove(0);
    assertEquals("http://myTrackingURL/wrapper/creativeView", videoEventUrls.get(VideoAdEvent.Event.AD_CREATIVEVIEW).get(0));
    videoEventUrls.get(VideoAdEvent.Event.AD_CREATIVEVIEW).remove(0);
    // Assert inline
    assertVastInline(result.creativeModels, true);
    mockWebServer.shutdown();
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) BaseNetworkTask(org.prebid.mobile.rendering.networking.BaseNetworkTask) AdResponseParserBase(org.prebid.mobile.rendering.parser.AdResponseParserBase) ArrayList(java.util.ArrayList) AdResponseParserVast(org.prebid.mobile.rendering.parser.AdResponseParserVast) HttpUrl(okhttp3.HttpUrl) VastExtractorResult(org.prebid.mobile.rendering.models.internal.VastExtractorResult) MockWebServer(okhttp3.mockwebserver.MockWebServer) VideoAdEvent(org.prebid.mobile.rendering.video.VideoAdEvent) VideoCreativeModel(org.prebid.mobile.rendering.video.VideoCreativeModel) Test(org.junit.Test)

Example 3 with AdResponseParserBase

use of org.prebid.mobile.rendering.parser.AdResponseParserBase in project prebid-mobile-android by prebid.

the class CreativeModelsMakerVastTest method getVastParsers.

private List<AdResponseParserBase> getVastParsers(BaseNetworkTask.GetUrlResult adResponse) throws NoSuchFieldException, IllegalAccessException {
    final VastParserExtractor.Listener mockListener = mock(VastParserExtractor.Listener.class);
    VastParserExtractor parserExtractor = new VastParserExtractor(mockListener);
    AsyncVastLoader asyncVastLoader = spy(new AsyncVastLoader());
    Field requesterVastField = VastParserExtractor.class.getDeclaredField("mAsyncVastLoader");
    requesterVastField.setAccessible(true);
    requesterVastField.set(parserExtractor, asyncVastLoader);
    parserExtractor.extract(adResponse.responseString);
    ArgumentCaptor<VastExtractorResult> varArgsCapture = ArgumentCaptor.forClass(VastExtractorResult.class);
    verify(mockListener).onResult(varArgsCapture.capture());
    final AdResponseParserBase[] vastResponseParserArray = varArgsCapture.getValue().getVastResponseParserArray();
    return Arrays.asList(vastResponseParserArray);
}
Also used : Field(java.lang.reflect.Field) AsyncVastLoader(org.prebid.mobile.rendering.networking.modelcontrollers.AsyncVastLoader) VastParserExtractor(org.prebid.mobile.rendering.loading.VastParserExtractor) AdResponseParserBase(org.prebid.mobile.rendering.parser.AdResponseParserBase) VastExtractorResult(org.prebid.mobile.rendering.models.internal.VastExtractorResult)

Example 4 with AdResponseParserBase

use of org.prebid.mobile.rendering.parser.AdResponseParserBase in project prebid-mobile-android by prebid.

the class CreativeModelsMakerVastTest method testNonOptInCompanion.

@Test
public void testNonOptInCompanion() throws Exception {
    String testFileName = "vast_inline_linear.xml";
    BaseNetworkTask.GetUrlResult adResponse = new BaseNetworkTask.GetUrlResult();
    adResponse.responseString = ResourceUtils.convertResourceToString(testFileName);
    CreativeModelsMakerVast creativeModelsMakerVast = new CreativeModelsMakerVast(null, mMockListener);
    List<AdResponseParserBase> parsers = getVastParsers(adResponse);
    AdResponseParserVast rootParser = (AdResponseParserVast) parsers.get(0);
    AdResponseParserVast latestParser = (AdResponseParserVast) parsers.get(1);
    // Valid - Inline, non-opt-in
    mAdConfiguration.setRewarded(false);
    creativeModelsMakerVast.makeModels(mAdConfiguration, rootParser, latestParser);
    ArgumentCaptor<CreativeModelsMaker.Result> argumentCaptor = ArgumentCaptor.forClass(CreativeModelsMaker.Result.class);
    verify(mMockListener).onCreativeModelReady(argumentCaptor.capture());
    CreativeModelsMaker.Result result = argumentCaptor.getValue();
    // Expect only two video creative model, because contains companion ad
    assertEquals(2, result.creativeModels.size());
    assertTrue(result.creativeModels.get(0) instanceof VideoCreativeModel);
}
Also used : BaseNetworkTask(org.prebid.mobile.rendering.networking.BaseNetworkTask) AdResponseParserBase(org.prebid.mobile.rendering.parser.AdResponseParserBase) AdResponseParserVast(org.prebid.mobile.rendering.parser.AdResponseParserVast) VastExtractorResult(org.prebid.mobile.rendering.models.internal.VastExtractorResult) VideoCreativeModel(org.prebid.mobile.rendering.video.VideoCreativeModel) Test(org.junit.Test)

Example 5 with AdResponseParserBase

use of org.prebid.mobile.rendering.parser.AdResponseParserBase in project prebid-mobile-android by prebid.

the class CreativeModelsMakerVastTest method testMakeModelsInline.

@Test
public void testMakeModelsInline() throws Exception {
    String testFileName = "vast_inline_linear.xml";
    BaseNetworkTask.GetUrlResult adResponse = new BaseNetworkTask.GetUrlResult();
    adResponse.responseString = ResourceUtils.convertResourceToString(testFileName);
    CreativeModelsMakerVast creativeModelsMakerVast = new CreativeModelsMakerVast(null, mMockListener);
    List<AdResponseParserBase> parsers = getVastParsers(adResponse);
    AdResponseParserVast rootParser = (AdResponseParserVast) parsers.get(0);
    AdResponseParserVast latestParser = (AdResponseParserVast) parsers.get(1);
    // Null ad configuration
    creativeModelsMakerVast.makeModels(null, rootParser, latestParser);
    verify(mMockListener).onFailedToLoadAd(any(AdException.class), any());
    // Valid - Inline
    creativeModelsMakerVast.makeModels(mAdConfiguration, rootParser, latestParser);
    ArgumentCaptor<CreativeModelsMaker.Result> argumentCaptor = ArgumentCaptor.forClass(CreativeModelsMaker.Result.class);
    verify(mMockListener).onCreativeModelReady(argumentCaptor.capture());
    CreativeModelsMaker.Result result = argumentCaptor.getValue();
    assertVastInline(result.creativeModels, false);
}
Also used : BaseNetworkTask(org.prebid.mobile.rendering.networking.BaseNetworkTask) AdResponseParserBase(org.prebid.mobile.rendering.parser.AdResponseParserBase) AdResponseParserVast(org.prebid.mobile.rendering.parser.AdResponseParserVast) AdException(org.prebid.mobile.rendering.errors.AdException) VastExtractorResult(org.prebid.mobile.rendering.models.internal.VastExtractorResult) Test(org.junit.Test)

Aggregations

VastExtractorResult (org.prebid.mobile.rendering.models.internal.VastExtractorResult)5 AdResponseParserBase (org.prebid.mobile.rendering.parser.AdResponseParserBase)5 AdResponseParserVast (org.prebid.mobile.rendering.parser.AdResponseParserVast)4 Test (org.junit.Test)3 BaseNetworkTask (org.prebid.mobile.rendering.networking.BaseNetworkTask)3 AdException (org.prebid.mobile.rendering.errors.AdException)2 VideoCreativeModel (org.prebid.mobile.rendering.video.VideoCreativeModel)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 HttpUrl (okhttp3.HttpUrl)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 MockWebServer (okhttp3.mockwebserver.MockWebServer)1 VastParseError (org.prebid.mobile.rendering.errors.VastParseError)1 VastParserExtractor (org.prebid.mobile.rendering.loading.VastParserExtractor)1 AsyncVastLoader (org.prebid.mobile.rendering.networking.modelcontrollers.AsyncVastLoader)1 VideoAdEvent (org.prebid.mobile.rendering.video.VideoAdEvent)1