use of com.xrtb.pojo.BidRequest in project XRTB by benmfaul.
the class TestNode method testOperators.
/**
* Test the various operators of the constraints.
* @throws Exception on file errors in configuration file.
*/
@Test
public void testOperators() throws Exception {
BidRequest br = new BidRequest(Configuration.getInputStream("SampleBids/nexage.txt"));
br.setExchange("nexage");
assertNotNull(br);
String content = new String(Files.readAllBytes(Paths.get("database.json")));
List<User> users = DbTools.mapper.readValue(content, DbTools.mapper.getTypeFactory().constructCollectionType(List.class, User.class));
User u = users.get(0);
List<Campaign> camps = u.campaigns;
assertNotNull(camps);
Campaign c = null;
for (Campaign x : camps) {
if (x.adId.equals("ben:payday")) {
c = x;
break;
}
}
Node n = c.getAttribute("site.domain");
List<String> list = (List) n.value;
// add this to the campaign blacklist
list.add("junk1.com");
String op = "NOT_MEMBER";
Node node = new Node("blacklist", "site.domain", op, list);
list.add("junk1.com");
// true means the constraint is satisfied.
Boolean b = node.test(br);
// should be on blacklist and will not bid
assertFalse(b);
op = "MEMBER";
node = new Node("blacklist", "site.domain", op, list);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid
assertTrue(b);
op = "EQUALS";
node = new Node("=", "user.yob", op, 1961);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid */
assertTrue(b);
String str = node.getLucene();
System.out.println(str);
node = new Node("=", "user.yob", op, 1960);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid */
assertFalse(b);
node = new Node("=", "user.yob", op, 1962);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid */
assertFalse(b);
op = "NOT_EQUALS";
node = new Node("!=", "user.yob", op, 1901);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid */
assertTrue(b);
op = "LESS_THAN";
node = new Node("<", "user.yob", op, 1960);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid */
assertTrue(b);
op = "LESS_THAN_EQUALS";
node = new Node("<=", "user.yob", op, 1960);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid */
assertTrue(b);
op = "GREATER_THAN";
node = new Node(">", "user.yob", op, 1962);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid */
assertTrue(b);
op = "GREATER_THAN_EQUALS";
node = new Node(">=", "user.yob", op, 1961);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid */
assertTrue(b);
op = "DOMAIN";
List range = new ArrayList();
range.add(new Double(1960));
range.add(new Double(1962));
node = new Node("inrangetest", "user.yob", op, range);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid */
assertTrue(b);
BidRequest brx = new BidRequest(Configuration.getInputStream("SampleBids/msie.txt"));
brx.setExchange("nexage");
op = "REGEX";
node = new Node("regex", "device.ua", op, ".*MSIE.*");
b = node.test(brx);
assertTrue(b);
op = "NOT_REGEX";
node = new Node("regex", "device.ua", op, ".*MSIE.*");
b = node.test(brx);
assertFalse(b);
op = "NOT_REGEX";
node = new Node("regex", "device.ua", op, ".*MSIE.*");
b = node.test(br);
assertTrue(b);
op = "STRINGIN";
node = new Node("stringintest", "site.page", op, "xxx");
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid */
assertFalse(b);
op = "NOT_STRINGIN";
node = new Node("stringintest", "site.page", op, "xxx");
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid */
assertTrue(b);
op = "STRINGIN";
node = new Node("stringintest", "site.page", op, "nexage");
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid */
assertTrue(b);
op = "NOT_STRINGIN";
node = new Node("stringintest", "site.page", op, "nexage");
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid */
assertFalse(b);
op = "STRINGIN";
list = new ArrayList();
list.add("nexage");
list.add("xxx");
node = new Node("stringintest", "site.page", op, list);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid */
assertTrue(b);
op = "STRINGIN";
String[] parts = new String[2];
parts[0] = "nexage";
parts[1] = "xxx";
node = new Node("stringintest", "site.page", op, parts);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid */
assertTrue(b);
node = new Node("exchangetest", "exchange", "EQUALS", "smartyads");
b = node.test(br);
assertFalse(b);
Arrays.asList("site.name", "app.name");
// node = new Node("eitheror",Arrays.asList("site.domain", "app.domain"),"EQUALS","smartyads");
b = node.test(br);
assertFalse(b);
br = new BidRequest(Configuration.getInputStream("SampleBids/atomx.txt"));
br.setExchange("atomx");
assertNotNull(br);
List<Integer> ilist = new ArrayList();
ilist.add(2);
node = new Node("devicetypes", "device.devicetype", Node.INTERSECTS, ilist);
b = node.test(br);
assertTrue(b);
br = new BidRequest(Configuration.getInputStream("SampleBids/atomx.txt"));
br.setExchange("atomx");
assertNotNull(br);
ilist = new ArrayList();
ilist.add(1);
ilist.add(4);
ilist.add(5);
node = new Node("devicetypes", "device.devicetype", Node.INTERSECTS, ilist);
b = node.test(br);
assertFalse(b);
br = new BidRequest(Configuration.getInputStream("SampleBids/atomx.txt"));
br.setExchange("atomx");
assertNotNull(br);
ilist = new ArrayList();
ilist.add(1);
ilist.add(2);
ilist.add(5);
node = new Node("devicetypes", "device.devicetype", Node.INTERSECTS, ilist);
b = node.test(br);
assertTrue(b);
br = new BidRequest(Configuration.getInputStream("SampleBids/atomx.txt"));
br.setExchange("atomx");
assertNotNull(br);
node = new Node("site-test", "site", Node.EXISTS, null);
b = node.test(br);
assertTrue(b);
br = new BidRequest(Configuration.getInputStream("SampleBids/atomx.txt"));
br.setExchange("atomx");
assertNotNull(br);
node = new Node("aoo-test", "app", Node.EXISTS, null);
node.notPresentOk = false;
b = node.test(br);
assertFalse(b);
br = new BidRequest(Configuration.getInputStream("SampleBids/atomx.txt"));
br.setExchange("atomx");
assertNotNull(br);
node = new Node("aoo-test", "app", Node.NOT_EXISTS, null);
b = node.test(br);
assertTrue(b);
ilist.clear();
ilist.add(1);
ilist.add(2);
ilist.add(3);
node = new Node("aoo-test", "member test", Node.MEMBER, 1);
boolean test = node.testInternal(ilist);
}
use of com.xrtb.pojo.BidRequest in project XRTB by benmfaul.
the class TestRanges method testGeoInBidRequest.
/**
* Test a single geo fence region in an isolated node.
* @throws Exception on I/O errors.
*/
@Test
public void testGeoInBidRequest() throws Exception {
InputStream is = Configuration.getInputStream("SampleBids/smaato.json");
BidRequest br = new BidRequest(is);
assertEquals(br.getId(), "K6t8sXXYdM");
Map m = new HashMap();
m.put("lat", 34.05);
m.put("lon", -118.25);
m.put("range", 600000.0);
List list = new ArrayList();
list.add(m);
Node node = new Node("LATLON", "device.geo", Node.INRANGE, list);
node.test(br);
ObjectNode map = (ObjectNode) node.getBRvalue();
assertTrue((Double) map.get("lat").doubleValue() == 37.62);
assertTrue((Double) map.get("lon").doubleValue() == -122.38);
assertTrue((Double) map.get("type").doubleValue() == 3);
List<Map> test = new ArrayList();
test.add(m);
node = new Node("LATLON", "device.geo", Node.INRANGE, test);
node.test(br);
}
use of com.xrtb.pojo.BidRequest in project XRTB by benmfaul.
the class TestNode method testSets.
/**
* Test the set operations.
* @throws Exception on configuration file errors.
*/
@Test
public void testSets() throws Exception {
BidRequest br = new BidRequest(Configuration.getInputStream("SampleBids/nexage.txt"));
assertNotNull(br);
String content = new String(Files.readAllBytes(Paths.get("database.json")));
List<User> users = DbTools.mapper.readValue(content, DbTools.mapper.getTypeFactory().constructCollectionType(List.class, User.class));
User u = users.get(0);
List<Campaign> camps = u.campaigns;
assertNotNull(camps);
Campaign c = null;
for (Campaign x : camps) {
if (x.adId.equals("ben:payday")) {
c = x;
break;
}
}
Node n = c.getAttribute("site.domain");
List<String> list = (List) n.value;
list.add("junk.com");
String op = "INTERSECTS";
Node node = new Node("blacklist", "site.domain", op, list);
// true means the constraint is satisfied.
Boolean b = node.test(br);
// should be on blacklist and will not bid
assertFalse(b);
/**
* Test adding an array of objects
*/
String[] parts = new String[1];
op = "INTERSECTS";
parts[0] = "junk.com";
node = new Node("blacklist-array", "site.domain", op, parts);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid
assertFalse(b);
n = new Node("matching-categories", "site.cat", Node.INTERSECTS, parts);
list.add("junk1.com");
node = new Node("blacklist", "site.domain", op, list);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid
assertTrue(b);
list.clear();
node = new Node("blacklist", "site.domain", op, list);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid
assertFalse(b);
op = "NOT_INTERSECTS";
node = new Node("blacklist", "site.domain", op, list);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid
assertTrue(b);
op = "MEMBER";
node = new Node("mimes", "imp.0.banner.mimes", op, "image/jpg");
b = node.test(br);
assertTrue(b);
}
use of com.xrtb.pojo.BidRequest in project XRTB by benmfaul.
the class TestNode method testOr.
@Test
public void testOr() throws Exception {
BidRequest br = new BidRequest(Configuration.getInputStream("SampleBids/atomx.txt"));
br.setExchange("atomx");
assertNotNull(br);
List ilist = new ArrayList();
Node a = new Node("site", "site.publisher.id", Node.EQUALS, "3456");
ilist.add(a);
a = new Node("site", "app.publisher.id", Node.EQUALS, "3456");
ilist.add(a);
Node node = new Node("ortest", null, Node.OR, ilist);
Boolean b = node.test(br);
assertTrue(b);
// reverse order
ilist = new ArrayList();
a = new Node("site", "app.publisher.id", Node.EQUALS, "3456");
ilist.add(a);
a = new Node("site", "site.publisher.id", Node.EQUALS, "3456");
ilist.add(a);
node = new Node("ortest", null, Node.OR, ilist);
b = node.test(br);
assertTrue(b);
// actual is second and bad
ilist = new ArrayList();
a = new Node("app", "app.publisher.id", Node.EQUALS, "3456");
ilist.add(a);
a = new Node("site", "site.publisher.id", Node.EQUALS, "666");
ilist.add(a);
node = new Node("ortest", null, Node.OR, ilist);
b = node.test(br);
assertFalse(b);
// actual is first and bad
ilist = new ArrayList();
a = new Node("site", "site.publisher.id", Node.EQUALS, "666");
ilist.add(a);
a = new Node("app", "app.publisher.id", Node.EQUALS, "3456");
ilist.add(a);
node = new Node("ortest", null, Node.OR, ilist);
b = node.test(br);
assertFalse(b);
}
use of com.xrtb.pojo.BidRequest in project XRTB by benmfaul.
the class TestNode method testOperatorsInImpressions.
@Test
public void testOperatorsInImpressions() throws Exception {
BidRequest br = new BidRequest(Configuration.getInputStream("SampleBids/c1x.txt"));
br.setExchange("c1x");
assertNotNull(br);
/* Node node = new Node("=","imp.0.banner.tagid","EQUALS","14404-loge-300x25");
boolean b = node.test(br); // true means the constraint is satisfied.
assertTrue(b);
br = new BidRequest(Configuration.getInputStream("SampleBids/c1xMulti.txt"));
br.setExchange( "c1x" );
assertNotNull(br);
node = new Node("=","imp.0.banner.id","EQUALS","2");
b = node.test(br); // true means the constraint is satisfied.
assertFalse(b);
node = new Node("=","imp.1.banner.id","EQUALS","2");
b = node.test(br); // true means the constraint is satisfied.
assertTrue(b); */
br = new BidRequest(Configuration.getInputStream("SampleBids/c1xMulti.txt"));
ArrayList list = new ArrayList();
list.add("2");
Node node = new Node("=", "imp.*.banner.id", Node.INTERSECTS, list);
// true means the constraint is satisfied.
boolean b = node.test(br);
assertTrue(b);
}
Aggregations