Skip to content

Commit

Permalink
Adjust App / Site config to allow empty publisher and respect the sit…
Browse files Browse the repository at this point in the history
…eApp filter
  • Loading branch information
steffenmllr committed Oct 9, 2024
1 parent 9da4ca8 commit 2271af3
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,17 @@ private static String getPublisherId(BidRequest bidRequest) {

final String publisherId = Optional.ofNullable(site).map(Site::getPublisher).map(Publisher::getId)
.or(() -> Optional.ofNullable(app).map(App::getPublisher).map(Publisher::getId))
.orElse(null);
.orElse("");
final String appSiteId = Optional.ofNullable(site).map(Site::getId)
.or(() -> Optional.ofNullable(app).map(App::getId))
.or(() -> Optional.ofNullable(app).map(App::getBundle))
.orElse(null);

if (publisherId == null && appSiteId == null) {
if (publisherId.equals("") && appSiteId == null) {
return null;
}

return publisherId;
return appSiteId != null ? publisherId + "_" + appSiteId : publisherId;
}

private void sendEvents(List<String> events) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,15 @@ private static class AgmaAnalyticsConfigurationProperties {
public AgmaAnalyticsProperties toComponentProperties() {
final Map<String, String> accountsByPublisherId = accounts.stream()
.collect(Collectors.toMap(
AgmaAnalyticsAccountProperties::getPublisherId,
AgmaAnalyticsAccountProperties::getCode));
account -> {
final String publisherId = account.getPublisherId();
final String siteAppId = account.getSiteAppId();
return (siteAppId != null && !siteAppId.isEmpty())
? publisherId + "_" + siteAppId
: publisherId;
},
AgmaAnalyticsAccountProperties::getCode
));

return AgmaAnalyticsProperties.builder()
.url(endpoint.getUrl())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,124 @@ public void processEventShouldNotSendAnythingWhenAccountsDoesNotHaveConfiguredPu
assertThat(result.succeeded()).isTrue();
}

@Test
public void processEventShouldSendWhenAccountsHasConfiguredAppsOrSites() {
// given
final AgmaAnalyticsProperties properties = AgmaAnalyticsProperties.builder()
.url("http://endpoint.com")
.gzip(false)
.bufferSize(100000)
.bufferTimeoutMs(10000L)
.maxEventsCount(0)
.httpTimeoutMs(1000L)
.accounts(Map.of("publisherId_bundleId", "accountCode"))
.build();

target = new AgmaAnalyticsReporter(properties, versionProvider, jacksonMapper, clock, httpClient, vertx);

// given
final App givenApp = App.builder().bundle("bundleId")
.publisher(Publisher.builder().id("publisherId").build()).build();
final Device givenDevice = Device.builder().build();
final User givenUser = User.builder().build();

final AuctionEvent auctionEvent = AuctionEvent.builder()
.auctionContext(AuctionContext.builder()
.privacyContext(PrivacyContext.of(
null, TcfContext.builder().consent(PARSED_VALID_CONSENT).build()))
.timeoutContext(TimeoutContext.of(clock.millis(), null, 1))
.bidRequest(BidRequest.builder()
.id("requestId")
.app(givenApp)
.app(givenApp)
.device(givenDevice)
.user(givenUser)
.build())
.build())
.build();

// when
final Future<Void> result = target.processEvent(auctionEvent);

// then
final AgmaEvent expectedEvent = AgmaEvent.builder()
.eventType("auction")
.accountCode("accountCode")
.requestId("requestId")
.app(givenApp)
.device(givenDevice)
.user(givenUser)
.startTime(ZonedDateTime.parse("2024-09-03T15:00:00+05:00"))
.build();

final String expectedEventPayload = "[" + jacksonMapper.encodeToString(expectedEvent) + "]";

verify(httpClient).request(
eq(POST),
eq("http://endpoint.com"),
any(),
eq(expectedEventPayload),
eq(1000L));
}

@Test
public void processEventShouldSendWhenAccountsHasConfiguredAppsOrSitesOnly() {
// given
final AgmaAnalyticsProperties properties = AgmaAnalyticsProperties.builder()
.url("http://endpoint.com")
.gzip(false)
.bufferSize(100000)
.bufferTimeoutMs(10000L)
.maxEventsCount(0)
.httpTimeoutMs(1000L)
.accounts(Map.of("_mySite", "accountCode"))
.build();

target = new AgmaAnalyticsReporter(properties, versionProvider, jacksonMapper, clock, httpClient, vertx);

// given
final Site givenSite = Site.builder().id("mySite").build();
final Device givenDevice = Device.builder().build();
final User givenUser = User.builder().build();

final AuctionEvent auctionEvent = AuctionEvent.builder()
.auctionContext(AuctionContext.builder()
.privacyContext(PrivacyContext.of(
null, TcfContext.builder().consent(PARSED_VALID_CONSENT).build()))
.timeoutContext(TimeoutContext.of(clock.millis(), null, 1))
.bidRequest(BidRequest.builder()
.id("requestId")
.site(givenSite)
.device(givenDevice)
.user(givenUser)
.build())
.build())
.build();

// when
final Future<Void> result = target.processEvent(auctionEvent);

// then
final AgmaEvent expectedEvent = AgmaEvent.builder()
.eventType("auction")
.accountCode("accountCode")
.requestId("requestId")
.site(givenSite)
.device(givenDevice)
.user(givenUser)
.startTime(ZonedDateTime.parse("2024-09-03T15:00:00+05:00"))
.build();

final String expectedEventPayload = "[" + jacksonMapper.encodeToString(expectedEvent) + "]";

verify(httpClient).request(
eq(POST),
eq("http://endpoint.com"),
any(),
eq(expectedEventPayload),
eq(1000L));
}

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

0 comments on commit 2271af3

Please sign in to comment.