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

Fix Yieldlab test. #1740

Merged
merged 3 commits into from
Feb 20, 2022
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 @@ -37,7 +37,7 @@

import java.math.BigDecimal;
import java.net.URISyntaxException;
import java.time.Instant;
import java.time.Clock;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
Expand All @@ -63,10 +63,12 @@ public class YieldlabBidder implements Bidder<Void> {
+ "</Wrapper></Ad></VAST>";

private final String endpointUrl;
private final Clock clock;
private final JacksonMapper mapper;

public YieldlabBidder(String endpointUrl, JacksonMapper mapper) {
public YieldlabBidder(String endpointUrl, Clock clock, JacksonMapper mapper) {
this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl));
this.clock = Objects.requireNonNull(clock);
this.mapper = Objects.requireNonNull(mapper);
}

Expand Down Expand Up @@ -128,7 +130,7 @@ private ExtImpYieldlab parseImpExt(Imp imp) {

private String makeUrl(ExtImpYieldlab extImpYieldlab, BidRequest request) {
// for passing validation tests
final String timestamp = isDebugEnabled(request) ? "200000" : String.valueOf(Instant.now().getEpochSecond());
final String timestamp = isDebugEnabled(request) ? "200000" : String.valueOf(clock.instant().getEpochSecond());

final String updatedPath = String.format("%s/%s", endpointUrl, extImpYieldlab.getAdslotId());

Expand Down Expand Up @@ -364,16 +366,18 @@ private String makeAdm(BidRequest bidRequest, ExtImpYieldlab extImpYieldlab, Yie
return String.format(AD_SOURCE_BANNER, makeNurl(bidRequest, extImpYieldlab, yieldlabResponse));
}

private static String resolveAdm(BidRequest bidRequest, ExtImpYieldlab extImpYieldlab,
YieldlabResponse yieldlabResponse) {
return String.format(VAST_MARKUP, extImpYieldlab.getAdslotId(),
private String resolveAdm(BidRequest bidRequest, ExtImpYieldlab extImpYieldlab, YieldlabResponse yieldlabResponse) {
return String.format(
VAST_MARKUP,
extImpYieldlab.getAdslotId(),
makeNurl(bidRequest, extImpYieldlab, yieldlabResponse));
}

private static String makeNurl(BidRequest bidRequest, ExtImpYieldlab extImpYieldlab,
YieldlabResponse yieldlabResponse) {
private String makeNurl(BidRequest bidRequest, ExtImpYieldlab extImpYieldlab, YieldlabResponse yieldlabResponse) {
// for passing validation tests
final String timestamp = isDebugEnabled(bidRequest) ? "200000" : String.valueOf(Instant.now().getEpochSecond());
final String timestamp = isDebugEnabled(bidRequest)
? "200000"
: String.valueOf(clock.instant().getEpochSecond());

final URIBuilder uriBuilder = new URIBuilder()
.addParameter("ts", timestamp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.context.annotation.PropertySource;

import javax.validation.constraints.NotBlank;
import java.time.Clock;

@Configuration
@PropertySource(value = "classpath:/bidder-config/yieldlab.yaml", factory = YamlPropertySourceFactory.class)
Expand All @@ -30,12 +31,13 @@ BidderConfigurationProperties configurationProperties() {
@Bean
BidderDeps yieldlabBidderDeps(BidderConfigurationProperties yieldlabConfigurationProperties,
@NotBlank @Value("${external-url}") String externalUrl,
Clock clock,
JacksonMapper mapper) {

return BidderDepsAssembler.forBidder(BIDDER_NAME)
.withConfig(yieldlabConfigurationProperties)
.usersyncerCreator(UsersyncerCreator.create(externalUrl))
.bidderCreator(config -> new YieldlabBidder(config.getEndpoint(), mapper))
.bidderCreator(config -> new YieldlabBidder(config.getEndpoint(), clock, mapper))
.assemble();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import org.prebid.server.proto.openrtb.ext.response.BidType;

import java.math.BigDecimal;
import java.time.Clock;
import java.time.Instant;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
Expand All @@ -39,23 +41,25 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.tuple;
import static org.assertj.core.api.Assertions.within;

public class YieldlabBidderTest extends VertxTest {

private static final String ENDPOINT_URL = "https://test.endpoint.com";

private Clock clock;

private YieldlabBidder yieldlabBidder;

@Before
public void setUp() {
yieldlabBidder = new YieldlabBidder(ENDPOINT_URL, jacksonMapper);
clock = Clock.fixed(Instant.parse("2019-07-26T10:00:00Z"), ZoneId.systemDefault());
yieldlabBidder = new YieldlabBidder(ENDPOINT_URL, clock, jacksonMapper);
}

@Test
public void creationShouldFailOnInvalidEndpointUrl() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new YieldlabBidder("invalid_url", jacksonMapper))
.isThrownBy(() -> new YieldlabBidder("invalid_url", clock, jacksonMapper))
.withMessage("URL supplied is not valid: invalid_url");
}

Expand Down Expand Up @@ -110,7 +114,7 @@ public void makeHttpRequestsShouldSendRequestToModifiedUrlWithHeaders() {
final Result<List<HttpRequest<Void>>> result = yieldlabBidder.makeHttpRequests(bidRequest);

// then
final int expectedTime = (int) Instant.now().getEpochSecond();
final long expectedTime = clock.instant().getEpochSecond();

assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).hasSize(1)
Expand All @@ -120,7 +124,7 @@ public void makeHttpRequestsShouldSendRequestToModifiedUrlWithHeaders() {
assertThat(uri).endsWith("&t=key1%3Dvalue1%26key2%3Dvalue2&ids=buyeruid&yl_rtb_ifa&"
+ "yl_rtb_devicetype=1&gdpr=1&consent=consent");
final String ts = uri.substring(54, uri.indexOf("&t="));
assertThat(Integer.parseInt(ts)).isCloseTo(expectedTime, within(10));
assertThat(Long.parseLong(ts)).isEqualTo(expectedTime);
});

assertThat(result.getValue()).hasSize(1)
Expand Down Expand Up @@ -230,7 +234,7 @@ public void makeBidsShouldReturnCorrectBidderBid() throws JsonProcessingExceptio
final Result<List<BidderBid>> result = yieldlabBidder.makeBids(httpCall, bidRequest);

// then
final String timestamp = String.valueOf((int) Instant.now().getEpochSecond());
final String timestamp = String.valueOf(clock.instant().getEpochSecond());
final int weekNumber = Calendar.getInstance().get(Calendar.WEEK_OF_YEAR);
final String adm = String.format(
"<script src=\"https://ad.yieldlab.net/d/1/2/728x90?ts=%s&id=extId&pvid=40cb3251-1e1e-4cfd-8edc-7d32dc1a21e5&ids=buyeruid&gdpr=1&consent=consent\"></script>",
Expand Down Expand Up @@ -277,7 +281,7 @@ public void makeBidsShouldReturnCorrectAdm() throws JsonProcessingException {
final Result<List<BidderBid>> result = yieldlabBidder.makeBids(httpCall, bidRequest);

// then
final String timestamp = String.valueOf((int) Instant.now().getEpochSecond());
final String timestamp = String.valueOf(clock.instant().getEpochSecond());
final String expectedAdm = String.format("<VAST version=\"2.0\"><Ad id=\"12345\"><Wrapper>"
+ "<AdSystem>Yieldlab</AdSystem>"
+ "<VASTAdTagURI>"
Expand Down