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));
}
}
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);
}
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());
}
Aggregations