Skip to content

Commit

Permalink
Ad position parameter for Original API ad unit (#806)
Browse files Browse the repository at this point in the history
* feat: remove BannerAdPosition to use only AdPosition

* feat: add new ad position according to the standard

* feat: ad position for video original API ad unit
  • Loading branch information
ValentinPostindustria authored Dec 5, 2024
1 parent 019bd6e commit bd17c32
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.prebid.mobile.api.data.AdFormat;
import org.prebid.mobile.api.data.AdUnitFormat;
import org.prebid.mobile.rendering.models.AdPosition;

import java.util.EnumSet;
import java.util.HashSet;
Expand Down Expand Up @@ -77,4 +78,8 @@ public void setOrtbConfig(@Nullable String ortbConfig) {
configuration.setOrtbConfig(ortbConfig);
}

public void setAdPosition(AdPosition adPosition) {
configuration.setAdPosition(adPosition);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.prebid.mobile.AdSize;
import org.prebid.mobile.LogUtil;
import org.prebid.mobile.api.data.AdFormat;
import org.prebid.mobile.api.data.BannerAdPosition;
import org.prebid.mobile.api.mediation.listeners.OnFetchCompleteListener;
import org.prebid.mobile.rendering.bidding.display.PrebidMediationDelegate;
import org.prebid.mobile.rendering.models.AdPosition;
Expand Down Expand Up @@ -115,13 +114,12 @@ public final void setRefreshInterval(int seconds) {
adUnitConfig.setAutoRefreshDelay(seconds);
}

public void setAdPosition(BannerAdPosition bannerAdPosition) {
final AdPosition adPosition = BannerAdPosition.mapToAdPosition(bannerAdPosition);
public void setAdPosition(AdPosition adPosition) {
adUnitConfig.setAdPosition(adPosition);
}

public BannerAdPosition getAdPosition() {
return BannerAdPosition.mapToDisplayAdPosition(adUnitConfig.getAdPositionValue());
public AdPosition getAdPosition() {
return adUnitConfig.getAdPosition();
}

public void stopRefresh() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.prebid.mobile.LogUtil;
import org.prebid.mobile.PrebidMobile;
import org.prebid.mobile.api.data.AdFormat;
import org.prebid.mobile.api.data.BannerAdPosition;
import org.prebid.mobile.api.data.VideoPlacementType;
import org.prebid.mobile.api.exceptions.AdException;
import org.prebid.mobile.api.rendering.listeners.BannerVideoListener;
Expand Down Expand Up @@ -529,13 +528,12 @@ public void clearExtKeywords() {
}


public void setAdPosition(BannerAdPosition bannerAdPosition) {
final AdPosition adPosition = BannerAdPosition.mapToAdPosition(bannerAdPosition);
public void setAdPosition(AdPosition adPosition) {
adUnitConfig.setAdPosition(adPosition);
}

public BannerAdPosition getAdPosition() {
return BannerAdPosition.mapToDisplayAdPosition(adUnitConfig.getAdPositionValue());
public AdPosition getAdPosition() {
return adUnitConfig.getAdPosition();
}

public void setPbAdSlot(String adSlot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public class AdUnitConfiguration {
private Position skipButtonPosition = Position.TOP_RIGHT;
private AdSize minSizePercentage;
private PlacementType placementType;
private AdPosition adPosition;
@NonNull
private AdPosition adPosition = AdPosition.UNDEFINED;
@Nullable
private ContentObject appContent;
private BannerParameters bannerParameters;
Expand Down Expand Up @@ -474,12 +475,19 @@ public boolean isPlacementTypeValid() {
return getPlacementTypeValue() != PlacementType.UNDEFINED.getValue();
}

public void setAdPosition(@Nullable AdPosition adPosition) {
public void setAdPosition(AdPosition adPosition) {
if (adPosition == null) return;

this.adPosition = adPosition;
}

@NonNull
public AdPosition getAdPosition() {
return adPosition;
}

public int getAdPositionValue() {
return adPosition != null ? adPosition.getValue() : AdPosition.UNDEFINED.getValue();
return adPosition.getValue();
}

public boolean isAdPositionValid() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@

package org.prebid.mobile.rendering.models;

/**
* The ad position for additional targeting.
*/
public enum AdPosition {

UNDEFINED(-1),
UNKNOWN(0),
ABOVE_THE_FOLD(1),
LOCKED(2),
BELOW_THE_FOLD(3),
HEADER(4),
FOOTER(5),
SIDEBAR(6),
Expand All @@ -33,4 +40,5 @@ public enum AdPosition {
public int getValue() {
return value;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ private void appendUserTargetingParameters(AdRequestInput adRequestInput) {

private void setVideoImpValues(Imp imp) {
Video video = new Video();

if (adConfiguration.isAdPositionValid()) {
video.pos = adConfiguration.getAdPositionValue();
}

if (adConfiguration.isOriginalAdUnit()) {
VideoParameters videoParameters = adConfiguration.getVideoParameters();
if (videoParameters != null) {
Expand Down Expand Up @@ -278,10 +283,6 @@ private void setVideoImpValues(Imp imp) {
//Interstitial video specific values
video.playbackend = VIDEO_INTERSTITIAL_PLAYBACK_END;//On Leaving Viewport or when Terminated by User

if (adConfiguration.isAdPositionValid()) {
video.pos = adConfiguration.getAdPositionValue();
}

if (!adConfiguration.isPlacementTypeValid()) {
video.placement = PlacementType.INTERSTITIAL.getValue();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.prebid.mobile.configuration.AdUnitConfiguration;
import org.prebid.mobile.reflection.AdUnitReflection;
import org.prebid.mobile.rendering.bidding.loader.BidLoader;
import org.prebid.mobile.rendering.models.AdPosition;
import org.prebid.mobile.testutils.BaseSetup;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
Expand Down Expand Up @@ -100,6 +101,27 @@ public void testGpidParameter() {
assertEquals(expectedGpid, configuration.getGpid());
}

@Test
public void adPosition_empty() {
BannerAdUnit adUnit = new BannerAdUnit(testConfigId, width, height);

AdUnitConfiguration configuration = adUnit.getConfiguration();
assertEquals(AdPosition.UNDEFINED, configuration.getAdPosition());
assertEquals(AdPosition.UNDEFINED.getValue(), configuration.getAdPositionValue());
}

@Test
public void adPosition() {
BannerAdUnit adUnit = new BannerAdUnit(testConfigId, width, height);
adUnit.setAdPosition(AdPosition.SIDEBAR);

AdUnitConfiguration configuration = adUnit.getConfiguration();
assertEquals(AdPosition.SIDEBAR, configuration.getAdPosition());
assertEquals(AdPosition.SIDEBAR.getValue(), configuration.getAdPositionValue());
}



@Test
public void testBannerParametersCreation() {
//given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import org.prebid.mobile.AdSize;
import org.prebid.mobile.PrebidMobile;
import org.prebid.mobile.api.data.AdFormat;
import org.prebid.mobile.api.data.BannerAdPosition;
import org.prebid.mobile.configuration.AdUnitConfiguration;
import org.prebid.mobile.rendering.bidding.config.MockMediationUtils;
import org.prebid.mobile.rendering.bidding.loader.BidLoader;
import org.prebid.mobile.rendering.models.AdPosition;
import org.prebid.mobile.rendering.utils.broadcast.ScreenStateReceiver;
import org.prebid.mobile.test.utils.WhiteBox;
import org.robolectric.Robolectric;
Expand Down Expand Up @@ -64,7 +64,7 @@ public void setUp() throws Exception {
WhiteBox.setInternalState(mediationBannerAdUnit, "bidLoader", mockBidLoader);
WhiteBox.setInternalState(mediationBannerAdUnit, "screenStateReceiver", mockScreenStateReceiver);

assertEquals(BannerAdPosition.UNDEFINED.getValue(), mediationBannerAdUnit.getAdPosition().getValue());
assertEquals(AdPosition.UNDEFINED.getValue(), mediationBannerAdUnit.getAdPosition().getValue());
}

@After
Expand Down Expand Up @@ -106,19 +106,19 @@ public void whenStopRefresh_BidLoaderCancelRefresh() {
@Test
public void setAdPosition_EqualsGetAdPosition() {
mediationBannerAdUnit.setAdPosition(null);
assertEquals(BannerAdPosition.UNDEFINED, mediationBannerAdUnit.getAdPosition());
assertEquals(AdPosition.UNDEFINED, mediationBannerAdUnit.getAdPosition());

mediationBannerAdUnit.setAdPosition(BannerAdPosition.FOOTER);
assertEquals(BannerAdPosition.FOOTER, mediationBannerAdUnit.getAdPosition());
mediationBannerAdUnit.setAdPosition(AdPosition.FOOTER);
assertEquals(AdPosition.FOOTER, mediationBannerAdUnit.getAdPosition());

mediationBannerAdUnit.setAdPosition(BannerAdPosition.HEADER);
assertEquals(BannerAdPosition.HEADER, mediationBannerAdUnit.getAdPosition());
mediationBannerAdUnit.setAdPosition(AdPosition.HEADER);
assertEquals(AdPosition.HEADER, mediationBannerAdUnit.getAdPosition());

mediationBannerAdUnit.setAdPosition(BannerAdPosition.SIDEBAR);
assertEquals(BannerAdPosition.SIDEBAR, mediationBannerAdUnit.getAdPosition());
mediationBannerAdUnit.setAdPosition(AdPosition.SIDEBAR);
assertEquals(AdPosition.SIDEBAR, mediationBannerAdUnit.getAdPosition());

mediationBannerAdUnit.setAdPosition(BannerAdPosition.UNKNOWN);
assertEquals(BannerAdPosition.UNKNOWN, mediationBannerAdUnit.getAdPosition());
mediationBannerAdUnit.setAdPosition(AdPosition.UNKNOWN);
assertEquals(AdPosition.UNKNOWN, mediationBannerAdUnit.getAdPosition());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
import org.prebid.mobile.AdSize;
import org.prebid.mobile.Host;
import org.prebid.mobile.PrebidMobile;
import org.prebid.mobile.api.data.BannerAdPosition;
import org.prebid.mobile.api.data.FetchDemandResult;
import org.prebid.mobile.api.exceptions.AdException;
import org.prebid.mobile.api.mediation.listeners.OnFetchCompleteListener;
import org.prebid.mobile.rendering.bidding.config.MockMediationUtils;
import org.prebid.mobile.rendering.bidding.loader.BidLoader;
import org.prebid.mobile.rendering.models.AdPosition;
import org.prebid.mobile.test.utils.WhiteBox;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
Expand Down Expand Up @@ -68,7 +68,7 @@ public void setUp() throws Exception {
baseAdUnit = createAdUnit("config");
PrebidMobile.setPrebidServerHost(Host.APPNEXUS);

assertEquals(BannerAdPosition.UNDEFINED.getValue(), baseAdUnit.adUnitConfig.getAdPositionValue());
assertEquals(AdPosition.UNDEFINED.getValue(), baseAdUnit.adUnitConfig.getAdPositionValue());
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.mockito.MockitoAnnotations;
import org.prebid.mobile.AdSize;
import org.prebid.mobile.api.data.AdFormat;
import org.prebid.mobile.api.data.BannerAdPosition;
import org.prebid.mobile.api.data.VideoPlacementType;
import org.prebid.mobile.api.exceptions.AdException;
import org.prebid.mobile.api.rendering.listeners.BannerVideoListener;
Expand All @@ -43,6 +42,7 @@
import org.prebid.mobile.rendering.bidding.listeners.DisplayVideoListener;
import org.prebid.mobile.rendering.bidding.listeners.DisplayViewListener;
import org.prebid.mobile.rendering.bidding.loader.BidLoader;
import org.prebid.mobile.rendering.models.AdPosition;
import org.prebid.mobile.rendering.utils.broadcast.ScreenStateReceiver;
import org.prebid.mobile.test.utils.WhiteBox;
import org.robolectric.Robolectric;
Expand Down Expand Up @@ -94,7 +94,7 @@ public void setup() throws Exception {
bannerView.setBannerListener(mockBannerListener);
bannerView.setBannerVideoListener(mockBannerVideoListener);

assertEquals(BannerAdPosition.UNDEFINED.getValue(), bannerView.getAdPosition().getValue());
assertEquals(AdPosition.UNDEFINED.getValue(), bannerView.getAdPosition().getValue());
}

@Test
Expand Down Expand Up @@ -496,19 +496,19 @@ public void addRemoveContextKeywords_EqualsGetContextKeyWordsSet() {
@Test
public void setAdPosition_EqualsGetAdPosition() {
bannerView.setAdPosition(null);
assertEquals(BannerAdPosition.UNDEFINED, bannerView.getAdPosition());
assertEquals(AdPosition.UNDEFINED, bannerView.getAdPosition());

bannerView.setAdPosition(BannerAdPosition.FOOTER);
assertEquals(BannerAdPosition.FOOTER, bannerView.getAdPosition());
bannerView.setAdPosition(AdPosition.FOOTER);
assertEquals(AdPosition.FOOTER, bannerView.getAdPosition());

bannerView.setAdPosition(BannerAdPosition.HEADER);
assertEquals(BannerAdPosition.HEADER, bannerView.getAdPosition());
bannerView.setAdPosition(AdPosition.HEADER);
assertEquals(AdPosition.HEADER, bannerView.getAdPosition());

bannerView.setAdPosition(BannerAdPosition.SIDEBAR);
assertEquals(BannerAdPosition.SIDEBAR, bannerView.getAdPosition());
bannerView.setAdPosition(AdPosition.SIDEBAR);
assertEquals(AdPosition.SIDEBAR, bannerView.getAdPosition());

bannerView.setAdPosition(BannerAdPosition.UNKNOWN);
assertEquals(BannerAdPosition.UNKNOWN, bannerView.getAdPosition());
bannerView.setAdPosition(AdPosition.UNKNOWN);
assertEquals(AdPosition.UNKNOWN, bannerView.getAdPosition());
}

@Test
Expand Down

0 comments on commit bd17c32

Please sign in to comment.