Skip to content

Commit 3b9ff55

Browse files
committed
Add unit tests
1 parent 8cb350b commit 3b9ff55

2 files changed

Lines changed: 111 additions & 2 deletions

File tree

src/test/java/org/prebid/server/auction/ImplicitParametersExtractorTest.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,13 @@ public void ipFromShouldReturnIpFromHeadersAndRemoteAddress() {
127127
.add("True-Client-IP", "192.168.144.1 ")
128128
.add("X-Forwarded-For", "192.168.144.2 , 192.168.144.3 ")
129129
.add("X-Real-IP", "192.168.144.4 ")
130+
.add("X-Device-IP", "192.168.144.5")
130131
.build();
131-
final String remoteHost = "192.168.144.5";
132+
final String remoteHost = "192.168.144.6";
132133

133134
// when and then
134135
assertThat(extractor.ipFrom(headers, remoteHost)).containsExactly(
135-
"192.168.144.1", "192.168.144.2", "192.168.144.3", "192.168.144.4", remoteHost);
136+
"192.168.144.1", "192.168.144.2", "192.168.144.3", "192.168.144.4", "192.168.144.5", remoteHost);
136137
}
137138

138139
@Test
@@ -153,13 +154,27 @@ public void uaFromShouldReturnUaFromUserAgentHeader() {
153154
final HttpRequestContext httpRequest = HttpRequestContext.builder()
154155
.headers(CaseInsensitiveMultiMap.builder()
155156
.add(HttpUtil.USER_AGENT_HEADER, " user agent ")
157+
.add(HttpUtil.X_DEVICE_USER_AGENT_HEADER, " device user agent ")
156158
.build())
157159
.build();
158160

159161
// when and then
160162
assertThat(extractor.uaFrom(httpRequest)).isEqualTo("user agent");
161163
}
162164

165+
@Test
166+
public void uaFromShouldReturnUaFromXDeviceUserAgentHeader() {
167+
// given
168+
final HttpRequestContext httpRequest = HttpRequestContext.builder()
169+
.headers(CaseInsensitiveMultiMap.builder()
170+
.add(HttpUtil.X_DEVICE_USER_AGENT_HEADER, " device user agent ")
171+
.build())
172+
.build();
173+
174+
// when and then
175+
assertThat(extractor.uaFrom(httpRequest)).isEqualTo("device user agent");
176+
}
177+
163178
@Test
164179
public void secureFromShouldReturnOneIfXForwardedProtoIsHttps() {
165180
// given

src/test/java/org/prebid/server/log/HttpInteractionLoggerTest.java

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,100 @@ public void maybeLogOpenrtb2AmpShouldNotLogIfSpecEndpointIsNotAmp() {
280280
verifyNoInteractions(logger);
281281
}
282282

283+
@Test
284+
public void maybeLogOpenrtb2GetInterfaceShouldLogWithExpectedParams() {
285+
// given
286+
final AuctionContext givenAuctionContext =
287+
givenAuctionContext(accountBuilder -> accountBuilder.id("123"));
288+
final HttpLogSpec givenSpec = HttpLogSpec.of(null, null, "123", null, 1);
289+
290+
// when
291+
target.setSpec(givenSpec);
292+
target.maybeLogOpenrtb2GetInterface(givenAuctionContext, routingContext, 200, "responseBody");
293+
294+
// then
295+
verify(logger)
296+
.info("Requested URL: \"{}\", response status: \"{}\", response body: \"{}\"",
297+
"example.com",
298+
200,
299+
"responseBody");
300+
}
301+
302+
@Test
303+
public void maybeLogOpenrtb2GetInterfaceShouldLimitLogBySpecLimit() {
304+
// given
305+
final AuctionContext givenAuctionContext =
306+
givenAuctionContext(accountBuilder -> accountBuilder.id("123"));
307+
final HttpLogSpec givenSpec = HttpLogSpec.of(null, null, "123", null, 1);
308+
309+
// when
310+
target.setSpec(givenSpec);
311+
target.maybeLogOpenrtb2GetInterface(givenAuctionContext, routingContext, 200, null);
312+
target.maybeLogOpenrtb2GetInterface(givenAuctionContext, routingContext, 200, null);
313+
314+
// then
315+
verify(logger).info(anyString(), anyString(), any(), any());
316+
}
317+
318+
@Test
319+
public void maybeLogOpenrtb2GetInterfaceShouldNotLogIfAccountIdNotEqualsToGivenInSpec() {
320+
// given
321+
final AuctionContext givenAuctionContext =
322+
givenAuctionContext(accountBuilder -> accountBuilder.id("456"));
323+
final HttpLogSpec givenSpec = HttpLogSpec.of(null, null, "123", null, 1);
324+
325+
// when
326+
target.setSpec(givenSpec);
327+
target.maybeLogOpenrtb2GetInterface(givenAuctionContext, routingContext, 200, null);
328+
329+
// then
330+
verifyNoInteractions(logger);
331+
}
332+
333+
@Test
334+
public void maybeLogOpenrtb2GetInterfaceShouldLogIfStatusEqualsToGivenInSpec() {
335+
// given
336+
final AuctionContext givenAuctionContext = givenAuctionContext(identity());
337+
final HttpLogSpec givenSpec = HttpLogSpec.of(null, 501, null, null, 1);
338+
339+
// when
340+
target.setSpec(givenSpec);
341+
target.maybeLogOpenrtb2GetInterface(givenAuctionContext, routingContext, 200, null);
342+
target.maybeLogOpenrtb2GetInterface(givenAuctionContext, routingContext, 501, null);
343+
344+
// then
345+
verify(logger).info(anyString(), anyString(), eq(501), any());
346+
verify(logger, never()).info(anyString(), anyString(), eq(200), any());
347+
}
348+
349+
@Test
350+
public void maybeLogOpenrtb2GetInterfaceShouldLogIfSpecEndpointIsGetInterface() {
351+
// given
352+
final AuctionContext givenAuctionContext = givenAuctionContext(identity());
353+
final HttpLogSpec givenSpec = HttpLogSpec.of(HttpLogSpec.Endpoint.get_interface, null, null, null, 1);
354+
355+
// when
356+
target.setSpec(givenSpec);
357+
target.maybeLogOpenrtb2GetInterface(givenAuctionContext, routingContext, 200, null);
358+
359+
// then
360+
verify(logger).info(anyString(), anyString(), any(), any());
361+
}
362+
363+
@Test
364+
public void maybeLogOpenrtb2GetInterfaceShouldNotLogIfSpecEndpointIsNotGetInterface() {
365+
// given
366+
final AuctionContext givenAuctionContext = givenAuctionContext(identity());
367+
final HttpLogSpec givenSpec = HttpLogSpec.of(HttpLogSpec.Endpoint.auction, null, null, null, 1);
368+
369+
// when
370+
target.setSpec(givenSpec);
371+
target.maybeLogOpenrtb2GetInterface(givenAuctionContext, routingContext, 200, null);
372+
373+
// then
374+
verifyNoInteractions(logger);
375+
}
376+
283377
@Test
284378
public void maybeLogBidderRequestShouldLogWithExpectedParams() {
285379
// given

0 commit comments

Comments
 (0)