Search in sources :

Example 6 with Campaign

use of com.xrtb.common.Campaign in project XRTB by benmfaul.

the class TestLucene method testLucene.

@Test
public void testLucene() {
    Campaign c = Configuration.getInstance().campaignsList.get(0);
    System.out.println(c.getLucene());
}
Also used : Campaign(com.xrtb.common.Campaign) Test(org.junit.Test)

Example 7 with Campaign

use of com.xrtb.common.Campaign 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 8 with Campaign

use of com.xrtb.common.Campaign in project XRTB by benmfaul.

the class CampaignSelector method add.

/**
	 * Adds a campaign to the list of usable campaigns.
	 * 
	 * @param campaign
	 *            . A new campaign to add.
	 */
public void add(Campaign campaign) throws Exception {
    boolean state = RTBServer.stopped;
    Thread.sleep(100);
    RTBServer.stopped = true;
    for (int i = 0; i < config.campaignsList.size(); i++) {
        Campaign camp = config.campaignsList.get(i);
        if (camp.owner.equals(campaign.owner) && camp.adId.equals(campaign.adId)) {
            config.campaignsList.remove(i);
            config.campaignsList.add(campaign);
            RTBServer.stopped = state;
            return;
        }
    }
    RTBServer.stopped = state;
    config.campaignsList.add(campaign);
}
Also used : Campaign(com.xrtb.common.Campaign)

Example 9 with Campaign

use of com.xrtb.common.Campaign in project XRTB by benmfaul.

the class WebCampaign method startCampaign.

/**
	 * Starts the campaign from the web portal
	 * 
	 * @param cmd
	 *            Map. The JSON command structure from the web user.
	 * @return String. The JSON string of all the running campaigns in this
	 *         bidder.
	 */
public String startCampaign(Map cmd) throws Exception {
    Map response = new HashMap();
    try {
        String id = getString(cmd.get("id"));
        String name = (String) cmd.get("username");
        id = id.replaceAll("\"", "");
        Campaign c = db.getCampaign(name, id);
        Controller.getInstance().addCampaign(c);
        response.put("error", false);
        AddCampaign command = new AddCampaign(null, name, id);
        command.to = "*";
        command.from = Configuration.getInstance().instanceName;
        Controller.getInstance().sendLog(3, "WebAccess-Start-Campaign", "Campaign start: " + id);
    } catch (Exception error) {
        response.put("message", "failed: " + error.toString());
        response.put("error", true);
    }
    response.put("running", Configuration.getInstance().getLoadedCampaignNames());
    return getString(response);
}
Also used : AddCampaign(com.xrtb.commands.AddCampaign) Campaign(com.xrtb.common.Campaign) AddCampaign(com.xrtb.commands.AddCampaign) DeleteCampaign(com.xrtb.commands.DeleteCampaign) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with Campaign

use of com.xrtb.common.Campaign in project XRTB by benmfaul.

the class TestWinProcessing method testCappingTimes1.

@Test
public void testCappingTimes1() throws Exception {
    redisson.del("capped_blocker166.137.138.18");
    for (Campaign c : Configuration.getInstance().campaignsList) {
        if (c.adId.equals("ben:payday")) {
            for (Creative cc : c.creatives) {
                if (cc.impid.equals("blocker")) {
                    cc.capFrequency = 1;
                    break;
                }
            }
        }
    }
    HttpPostGet http = new HttpPostGet();
    String bid = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexage50x50.txt")))).toString();
    // Get 1 time is ok, but 2d time is a no bid
    String s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", bid, 100000, 100000);
    assertNotNull(s);
    int rc = http.getResponseCode();
    assertTrue(rc == 200);
    String value = redisson.get("capped_blocker166.137.138.18");
    assertTrue(value == null);
    Bid win = new Bid(s);
    String repl = win.nurl.replaceAll("\\$", "");
    win.nurl = repl.replace("{AUCTION_PRICE}", ".05");
    System.out.println(win.nurl);
    s = http.sendPost(win.nurl, "", 30000, 30000);
    value = redisson.get("capped_blocker166.137.138.18");
    assertTrue(value.equals("1"));
    // better no bid.
    s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", bid, 100000, 100000);
    rc = http.getResponseCode();
    assertTrue(rc == 204);
    assertNull(s);
    rc = http.getResponseCode();
    value = redisson.get("capped_blocker166.137.138.18");
    assertTrue(value.equals("1"));
    System.out.println("DONE!");
}
Also used : Campaign(com.xrtb.common.Campaign) Creative(com.xrtb.common.Creative) HttpPostGet(com.xrtb.common.HttpPostGet) Bid(com.xrtb.pojo.Bid) Test(org.junit.Test)

Aggregations

Campaign (com.xrtb.common.Campaign)27 User (com.xrtb.db.User)13 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 Configuration (com.xrtb.common.Configuration)7 List (java.util.List)7 Creative (com.xrtb.common.Creative)6 RTBServer (com.xrtb.bidder.RTBServer)5 Node (com.xrtb.common.Node)5 BidRequest (com.xrtb.pojo.BidRequest)5 DbTools (com.xrtb.tools.DbTools)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 AddCampaign (com.xrtb.commands.AddCampaign)4 DeleteCampaign (com.xrtb.commands.DeleteCampaign)4 SelectedCreative (com.xrtb.bidder.SelectedCreative)3 BidResponse (com.xrtb.pojo.BidResponse)3 HttpPostGet (com.xrtb.common.HttpPostGet)2 Bid (com.xrtb.pojo.Bid)2