Search in sources :

Example 6 with BidRequest

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);
}
Also used : User(com.xrtb.db.User) Node(com.xrtb.common.Node) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) BidRequest(com.xrtb.pojo.BidRequest) Campaign(com.xrtb.common.Campaign) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 7 with BidRequest

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);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Node(com.xrtb.common.Node) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) BidRequest(com.xrtb.pojo.BidRequest) Test(org.junit.Test)

Example 8 with BidRequest

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);
}
Also used : User(com.xrtb.db.User) Campaign(com.xrtb.common.Campaign) Node(com.xrtb.common.Node) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) List(java.util.List) BidRequest(com.xrtb.pojo.BidRequest) Test(org.junit.Test)

Example 9 with BidRequest

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);
}
Also used : Node(com.xrtb.common.Node) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BidRequest(com.xrtb.pojo.BidRequest) Test(org.junit.Test)

Example 10 with BidRequest

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);
}
Also used : Node(com.xrtb.common.Node) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) BidRequest(com.xrtb.pojo.BidRequest) Test(org.junit.Test)

Aggregations

BidRequest (com.xrtb.pojo.BidRequest)20 Test (org.junit.Test)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 Node (com.xrtb.common.Node)10 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Campaign (com.xrtb.common.Campaign)5 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 User (com.xrtb.db.User)3 BidResponse (com.xrtb.pojo.BidResponse)3 BufferedReader (java.io.BufferedReader)3 FileReader (java.io.FileReader)3 Map (java.util.Map)3 AerospikeHandler (com.aerospike.redisson.AerospikeHandler)2 AbortableCountDownLatch (com.xrtb.bidder.AbortableCountDownLatch)2 CampaignProcessor (com.xrtb.bidder.CampaignProcessor)2 SelectedCreative (com.xrtb.bidder.SelectedCreative)2 NobidResponse (com.xrtb.pojo.NobidResponse)2 CountDownLatch (java.util.concurrent.CountDownLatch)2