Search in sources :

Example 1 with VideoCreative

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()));
    }
}
Also used : RewardedVideoCreative(org.prebid.mobile.rendering.video.RewardedVideoCreative) VideoCreative(org.prebid.mobile.rendering.video.VideoCreative) RewardedVideoCreative(org.prebid.mobile.rendering.video.RewardedVideoCreative) VideoAdEvent(org.prebid.mobile.rendering.video.VideoAdEvent) AdException(org.prebid.mobile.rendering.errors.AdException) VideoCreativeModel(org.prebid.mobile.rendering.video.VideoCreativeModel) AdException(org.prebid.mobile.rendering.errors.AdException)

Example 2 with VideoCreative

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();
}
Also used : VideoCreative(org.prebid.mobile.rendering.video.VideoCreative) Transaction(org.prebid.mobile.rendering.loading.Transaction) TransactionManager(org.prebid.mobile.rendering.loading.TransactionManager) AdConfiguration(org.prebid.mobile.rendering.models.AdConfiguration) ArrayList(java.util.ArrayList) CreativeFactory(org.prebid.mobile.rendering.loading.CreativeFactory) VideoCreativeModel(org.prebid.mobile.rendering.video.VideoCreativeModel) Test(org.junit.Test)

Example 3 with VideoCreative

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());
}
Also used : VideoCreative(org.prebid.mobile.rendering.video.VideoCreative) Test(org.junit.Test)

Example 4 with VideoCreative

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));
}
Also used : AbstractCreative(org.prebid.mobile.rendering.models.AbstractCreative) VideoCreative(org.prebid.mobile.rendering.video.VideoCreative) HashMap(java.util.HashMap) AdConfiguration(org.prebid.mobile.rendering.models.AdConfiguration) ArrayList(java.util.ArrayList) Handler(android.os.Handler) VideoAdEvent(org.prebid.mobile.rendering.video.VideoAdEvent) VideoCreativeModel(org.prebid.mobile.rendering.video.VideoCreativeModel) Test(org.junit.Test)

Example 5 with VideoCreative

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);
}
Also used : VideoCreative(org.prebid.mobile.rendering.video.VideoCreative) InvocationOnMock(org.mockito.invocation.InvocationOnMock) VideoCreativeModel(org.prebid.mobile.rendering.video.VideoCreativeModel) Test(org.junit.Test)

Aggregations

VideoCreative (org.prebid.mobile.rendering.video.VideoCreative)7 Test (org.junit.Test)5 VideoCreativeModel (org.prebid.mobile.rendering.video.VideoCreativeModel)4 ArrayList (java.util.ArrayList)2 InterstitialView (org.prebid.mobile.rendering.bidding.display.InterstitialView)2 AdConfiguration (org.prebid.mobile.rendering.models.AdConfiguration)2 VideoAdEvent (org.prebid.mobile.rendering.video.VideoAdEvent)2 Handler (android.os.Handler)1 View (android.view.View)1 HashMap (java.util.HashMap)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 AdException (org.prebid.mobile.rendering.errors.AdException)1 CreativeFactory (org.prebid.mobile.rendering.loading.CreativeFactory)1 Transaction (org.prebid.mobile.rendering.loading.Transaction)1 TransactionManager (org.prebid.mobile.rendering.loading.TransactionManager)1 AbstractCreative (org.prebid.mobile.rendering.models.AbstractCreative)1 RewardedVideoCreative (org.prebid.mobile.rendering.video.RewardedVideoCreative)1 VideoCreativeView (org.prebid.mobile.rendering.video.VideoCreativeView)1 PrebidWebViewInterstitial (org.prebid.mobile.rendering.views.webview.PrebidWebViewInterstitial)1 WebViewBase (org.prebid.mobile.rendering.views.webview.WebViewBase)1