Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update AnalyticsReporterDelegator to tolerate with missing BidRequest #1302

Merged
merged 1 commit into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ private <T> void checkUnknownAdaptersForAuctionEvent(T event) {
}

private void logUnknownAdapters(AuctionEvent auctionEvent) {
final BidRequest bidRequest = auctionEvent.getAuctionContext().getBidRequest();
final ExtRequest extRequest = bidRequest.getExt();
final AuctionContext auctionContext = auctionEvent.getAuctionContext();
final BidRequest bidRequest = auctionContext != null ? auctionContext.getBidRequest() : null;
final ExtRequest extRequest = bidRequest != null ? bidRequest.getExt() : null;
final ExtRequestPrebid extPrebid = extRequest != null ? extRequest.getPrebid() : null;
final JsonNode analytics = extPrebid != null ? extPrebid.getAnalytics() : null;
final Iterator<String> analyticsFieldNames = isNotEmptyObjectNode(analytics) ? analytics.fieldNames() : null;
Expand Down Expand Up @@ -149,13 +150,14 @@ private static <T> T updateEvent(T event, String adapter) {
}

private static AuctionContext updateAuctionContextAdapter(AuctionContext context, String adapter) {
final BidRequest updatedBidRequest = updateBidRequest(context.getBidRequest(), adapter);
final BidRequest bidRequest = context != null ? context.getBidRequest() : null;
final BidRequest updatedBidRequest = updateBidRequest(bidRequest, adapter);

return updatedBidRequest != null ? context.toBuilder().bidRequest(updatedBidRequest).build() : null;
}

private static BidRequest updateBidRequest(BidRequest bidRequest, String adapterName) {
final ExtRequest requestExt = bidRequest.getExt();
final ExtRequest requestExt = bidRequest != null ? bidRequest.getExt() : null;
final ExtRequestPrebid extPrebid = requestExt != null ? requestExt.getPrebid() : null;
final JsonNode analytics = extPrebid != null ? extPrebid.getAnalytics() : null;
ObjectNode preparedAnalytics = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ public void shouldTolerateInvalidExtPrebidAnalyticsNode() {
.containsExactly(analyticsNode, analyticsNode);
}

@Test
public void shouldTolerateWithMissingBidRequest() {
// given
final AuctionEvent givenAuctionEventWithoutContext = AuctionEvent.builder().build();
final AuctionEvent givenAuctionEventWithoutBidRequest = AuctionEvent.builder()
.auctionContext(AuctionContext.builder().build())
.build();

// when
target.processEvent(givenAuctionEventWithoutContext, TcfContext.empty());
target.processEvent(givenAuctionEventWithoutBidRequest, TcfContext.empty());

// then
verify(vertx, times(4)).runOnContext(any());
}

@Test
public void shouldPassOnlyAdapterRelatedEntriesToAnalyticReporters() {
// given
Expand Down