Search in sources :

Example 6 with CreativeModel

use of org.prebid.mobile.rendering.models.CreativeModel in project prebid-mobile-android by prebid.

the class TransactionTest method testTransactionInit.

@Test
public void testTransactionInit() throws Exception {
    List<CreativeModel> creativeModels = new ArrayList<>();
    CreativeModel mockCreativeModel = mock(CreativeModel.class);
    creativeModels.add(mockCreativeModel);
    Transaction.Listener mockOxTransactionListener = mock(Transaction.Listener.class);
    // Valid
    InterstitialManager mockInterstitialManager = mock(InterstitialManager.class);
    Transaction transaction = Transaction.createTransaction(mMockContext, createModelResult(creativeModels, "ts"), mockInterstitialManager, mockOxTransactionListener);
    assertNotNull(transaction);
    // No context
    boolean hasException = false;
    try {
        Transaction.createTransaction(null, createModelResult(creativeModels, "ts"), mockInterstitialManager, mockOxTransactionListener);
    } catch (AdException e) {
        hasException = true;
    }
    assertTrue(hasException);
    // No creative models
    hasException = false;
    try {
        Transaction.createTransaction(mMockContext, createModelResult(null, "ts"), mockInterstitialManager, mockOxTransactionListener);
    } catch (AdException e) {
        hasException = true;
    }
    assertTrue(hasException);
    // Empty creative models
    hasException = false;
    try {
        Transaction.createTransaction(mMockContext, createModelResult(new ArrayList<>(), "ts"), mockInterstitialManager, mockOxTransactionListener);
    } catch (AdException e) {
        hasException = true;
    }
    assertTrue(hasException);
    // No listener
    hasException = false;
    try {
        Transaction.createTransaction(mMockContext, createModelResult(creativeModels, "ts"), mockInterstitialManager, null);
    } catch (AdException e) {
        hasException = true;
    }
    assertTrue(hasException);
}
Also used : CreativeModel(org.prebid.mobile.rendering.models.CreativeModel) ArrayList(java.util.ArrayList) InterstitialManager(org.prebid.mobile.rendering.views.interstitial.InterstitialManager) AdException(org.prebid.mobile.rendering.errors.AdException) Test(org.junit.Test)

Example 7 with CreativeModel

use of org.prebid.mobile.rendering.models.CreativeModel in project prebid-mobile-android by prebid.

the class TransactionTest method testStartCreativeFactories.

// Tests that CreativeFactory is started
@Test
public void testStartCreativeFactories() throws Exception {
    CreativeModel mockCreativeModel = mock(CreativeModel.class);
    List<CreativeModel> creativeModels = new ArrayList<>();
    creativeModels.add(mockCreativeModel);
    Transaction.Listener mockOxTransactionListener = mock(Transaction.Listener.class);
    final Transaction transaction = Transaction.createTransaction(mMockContext, createModelResult(creativeModels, "ts"), mock(InterstitialManager.class), mockOxTransactionListener);
    transaction.startCreativeFactories();
    verify(mockOxTransactionListener).onTransactionFailure(any(AdException.class), anyString());
}
Also used : CreativeModel(org.prebid.mobile.rendering.models.CreativeModel) ArrayList(java.util.ArrayList) InterstitialManager(org.prebid.mobile.rendering.views.interstitial.InterstitialManager) AdException(org.prebid.mobile.rendering.errors.AdException) Test(org.junit.Test)

Example 8 with CreativeModel

use of org.prebid.mobile.rendering.models.CreativeModel in project prebid-mobile-android by prebid.

the class PrebidWebViewBannerTest method initTwoPartAndLoadTest.

@Test
public void initTwoPartAndLoadTest() throws IOException {
    mBanner.mCreative = mock(HTMLCreative.class);
    CreativeModel mockModel = mock(CreativeModel.class);
    when(mockModel.getHtml()).thenReturn(ResourceUtils.convertResourceToString("ad_contains_iframe"));
    when(mBanner.mCreative.getCreativeModel()).thenReturn(mockModel);
    mBanner.initTwoPartAndLoad(mAdHTML);
    assertNotNull(mBanner.mMraidWebView);
    assertEquals("twopart", mBanner.mMraidWebView.mMRAIDBridgeName);
}
Also used : CreativeModel(org.prebid.mobile.rendering.models.CreativeModel) HTMLCreative(org.prebid.mobile.rendering.models.HTMLCreative) Test(org.junit.Test)

