@Override public void destroy() { response.destroy(); }
static boolean isValid(NativeAdResponse response) { if (response != null && !response.hasExpired()) { return true; } Clog.d(Clog.nativeLogTag, "NativeAdResponse is not valid"); return false; } }
@Test public void testgetAdTypeBannerNative() { server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.anNativeVideo())); // First queue a regular HTML banner response assertTrue(bannerAdView.getAdType() == AdType.UNKNOWN); // First tests if ad_type is UNKNOWN initially executeBannerRequest(); assertTrue(bannerAdView.getAdType() == AdType.NATIVE); // If a Native Ad is served then NATIVE assertTrue(nativeAdResponse.getCreativeId().equalsIgnoreCase("47772560")); assertTrue(nativeAdResponse.getIconUrl().equalsIgnoreCase("http://path_to_icon.com")); assertTrue(nativeAdResponse.getIcon() == null); assertTrue(nativeAdResponse.getImage() == null); assertTrue(nativeAdResponse.getImageUrl().equalsIgnoreCase("http://path_to_main.com")); assertTrue(nativeAdResponse.getTitle().equalsIgnoreCase("test title")); assertTrue(nativeAdResponse.getDescription().equalsIgnoreCase("test description")); assertTrue(nativeAdResponse.getAdditionalDescription().equalsIgnoreCase("additional test description")); assertTrue(nativeAdResponse.getImageSize().getHeight() == 200); assertTrue(nativeAdResponse.getImageSize().getWidth() == 300); assertTrue(nativeAdResponse.getIconSize().getHeight() == 150); assertTrue(nativeAdResponse.getIconSize().getWidth() == 100); assertEquals("<VAST>content</VAST>",nativeAdResponse.getVastXml()); assertEquals("http://ib.adnxs.com/privacy...",nativeAdResponse.getPrivacyLink()); }
public void runBasicMediationTest(ResultCode errorCode, boolean success, boolean checkLatency) { executeUTRequest(); Lock.pause(Settings.MEDIATED_NETWORK_TIMEOUT + 1000); executeAndAssertResponseURL(2, errorCode,checkLatency); assertCallbacks(success); if(ResultCode.SUCCESS == errorCode){ assertEquals(MediatedNativeSuccessful.TITLE,response.getTitle()); assertEquals(MediatedNativeSuccessful.DESCRIPTION,response.getDescription()); assertEquals(MediatedNativeSuccessful.ADDITIONAL_DESCRIPTION,response.getAdditionalDescription()); assertTrue(response.getImageSize().getHeight() == -1); assertTrue(response.getImageSize().getWidth() == -1); assertTrue(response.getIconSize().getHeight() == -1); assertTrue(response.getIconSize().getWidth() == -1); assertEquals(MediatedNativeSuccessful.ImageUrl,response.getImageUrl()); } }
final String IMAGE_URL = "image", ICON_URL = "icon"; final NativeAdResponse response = ad.getNativeAdResponse(); response.setCreativeId(ad.getResponseData().getCreativeId()); if (!loadImage && !loadIcon) { if (listener != null) { listener.onAdLoaded(response); } else { response.destroy(); HashMap<String, String> imageUrlMap = new HashMap<>(); if (loadImage) imageUrlMap.put(IMAGE_URL, response.getImageUrl()); if (loadIcon) imageUrlMap.put(ICON_URL, response.getIconUrl()); imageService.registerImageReceiver(imageReceiver, imageUrlMap); imageService.registerNotification(this);
@Test public void testCreativeId() { server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.anNative())); adRequest.loadAd(); Lock.pause(1000); waitForTasks(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); waitForTasks(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); assertEquals("47772560",response.getCreativeId()); assertAdLoaded(true); }
@Test public void testSkipFirstSuccessfulSecond() { String[] classNames = {"MediatedNativeNoFill", "MediatedNativeSuccessful2"}; String[] responseURLs = {TestResponsesUT.RESPONSE_URL, TestResponsesUT.RESPONSE_URL}; server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.waterfall_CSM_Native(classNames, responseURLs))); server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.blank())); server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.blank())); executeUTRequest(); executeAndAssertResponseURL(2, UNABLE_TO_FILL, CHECK_LATENCY_TRUE); //2 request are already taken out of queue current position of ResponseURL in queue is 1 executeAndAssertResponseURL(1, SUCCESS, CHECK_LATENCY_TRUE); Lock.pause(Settings.MEDIATED_NETWORK_TIMEOUT + 1000); assertCallbacks(true); assertTrue(MediatedNativeSuccessful2.didPass); assertEquals(MediatedNativeSuccessful2.TITLE,response.getTitle()); assertEquals(MediatedNativeSuccessful2.DESCRIPTION,response.getDescription()); assertEquals(MediatedNativeSuccessful2.ADDITIONAL_DESCRIPTION,response.getAdditionalDescription()); assertTrue(response.getImageSize().getHeight() == -1); assertTrue(response.getImageSize().getWidth() == -1); assertTrue(response.getIconSize().getHeight() == -1); assertTrue(response.getIconSize().getWidth() == -1); assertEquals(MediatedNativeSuccessful2.ImageUrl,response.getImageUrl()); }
@Override public void onAllImageDownloadsFinish() { if (listener != null) { listener.onAdLoaded(response); } else { response.destroy(); } imageService = null; response = null; isLoading = false; }
@Test public void requestNativeSuccess() { server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.anNative())); adRequest.loadAd(); Lock.pause(1000); waitForTasks(); Robolectric.flushForegroundThreadScheduler(); Robolectric.flushBackgroundThreadScheduler(); waitForTasks(); Robolectric.getBackgroundThreadScheduler().advanceToNextPostedRunnable(); Robolectric.getForegroundThreadScheduler().advanceToNextPostedRunnable(); //Robolectric.flushForegroundThreadScheduler(); //Lock.pause(2000); assertAdLoaded(true); nativeAdView = DummyView.getDummyView(activity); attachToWindow(nativeAdView); NativeAdSDK.registerTracking(response, nativeAdView, this); //@TODO can do perform Click and Test but issue with roboelectric https://github.com/robolectric/robolectric/issues/2372 //Shadows.shadowOf(nativeAdView).checkedPerformClick(); //Robolectric.getForegroundThreadScheduler().advanceToNextPostedRunnable(); //assertTrue(adWasClicked); assertFalse(response.hasExpired()); }
@Override public void tearDown() { super.tearDown(); if (response != null) { response.destroy(); } }
@Override public void tearDown() { super.tearDown(); if (response != null) { response.destroy(); } }
@Override public void tearDown() { super.tearDown(); if (response != null) { response.destroy(); } } }
} else { Clog.d(Clog.mediationLogTag, "Request was cancelled, destroy mediated ad response"); response.destroy();