Search in sources :

Example 26 with Campaign

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

the class Config method setup.

public static void setup(String configFile) throws Exception {
    try {
        DbTools tools = new DbTools("localhost:3000");
        tools.clear();
        tools.loadDatabase("database.json");
        if (server == null) {
            server = new RTBServer(configFile);
            int wait = 0;
            while (!server.isReady() && wait < 10) {
                Thread.sleep(1000);
                wait++;
            }
            if (wait == 10) {
                fail("Server never started");
            }
            Thread.sleep(1000);
        } else {
            Configuration c = Configuration.getInstance();
            c.campaignsList.clear();
            User u = DataBaseObject.getInstance().get("ben");
            for (Campaign camp : u.campaigns) {
                c.addCampaign("ben", camp.adId);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.toString());
    }
}
Also used : RTBServer(com.xrtb.bidder.RTBServer) User(com.xrtb.db.User) Campaign(com.xrtb.common.Campaign) Configuration(com.xrtb.common.Configuration) DbTools(com.xrtb.tools.DbTools)

Example 27 with Campaign

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

the class TestWinProcessing method testCappingTimes3.

/**
	   * 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 testCappingTimes3() 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 = 3;
                    break;
                }
            }
        }
    }
    HttpPostGet http = new HttpPostGet();
    String bid = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexage50x50.txt")))).toString();
    // Get 3 times is ok, but 4th 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");
    s = http.sendPost(win.nurl, "");
    value = redisson.get("capped_blocker166.137.138.18");
    assertTrue(value.equals("1"));
    s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", bid, 100000, 100000);
    assertNotNull(s);
    rc = http.getResponseCode();
    assertTrue(rc == 200);
    s = http.sendPost(win.nurl, "");
    value = redisson.get("capped_blocker166.137.138.18");
    assertTrue(value.equals("2"));
    s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", bid, 100000, 100000);
    assertNotNull(s);
    rc = http.getResponseCode();
    assertTrue(rc == 200);
    s = http.sendPost(win.nurl, "");
    value = redisson.get("capped_blocker166.137.138.18");
    assertTrue(value.equals("3"));
    // 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("3"));
    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