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