Search in sources :

Example 1 with VastExtractorResult

use of org.prebid.mobile.rendering.models.internal.VastExtractorResult 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 VastExtractorResult

use of org.prebid.mobile.rendering.models.internal.VastExtractorResult 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 3 with VastExtractorResult

use of org.prebid.mobile.rendering.models.internal.VastExtractorResult in project prebid-mobile-android by prebid.

the class VastParserExtractorTest method extractAndWrapperLimitReached_CallOnFailedToLoad.

@Test
public void extractAndWrapperLimitReached_CallOnFailedToLoad() throws IllegalAccessException, IOException {
    String responseString = ResourceUtils.convertResourceToString("vast_wrapper_linear_nonlinear.xml");
    WhiteBox.field(VastParserExtractor.class, "mVastWrapperCount").set(mVastParserExtractor, 5);
    final AdException exception = new AdException(INTERNAL_ERROR, WRAPPER_LIMIT_REACH_ERROR.toString());
    mVastParserExtractor.extract(responseString);
    ArgumentCaptor<VastExtractorResult> argument = ArgumentCaptor.forClass(VastExtractorResult.class);
    verify(mMockListener).onResult(argument.capture());
    final VastExtractorResult value = argument.getValue();
    assertTrue(value.hasException());
    assertEquals(exception.getMessage(), value.getAdException().getMessage());
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) VastExtractorResult(org.prebid.mobile.rendering.models.internal.VastExtractorResult) AdException(org.prebid.mobile.rendering.errors.AdException) Test(org.junit.Test)

Aggregations

VastExtractorResult (org.prebid.mobile.rendering.models.internal.VastExtractorResult)3 AdException (org.prebid.mobile.rendering.errors.AdException)2 AdResponseParserBase (org.prebid.mobile.rendering.parser.AdResponseParserBase)2 Field (java.lang.reflect.Field)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)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 AdResponseParserVast (org.prebid.mobile.rendering.parser.AdResponseParserVast)1