@Test(expected = MapperException.class) public void testResponse_impWithoutAd() { OpenRtb.BidRequest request = OpenRtb.BidRequest.newBuilder().setId("1").addImp(Imp.newBuilder().setId("1")).build(); Bid bid = TestData.newBid(false).setAdm("snippet").build(); NetworkBid.BidResponse.Ad.Builder ad = mapper.mapResponseAd(request, bid); assertThat(ad).isNotNull(); }
@Test public void testRequest_ping() { NetworkBid.BidRequest dcRequest = NetworkBid.BidRequest.newBuilder().setId(TestUtil.REQUEST_ID).setIsPing(true).build(); OpenRtb.BidRequest request = mapper.toOpenRtbBidRequest(dcRequest).build(); assertThat(request) .isEqualTo( OpenRtb.BidRequest.newBuilder() .setId( Base64.getUrlEncoder() .withoutPadding() .encodeToString(dcRequest.getId().toByteArray())) .build()); }
@Test public void testExtMapper() { ExtMapper extMapper = new ExtMapper() {}; extMapper.toOpenRtbBidRequest( NetworkBid.BidRequest.getDefaultInstance(), OpenRtb.BidRequest.newBuilder()); extMapper.toOpenRtbDevice( NetworkBid.BidRequest.getDefaultInstance(), OpenRtb.BidRequest.Device.newBuilder()); extMapper.toOpenRtbImp( NetworkBid.BidRequest.AdSlot.getDefaultInstance(), OpenRtb.BidRequest.Imp.newBuilder()); extMapper.toOpenRtbBanner( NetworkBid.BidRequest.AdSlot.getDefaultInstance(), OpenRtb.BidRequest.Imp.Banner.newBuilder()); extMapper.toOpenRtbVideo( NetworkBid.BidRequest.Video.getDefaultInstance(), OpenRtb.BidRequest.Imp.Video.newBuilder()); extMapper.toOpenRtbPmp( NetworkBid.BidRequest.AdSlot.MatchingAdData.getDefaultInstance(), OpenRtb.BidRequest.Imp.Pmp.newBuilder()); extMapper.toDoubleClickAd( OpenRtb.BidRequest.getDefaultInstance(), OpenRtb.BidResponse.SeatBid.Bid.getDefaultInstance(), NetworkBid.BidResponse.Ad.newBuilder()); }
@Test public void testResponse_multisizeBannerGood() { Imp.Builder imp = Imp.newBuilder() .setId("1") .setBanner( Banner.newBuilder().setId("1").setWmin(100).setWmax(200).setHmin(300).setHmax(400)) .setExtension( DcExt.adSlot, NetworkBid.BidRequest.AdSlot.newBuilder() .setId(0) .addAllWidth(asList(100, 200)) .addAllHeight(asList(300, 400)) .build()); Bid bid1 = TestData.newBid(false).build(); Bid bid2 = TestData.newBid(true).build(); OpenRtb.BidRequest request = OpenRtb.BidRequest.newBuilder().setId("1").addImp(imp).build(); NetworkBid.BidResponse.Ad.Builder ad1 = mapper.mapResponseAd(request, bid1); assertThat(!ad1.hasWidth() && !ad1.hasHeight()).isTrue(); NetworkBid.BidResponse.Ad.Builder ad2 = mapper.mapResponseAd(request, bid2); assertThat(ad2.getWidth()).isEqualTo(bid2.getW()); assertThat(ad2.getHeight()).isEqualTo(bid2.getH()); }