use of org.prebid.mobile.rendering.video.VideoCreative in project prebid-mobile-android by prebid.
the class CreativeFactory method attemptVastCreative.
private void attemptVastCreative() {
VideoCreativeModel videoCreativeModel = (VideoCreativeModel) mCreativeModel;
String mediaUrl = videoCreativeModel.getMediaUrl();
if (Utils.isBlank(mediaUrl) || mediaUrl.equals("invalid media file")) {
mListener.onFailure(new AdException(AdException.INTERNAL_ERROR, VASTErrorCodes.NO_SUPPORTED_MEDIA_ERROR.toString()));
return;
}
// get the tracking url for all event types & do the registration here.
for (VideoAdEvent.Event videoEvent : VideoAdEvent.Event.values()) {
videoCreativeModel.registerVideoEvent(videoEvent, videoCreativeModel.getVideoEventUrls().get(videoEvent));
}
VideoCreative newCreative;
try {
if (mCreativeModel.getAdConfiguration().isRewarded()) {
newCreative = new RewardedVideoCreative(mContextReference.get(), videoCreativeModel, mOmAdSessionManager, mInterstitialManager);
} else {
newCreative = new VideoCreative(mContextReference.get(), videoCreativeModel, mOmAdSessionManager, mInterstitialManager);
}
newCreative.setResolutionListener(new CreativeFactoryCreativeResolutionListener(this));
mCreative = newCreative;
markWorkStart(VAST_TIMEOUT);
newCreative.load();
} catch (Exception exception) {
LogUtil.error(TAG, "VideoCreative creation failed: " + Log.getStackTraceString(exception));
mListener.onFailure(new AdException(AdException.INTERNAL_ERROR, "VideoCreative creation failed: " + exception.getMessage()));
}
}
use of org.prebid.mobile.rendering.video.VideoCreative in project prebid-mobile-android by prebid.
the class AdViewManagerTest method creativeDidCompleteTest.
@Test
public void creativeDidCompleteTest() throws Exception {
VideoCreative mockVideoCreative = mock(VideoCreative.class);
when(mockVideoCreative.getCreativeModel()).thenReturn(new VideoCreativeModel(mock(TrackingManager.class), mock(OmEventTracker.class), new AdConfiguration()));
when(mockVideoCreative.isVideo()).thenReturn(true);
Transaction mockTransaction = mock(Transaction.class);
ArrayList<CreativeFactory> creativeFactories = new ArrayList<>();
TransactionManager mockTransactionManager = mock(TransactionManager.class);
when(mockTransactionManager.getCurrentTransaction()).thenReturn(mockTransaction);
when(mockTransaction.getCreativeFactories()).thenReturn(creativeFactories);
WhiteBox.field(AdViewManager.class, "mTransactionManager").set(mAdViewManager, mockTransactionManager);
WhiteBox.field(AdViewManager.class, "mAdView").set(mAdViewManager, mockAdView);
mAdViewManager.creativeDidComplete(mockVideoCreative);
verify(mockAdView).closeInterstitialVideo();
verify(mMockAdViewListener, times(1)).adCompleted();
mAdViewManager.creativeDidComplete(mockVideoCreative);
verify(mMockAdViewListener, times(2)).adCompleted();
}
use of org.prebid.mobile.rendering.video.VideoCreative in project prebid-mobile-android by prebid.
the class AdViewManagerTest method testGetMediaDuration.
@Test
public void testGetMediaDuration() throws IllegalAccessException {
long mediaDuration = mAdViewManager.getMediaDuration();
assertEquals(0, mediaDuration);
VideoCreative videoCreative = mock(VideoCreative.class);
long expectedValue = 15 * 1000;
when(videoCreative.getMediaDuration()).thenReturn(expectedValue);
WhiteBox.field(AdViewManager.class, "mCurrentCreative").set(mAdViewManager, videoCreative);
assertEquals(expectedValue, mAdViewManager.getMediaDuration());
}
use of org.prebid.mobile.rendering.video.VideoCreative in project prebid-mobile-android by prebid.
the class CreativeFactoryTest method testAttemptVastCreative.
@Test
public void testAttemptVastCreative() throws Exception {
VideoCreativeModel mockVideoModel = mock(VideoCreativeModel.class);
AdConfiguration adConfiguration = new AdConfiguration();
Handler mockHandler = mock(Handler.class);
adConfiguration.setAdUnitIdentifierType(AdConfiguration.AdUnitIdentifierType.VAST);
HashMap<VideoAdEvent.Event, ArrayList<String>> videoEventsUrls = new HashMap<>();
videoEventsUrls.put(VideoAdEvent.Event.AD_EXPAND, new ArrayList<>(Arrays.asList("AD_EXPAND")));
when(mockVideoModel.getVideoEventUrls()).thenReturn(videoEventsUrls);
when(mockVideoModel.getAdConfiguration()).thenReturn(adConfiguration);
CreativeFactory creativeFactory;
// Blank media URL
when(mockVideoModel.getMediaUrl()).thenReturn("");
creativeFactory = new CreativeFactory(mMockContext, mockVideoModel, mMockListener, mMockOmAdSessionManager, mMockInterstitialManager);
creativeFactory.start();
assertNull(WhiteBox.getInternalState(creativeFactory, "mCreative"));
// Valid
when(mockVideoModel.getMediaUrl()).thenReturn("mediaUrl");
creativeFactory = new CreativeFactory(mMockContext, mockVideoModel, mMockListener, mMockOmAdSessionManager, mMockInterstitialManager);
WhiteBox.field(CreativeFactory.class, "mTimeoutHandler").set(creativeFactory, mockHandler);
creativeFactory.start();
AbstractCreative creative = creativeFactory.getCreative();
assertNotNull(creative);
assertTrue(creative instanceof VideoCreative);
verify(mockHandler).postDelayed(any(Runnable.class), eq(30_000L));
}
use of org.prebid.mobile.rendering.video.VideoCreative in project prebid-mobile-android by prebid.
the class AdViewManagerTest method testInterstitialClosed.
@Test
public void testInterstitialClosed() throws IllegalAccessException {
assertFalse(mAdViewManager.isInterstitialClosed());
VideoCreative videoCreative = mock(VideoCreative.class);
final VideoCreativeModel videoCreativeModel = mock(VideoCreativeModel.class);
when(videoCreative.getCreativeModel()).thenReturn(videoCreativeModel);
when(videoCreative.isInterstitialClosed()).thenReturn(true);
WhiteBox.field(AdViewManager.class, "mCurrentCreative").set(mAdViewManager, videoCreative);
assertTrue(mAdViewManager.isInterstitialClosed());
when(videoCreativeModel.hasEndCard()).thenReturn(false);
WhiteBox.field(VideoCreative.class, "mModel").set(videoCreative, videoCreativeModel);
when(videoCreative.isInterstitialClosed()).then(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
videoCreativeModel.trackVideoEvent(VideoAdEvent.Event.AD_CLOSE);
return null;
}
});
mAdViewManager.isInterstitialClosed();
verify(videoCreativeModel).trackVideoEvent(VideoAdEvent.Event.AD_CLOSE);
}
Aggregations