use of com.xrtb.common.Node in project XRTB by benmfaul.
the class TestNode method makeSimpleCampaign.
/* @Test
public void testOs() throws Exception {
List<String> parts = new ArrayList();
parts.add("Android");
Node node = new Node("test","device.os","MEMBER",parts);
node.notPresentOk = false;
BufferedReader br = new BufferedReader(new FileReader("../requests"));
for(String line; (line = br.readLine()) != null; ) {
BidRequest bidR = new BidRequest(new StringBuilder(line));
boolean x = node.test(bidR);
if (x == true) {
JsonNode os = (JsonNode)bidR.interrogate("device.os");
if (os.textValue() == null) {
System.out.println("NULL");
return;
}
assertTrue(os.textValue().equals("Android"));
}
}
} */
/**
* Trivial test of the payload atributes
* @throws Exception on configuration file errors.
*/
@Test
public void makeSimpleCampaign() 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");
assertNotNull(n);
List<String> list = (List) n.value;
assertNotNull(list);
String op = (String) n.op;
assertTrue(op.equals("NOT_MEMBER"));
}
use of com.xrtb.common.Node in project XRTB by benmfaul.
the class TestNode method testNotMemberWithBidRequest.
/**
* Tests that br does not have the app key
* @throws Exception on io errors.
*/
@Test
public void testNotMemberWithBidRequest() throws Exception {
BidRequest br = new BidRequest(Configuration.getInputStream("SampleBids/nexage.txt"));
br.setExchange("nexage");
assertNotNull(br);
Node node = new Node("nm", "app", Node.NOT_EXISTS, null);
// true means the constraint is satisfied.
boolean b = node.test(br);
assertTrue(b);
}
use of com.xrtb.common.Node 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.common.Node 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.common.Node 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);
}
Aggregations