2121import org .prebid .server .bidder .model .HttpResponse ;
2222import org .prebid .server .bidder .model .Result ;
2323import org .prebid .server .proto .openrtb .ext .ExtPrebid ;
24+ import org .prebid .server .proto .openrtb .ext .request .ExtImpPrebid ;
2425import org .prebid .server .proto .openrtb .ext .request .gumgum .ExtImpGumgum ;
2526import org .prebid .server .proto .openrtb .ext .request .gumgum .ExtImpGumgumBanner ;
2627import org .prebid .server .proto .openrtb .ext .request .gumgum .ExtImpGumgumVideo ;
2728
29+ import java .io .IOException ;
2830import java .math .BigDecimal ;
2931import java .math .BigInteger ;
32+ import java .util .Collections ;
3033import java .util .List ;
3134import java .util .function .Function ;
3235
3639import static org .assertj .core .api .Assertions .assertThat ;
3740import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
3841import static org .assertj .core .api .Assertions .tuple ;
42+ import static org .junit .Assert .assertEquals ;
43+ import static org .junit .Assert .assertFalse ;
44+ import static org .junit .Assert .assertNotNull ;
45+ import static org .junit .Assert .assertNull ;
3946import static org .prebid .server .proto .openrtb .ext .response .BidType .banner ;
4047import static org .prebid .server .proto .openrtb .ext .response .BidType .video ;
4148
@@ -45,6 +52,124 @@ public class GumgumBidderTest extends VertxTest {
4552
4653 private final GumgumBidder target = new GumgumBidder (ENDPOINT_URL , jacksonMapper );
4754
55+ @ Test
56+ public void makeHttpRequestsShouldReturnErrorIfImpExtCouldNotBeParsed () {
57+ // given
58+ final BidRequest bidRequest = givenBidRequest (impBuilder ->
59+ impBuilder .ext (mapper .valueToTree (ExtPrebid .of (null , mapper .createArrayNode ()))));
60+
61+ // when
62+ final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
63+
64+ // then
65+ assertThat (result .getErrors ()).hasSize (2 )
66+ .anySatisfy (error -> {
67+ assertThat (error .getType ()).isEqualTo (BidderError .Type .bad_input );
68+ assertThat (error .getMessage ()).startsWith ("Cannot deserialize value" );
69+ });
70+ }
71+
72+ @ Test
73+ public void makeHttpRequestsShouldModifyImpressionsWhenValidInput () {
74+ // given
75+ final ObjectNode extImp = mapper .valueToTree (ExtPrebid .of (
76+ ExtImpPrebid .builder ().adUnitCode ("adUnit123" ).build (),
77+ ExtImpGumgum .of ("zone" , BigInteger .TEN , "irisId" , null , "product" )));
78+
79+ final BidRequest bidRequest = givenBidRequest (impBuilder ->
80+ impBuilder .ext (extImp ));
81+
82+ // when
83+ final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
84+
85+ // then
86+ assertThat (result .getValue ())
87+ .extracting (HttpRequest ::getPayload )
88+ .flatExtracting (BidRequest ::getImp )
89+ .extracting (Imp ::getTagid )
90+ .containsExactly ("adUnit123" );
91+ }
92+
93+ @ Test
94+ public void testMakeHttpRequestsShouldNotSetTagIdFromZoneWhenAdUnitIdIsMissing () throws IOException {
95+ // given
96+ final ObjectNode extImp = mapper .valueToTree (ExtPrebid .of (null ,
97+ ExtImpGumgum .of ("zone123" , BigInteger .TEN , "productA" , null , "zone123" )));
98+
99+ final Imp imp = Imp .builder ()
100+ .id ("imp1" )
101+ .banner (Banner .builder ().w (300 ).h (250 ).build ())
102+ .ext (extImp )
103+ .build ();
104+
105+ final BidRequest bidRequest = BidRequest .builder ()
106+ .id ("test-bid-request" )
107+ .imp (Collections .singletonList (imp ))
108+ .site (Site .builder ().id ("test-site" ).build ())
109+ .build ();
110+
111+ // when
112+ final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
113+
114+ // then
115+ assertNotNull (result );
116+ assertFalse (result .getValue ().isEmpty ());
117+
118+ final byte [] requestBody = result .getValue ().get (0 ).getBody ();
119+ final BidRequest modifiedRequest = mapper .readValue (requestBody , BidRequest .class );
120+
121+ assertFalse (modifiedRequest .getImp ().isEmpty ());
122+
123+ final Imp modifiedImp = modifiedRequest .getImp ().get (0 );
124+
125+ assertNull (modifiedImp .getTagid ());
126+ assertEquals ("test-site" , modifiedRequest .getSite ().getId (), "zone123" );
127+ }
128+
129+ @ Test
130+ public void makeHttpRequestsShouldReturnModifiedBidRequestWhenValidInput () {
131+ // given
132+ final ObjectNode extImp = mapper .valueToTree (ExtPrebid .of (
133+ ExtImpPrebid .builder ().adUnitCode ("adUnit123" ).build (),
134+ ExtImpGumgum .of ("zone" , BigInteger .TEN , "irisId" , null , "product" )));
135+
136+ final BidRequest bidRequest = givenBidRequest (impBuilder -> impBuilder .ext (extImp ));
137+
138+ // when
139+ final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
140+
141+ // then
142+ assertThat (result .getErrors ()).isEmpty ();
143+
144+ assertThat (result .getValue ())
145+ .extracting (HttpRequest ::getPayload )
146+ .flatExtracting (BidRequest ::getImp )
147+ .extracting (Imp ::getTagid )
148+ .containsExactly ("adUnit123" );
149+ }
150+
151+ @ Test
152+ public void makeHttpRequestsShouldExtractAdUnitIdWhenPresent () {
153+ // given
154+ final ObjectNode extImp = mapper .valueToTree (ExtPrebid .of (
155+ ExtImpPrebid .builder ().adUnitCode ("adUnit123" ).build (),
156+ ExtImpGumgum .of ("zone" , BigInteger .TEN , "irisId" , null , "product" )));
157+
158+ final BidRequest bidRequest = givenBidRequest (impBuilder -> impBuilder .ext (extImp ));
159+
160+ // when
161+ final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
162+
163+ // then
164+ assertThat (result .getErrors ()).isEmpty ();
165+
166+ assertThat (result .getValue ())
167+ .extracting (HttpRequest ::getPayload )
168+ .flatExtracting (BidRequest ::getImp )
169+ .extracting (Imp ::getTagid )
170+ .containsExactly ("adUnit123" );
171+ }
172+
48173 @ Test
49174 public void creationShouldFailOnInvalidEndpointUrl () {
50175 assertThatIllegalArgumentException ().isThrownBy (() -> new GumgumBidder ("invalid_url" , jacksonMapper ));
@@ -422,4 +547,5 @@ private static BidderCall<BidRequest> givenHttpCall(BidRequest bidRequest, Strin
422547 HttpResponse .of (200 , null , body ),
423548 null );
424549 }
550+
425551}
0 commit comments