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());
}
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);
}
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);
}
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);
}
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!");
}
Aggregations