Example 9 with CreativeModel

use of org.prebid.mobile.rendering.models.CreativeModel in project prebid-mobile-android by prebid.

the class PrebidWebViewInterstitialTest method loadHTMLTest.

@Test
public void loadHTMLTest() throws IOException {
    mPrebidWebViewInterstitial.mCreative = mock(HTMLCreative.class);
    CreativeModel mockModel = mock(CreativeModel.class);
    when(mPrebidWebViewInterstitial.mCreative.getCreativeModel()).thenReturn(mockModel);
    when(mockModel.getHtml()).thenReturn(ResourceUtils.convertResourceToString("ad_contains_iframe"));
    when(mockModel.getAdConfiguration()).thenReturn(new AdConfiguration());
    mPrebidWebViewInterstitial.loadHTML(mAdHTML, 100, 200);
    assertNotNull(mPrebidWebViewInterstitial.mWebView);
    assertEquals("WebViewInterstitial", mPrebidWebViewInterstitial.mWebView.mMRAIDBridgeName);
}
Also used : CreativeModel(org.prebid.mobile.rendering.models.CreativeModel) AdConfiguration(org.prebid.mobile.rendering.models.AdConfiguration) HTMLCreative(org.prebid.mobile.rendering.models.HTMLCreative) Test(org.junit.Test)

Example 10 with CreativeModel

use of org.prebid.mobile.rendering.models.CreativeModel in project prebid-mobile-android by prebid.

the class TransactionTest method onSuccessWithCreativeTimeout_TransactionListenerSuccessNotCalled.

@Test
public void onSuccessWithCreativeTimeout_TransactionListenerSuccessNotCalled() throws Exception {
    List<CreativeModel> creativeModels = Arrays.asList(mock(CreativeModel.class), mock(CreativeModel.class));
    Transaction.Listener mockListener = mock(Transaction.Listener.class);
    InterstitialManager mockInterstitialManager = mock(InterstitialManager.class);
    Transaction transaction = Transaction.createTransaction(mMockContext, createModelResult(creativeModels, ""), mockInterstitialManager, mockListener);
    Transaction.CreativeFactoryListener creativeFactoryListener = new Transaction.CreativeFactoryListener(transaction);
    Iterator<CreativeFactory> mockIterator = mock(Iterator.class);
    when(mockIterator.hasNext()).thenReturn(true);
    when(mockIterator.next()).thenReturn(mock(CreativeFactory.class));
    WhiteBox.setInternalState(transaction, "mCreativeFactoryIterator", mockIterator);
    creativeFactoryListener.onSuccess();
    verify(mockListener, never()).onTransactionSuccess(transaction);
    AdException adException = new AdException(AdException.INTERNAL_ERROR, "CreativeFactory Timeout");
    creativeFactoryListener.onFailure(adException);
    verify(mockListener).onTransactionFailure(eq(adException), anyString());
}
Also used : CreativeModel(org.prebid.mobile.rendering.models.CreativeModel) InterstitialManager(org.prebid.mobile.rendering.views.interstitial.InterstitialManager) AdException(org.prebid.mobile.rendering.errors.AdException) Test(org.junit.Test)

Aggregations

CreativeModel (org.prebid.mobile.rendering.models.CreativeModel)10 Test (org.junit.Test)7 AdException (org.prebid.mobile.rendering.errors.AdException)6 HTMLCreative (org.prebid.mobile.rendering.models.HTMLCreative)4 InterstitialManager (org.prebid.mobile.rendering.views.interstitial.InterstitialManager)4 AdConfiguration (org.prebid.mobile.rendering.models.AdConfiguration)3 ArrayList (java.util.ArrayList)2 PrebidWebViewBase (org.prebid.mobile.rendering.views.webview.PrebidWebViewBase)1 WebViewBase (org.prebid.mobile.rendering.views.webview.WebViewBase)1