VastManager implements VastXmlManagerAggregatorListener { public void prepareVastVideoConfiguration(final String vastXml, final VastManagerListener vastManagerListener) { if (mVastXmlManagerAggregator == null) { mVastManagerListener = vastManagerListener; mVastXmlManagerAggregator = new VastXmlManagerAggregator(this); try { AsyncTasks.safeExecuteOnExecutor(mVastXmlManagerAggregator, vastXml); } catch (Exception e) { MoPubLog.d("Failed to aggregate vast xml", e); mVastManagerListener.onVastVideoConfigurationPrepared(null); } } } VastManager(final Context context); void prepareVastVideoConfiguration(final String vastXml, final VastManagerListener vastManagerListener); void cancel(); @Override void onAggregationComplete(final List<VastXmlManager> vastXmlManagers);  }
@Test public void prepareVastVideoConfiguration_shouldNotifyTheListenerAndContainTheCorrectVastValues() throws Exception { mFakeHttpLayer.addPendingHttpResponse(200, TEST_NESTED_VAST_XML_STRING); mFakeHttpLayer.addPendingHttpResponse(200, "video_data"); prepareVastVideoConfiguration(); semaphore.acquire(); verify(vastManagerListener).onVastVideoConfigurationPrepared(any(VastVideoConfiguration.class)); assertThat(vastVideoConfiguration.getNetworkMediaFileUrl()).isEqualTo("https: final String expectedFilePathDiskCache = CacheService.getFilePathDiskCache(vastVideoConfiguration.getNetworkMediaFileUrl()); assertThat(vastVideoConfiguration.getDiskMediaFileUrl()).isEqualTo(expectedFilePathDiskCache); assertThat(vastVideoConfiguration.getClickThroughUrl()).isEqualTo("http: assertThat(vastVideoConfiguration.getImpressionTrackers().size()).isEqualTo(5); assertThat(vastVideoConfiguration.getStartTrackers().size()).isEqualTo(1); assertThat(vastVideoConfiguration.getFirstQuartileTrackers().size()).isEqualTo(1); assertThat(vastVideoConfiguration.getMidpointTrackers().size()).isEqualTo(1); assertThat(vastVideoConfiguration.getThirdQuartileTrackers().size()).isEqualTo(1); assertThat(vastVideoConfiguration.getCompleteTrackers().size()).isEqualTo(1); assertThat(vastVideoConfiguration.getClickTrackers().size()).isEqualTo(1); final VastCompanionAd vastCompanionAd = vastVideoConfiguration.getVastCompanionAd(); assertThat(vastCompanionAd.getWidth()).isEqualTo(300); assertThat(vastCompanionAd.getHeight()).isEqualTo(250); assertThat(vastCompanionAd.getImageUrl()).isEqualTo("http: assertThat(vastCompanionAd.getClickThroughUrl()).isEqualTo("http: assertThat(vastCompanionAd.getClickTrackers()) .containsOnly("http: }
@Test public void prepareVastVideoConfiguration_shouldHandleMultipleRedirects() throws Exception { mFakeHttpLayer.addPendingHttpResponse(200, TEST_VAST_XML_STRING); mFakeHttpLayer.addPendingHttpResponse(200, TEST_VAST_XML_STRING); mFakeHttpLayer.addPendingHttpResponse(200, TEST_NESTED_VAST_XML_STRING); mFakeHttpLayer.addPendingHttpResponse(200, "video_data"); prepareVastVideoConfiguration(); semaphore.acquire(); verify(vastManagerListener).onVastVideoConfigurationPrepared(any(VastVideoConfiguration.class)); assertThat(vastVideoConfiguration.getNetworkMediaFileUrl()).isEqualTo("https: final String expectedFilePathDiskCache = CacheService.getFilePathDiskCache(vastVideoConfiguration.getNetworkMediaFileUrl()); assertThat(vastVideoConfiguration.getDiskMediaFileUrl()).isEqualTo(expectedFilePathDiskCache); assertThat(vastVideoConfiguration.getClickThroughUrl()).isEqualTo("http: assertThat(vastVideoConfiguration.getImpressionTrackers().size()).isEqualTo(13); assertThat(vastVideoConfiguration.getStartTrackers().size()).isEqualTo(3); assertThat(vastVideoConfiguration.getFirstQuartileTrackers().size()).isEqualTo(3); assertThat(vastVideoConfiguration.getMidpointTrackers().size()).isEqualTo(3); assertThat(vastVideoConfiguration.getThirdQuartileTrackers().size()).isEqualTo(3); assertThat(vastVideoConfiguration.getCompleteTrackers().size()).isEqualTo(3); assertThat(vastVideoConfiguration.getClickTrackers().size()).isEqualTo(3); final VastCompanionAd vastCompanionAd = vastVideoConfiguration.getVastCompanionAd(); assertThat(vastCompanionAd.getWidth()).isEqualTo(300); assertThat(vastCompanionAd.getHeight()).isEqualTo(250); assertThat(vastCompanionAd.getImageUrl()).isEqualTo("http: assertThat(vastCompanionAd.getClickThroughUrl()).isEqualTo("http: assertThat(vastCompanionAd.getClickTrackers()) .containsOnly("http: }
@Test public void prepareVastVideoConfiguration_shouldReturnCorrectVastValuesWhenAVastRedirectFails() throws Exception { mFakeHttpLayer.addPendingHttpResponse(404, ""); mFakeHttpLayer.addPendingHttpResponse(200, "video_data"); prepareVastVideoConfiguration(); semaphore.acquire(); verify(vastManagerListener).onVastVideoConfigurationPrepared(any(VastVideoConfiguration.class)); assertThat(vastVideoConfiguration.getNetworkMediaFileUrl()).isEqualTo("https: final String expectedFilePathDiskCache = CacheService.getFilePathDiskCache(vastVideoConfiguration.getNetworkMediaFileUrl()); assertThat(vastVideoConfiguration.getDiskMediaFileUrl()).isEqualTo(expectedFilePathDiskCache); assertThat(vastVideoConfiguration.getClickThroughUrl()).isEqualTo(null); assertThat(vastVideoConfiguration.getImpressionTrackers().size()).isEqualTo(4); assertThat(vastVideoConfiguration.getFirstQuartileTrackers().size()).isEqualTo(1); }