use of com.xrtb.common.HttpPostGet in project XRTB by benmfaul.
the class TestValidBids method testInterstitial.
/**
* Test a valid bid response with no bid, the campaign doesn't match width
* or height of the bid request
*
* @throws Exception
* on network errors.
*/
@Test
public void testInterstitial() throws Exception {
HttpPostGet http = new HttpPostGet();
String s = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/interstitial.txt")))).toString();
try {
s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", s, 100000, 100000);
} catch (Exception error) {
fail("Network error");
}
System.out.println(s);
int rc = http.getResponseCode();
assertTrue(rc == 204);
assertTrue(http.getHeader("X-REASON").equals("No matching campaign"));
}
use of com.xrtb.common.HttpPostGet in project XRTB by benmfaul.
the class TestValidBids method testNativeAppWall.
@Test
public void testNativeAppWall() throws Exception {
HttpPostGet http = new HttpPostGet();
String bid = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexageNativeAppWall.txt")))).toString();
String s = null;
long time = 0;
/******** Make one bid to prime the pump */
try {
http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", bid, 30000, 30000);
} catch (Exception error) {
fail("Network error");
}
/*********************************/
String xtime = null;
try {
try {
time = System.currentTimeMillis();
s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", bid);
time = System.currentTimeMillis() - time;
xtime = http.getHeader("X-TIME");
} catch (Exception error) {
fail("Can't connect to test host: " + Config.testHost);
}
assertNotNull(s);
System.out.println(s + "\n----------");
Map m = null;
try {
m = DbTools.mapper.readValue(s, Map.class);
} catch (Exception error) {
fail("Bad JSON for bid");
}
List list = (List) m.get("seatbid");
m = (Map) list.get(0);
assertNotNull(m);
String test = (String) m.get("seat");
assertTrue(test.equals("99999999"));
list = (List) m.get("bid");
assertEquals(list.size(), 1);
m = (Map) list.get(0);
assertNotNull(m);
test = (String) m.get("impid");
assertTrue(test.equals("39c22289-06e2-48e9-a0cd-94aeb79fab43-1=3"));
test = (String) m.get("id");
assertNotNull(test);
Double d = (Double) m.get("price");
assertNotNull(d);
assertTrue(d == 5.0);
test = (String) m.get("adid");
assertTrue(test.equals("ben:payday"));
test = (String) m.get("cid");
assertTrue(test.equals("ben:payday"));
test = (String) m.get("crid");
assertTrue(test.equals("iAmAnAppWall"));
list = (List) m.get("adomain");
test = (String) list.get(0);
assertTrue(test.equals("originator.com"));
System.out.println("XTIME: " + xtime);
System.out.println("RTTIME: " + time);
System.out.println(s);
assertFalse(s.contains("pub"));
assertFalse(s.contains("ad_id"));
assertFalse(s.contains("bid_id"));
assertFalse(s.contains("site_id"));
/**
* Remove the layout in the request, it should still bid
*/
Map map = DbTools.mapper.readValue(bid, Map.class);
list = (List) map.get("imp");
Map sub = (Map) list.get(0);
sub = (Map) sub.get("native");
sub.remove("layout");
s = DbTools.mapper.writer().withDefaultPrettyPrinter().writeValueAsString(map);
try {
time = System.currentTimeMillis();
s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", s);
time = System.currentTimeMillis() - time;
xtime = http.getHeader("X-TIME");
} catch (Exception error) {
fail("Can't connect to test host: " + Config.testHost);
}
assertNotNull(s);
/*
* Make the title too short
*/
map = DbTools.mapper.readValue(bid, Map.class);
list = (List) map.get("imp");
sub = (Map) list.get(0);
sub = (Map) sub.get("native");
list = (List) sub.get("assets");
sub = (Map) list.get(0);
sub = (Map) sub.get("title");
sub.put("len", 1);
s = DbTools.mapper.writer().withDefaultPrettyPrinter().writeValueAsString(map);
System.out.println(s);
try {
time = System.currentTimeMillis();
s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", s);
time = System.currentTimeMillis() - time;
xtime = http.getHeader("X-TIME");
} catch (Exception error) {
fail("Can't connect to test host: " + Config.testHost);
}
assertNull(s);
/*
* Make img have wrong size
*/
map = DbTools.mapper.readValue(bid, Map.class);
list = (List) map.get("imp");
sub = (Map) list.get(0);
sub = (Map) sub.get("native");
list = (List) sub.get("assets");
sub = (Map) list.get(2);
sub = (Map) sub.get("img");
sub.put("w", 1);
s = DbTools.mapper.writer().withDefaultPrettyPrinter().writeValueAsString(map);
try {
time = System.currentTimeMillis();
s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", s);
time = System.currentTimeMillis() - time;
xtime = http.getHeader("X-TIME");
} catch (Exception error) {
fail("Can't connect to test host: " + Config.testHost);
}
assertNull(s);
/*
* Make img have wrong size
*/
map = DbTools.mapper.readValue(bid, Map.class);
list = (List) map.get("imp");
sub = (Map) list.get(0);
sub = (Map) sub.get("native");
list = (List) sub.get("assets");
sub = (Map) list.get(2);
sub = (Map) sub.get("img");
sub.put("h", 1);
s = DbTools.mapper.writer().withDefaultPrettyPrinter().writeValueAsString(map);
try {
time = System.currentTimeMillis();
s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", s);
time = System.currentTimeMillis() - time;
xtime = http.getHeader("X-TIME");
} catch (Exception error) {
fail("Can't connect to test host: " + Config.testHost);
}
assertNull(s);
/*
* Make the length to long on a data item
*/
map = DbTools.mapper.readValue(bid, Map.class);
list = (List) map.get("imp");
sub = (Map) list.get(0);
sub = (Map) sub.get("native");
list = (List) sub.get("assets");
sub = (Map) list.get(3);
sub = (Map) sub.get("data");
sub.put("len", 1);
s = DbTools.mapper.writer().withDefaultPrettyPrinter().writeValueAsString(map);
try {
time = System.currentTimeMillis();
s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", s);
time = System.currentTimeMillis() - time;
xtime = http.getHeader("X-TIME");
} catch (Exception error) {
fail("Can't connect to test host: " + Config.testHost);
}
assertNull(s);
/*
* Make it the wrong layout
*/
map = DbTools.mapper.readValue(bid, Map.class);
list = (List) map.get("imp");
sub = (Map) list.get(0);
sub = (Map) sub.get("native");
sub.put("layout", 4);
s = DbTools.mapper.writer().withDefaultPrettyPrinter().writeValueAsString(map);
try {
time = System.currentTimeMillis();
s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", s);
time = System.currentTimeMillis() - time;
xtime = http.getHeader("X-TIME");
} catch (Exception error) {
fail("Can't connect to test host: " + Config.testHost);
}
assertNull(s);
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
}
use of com.xrtb.common.HttpPostGet in project XRTB by benmfaul.
the class TestValidBids method testCapptureOverride.
@Test
public void testCapptureOverride() throws Exception {
HttpPostGet http = new HttpPostGet();
String bid = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/cappture-override.txt")))).toString();
String s = null;
long time = 0;
String xtime = null;
try {
try {
time = System.currentTimeMillis();
s = http.sendPost("http://" + Config.testHost + "/rtb/bids/cappture", bid);
time = System.currentTimeMillis() - time;
xtime = http.getHeader("X-TIME");
} catch (Exception error) {
fail("Can't connect to test host: " + Config.testHost);
}
assertNotNull(s);
int index = s.indexOf("%3C");
assertTrue(index == -1);
index = s.indexOf("override");
assertTrue(index > -1);
System.out.println(s);
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
}
use of com.xrtb.common.HttpPostGet in project XRTB by benmfaul.
the class TestValidBids method testAtomxEncoding.
@Test
public void testAtomxEncoding() throws Exception {
HttpPostGet http = new HttpPostGet();
String bid = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexage.txt")))).toString();
String s = null;
long time = 0;
String xtime = null;
try {
try {
time = System.currentTimeMillis();
s = http.sendPost("http://" + Config.testHost + "/rtb/bids/atomx", bid);
time = System.currentTimeMillis() - time;
xtime = http.getHeader("X-TIME");
} catch (Exception error) {
fail("Can't connect to test host: " + Config.testHost);
}
assertNotNull(s);
int index = s.indexOf("%3C");
assertTrue(index == -1);
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
}
use of com.xrtb.common.HttpPostGet in project XRTB by benmfaul.
the class TestValidBids method testSuspect2.
@Test
public void testSuspect2() throws Exception {
HttpPostGet http = new HttpPostGet();
String bid = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/another-suspect.txt")))).toString();
String s = null;
long time = 0;
String xtime = null;
try {
try {
time = System.currentTimeMillis();
s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", bid, 300000, 300000);
time = System.currentTimeMillis() - time;
xtime = http.getHeader("X-TIME");
} catch (Exception error) {
fail("Can't connect to test host: " + Config.testHost);
}
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
}
Aggregations