Search in sources :

Example 1 with AdResponseParserVast

use of org.prebid.mobile.rendering.parser.AdResponseParserVast 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 AdResponseParserVast

use of org.prebid.mobile.rendering.parser.AdResponseParserVast 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 AdResponseParserVast

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

the class VastParserExtractorTest method extractAndRootParserNotNull_SetWrapperToLatestParser.

@Test
public void extractAndRootParserNotNull_SetWrapperToLatestParser() throws IllegalAccessException {
    AdResponseParserVast mockParser = mock(AdResponseParserVast.class);
    WhiteBox.field(VastParserExtractor.class, "mRootVastParser").set(mVastParserExtractor, mMockResponseParserVast);
    WhiteBox.field(VastParserExtractor.class, "mLatestVastWrapperParser").set(mVastParserExtractor, mockParser);
    mVastParserExtractor.extract(mDefaultResponseString);
    verify(mockParser).setWrapper(any(AdResponseParserVast.class));
}
Also used : AdResponseParserVast(org.prebid.mobile.rendering.parser.AdResponseParserVast) Test(org.junit.Test)

Example 4 with AdResponseParserVast

use of org.prebid.mobile.rendering.parser.AdResponseParserVast 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 AdResponseParserVast

use of org.prebid.mobile.rendering.parser.AdResponseParserVast 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

AdResponseParserVast (org.prebid.mobile.rendering.parser.AdResponseParserVast)5 Test (org.junit.Test)4 VastExtractorResult (org.prebid.mobile.rendering.models.internal.VastExtractorResult)4 AdResponseParserBase (org.prebid.mobile.rendering.parser.AdResponseParserBase)4 BaseNetworkTask (org.prebid.mobile.rendering.networking.BaseNetworkTask)3 AdException (org.prebid.mobile.rendering.errors.AdException)2 VideoCreativeModel (org.prebid.mobile.rendering.video.VideoCreativeModel)2 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 VideoAdEvent (org.prebid.mobile.rendering.video.VideoAdEvent)1