Search in sources :

Example 51 with HttpPostGet

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

the class TestWinProcessing method testWinProcessingEpom.

@Test
public void testWinProcessingEpom() throws Exception {
    HttpPostGet http = new HttpPostGet();
    redisson.del("35c22289-06e2-48e9-a0cd-94aeb79fab43");
    // Make the bid
    String s = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexage.txt")))).toString();
    /**
		 * Send the bid
		 */
    try {
        s = http.sendPost("http://" + Config.testHost + "/rtb/bids/epomx", s, 3000000, 3000000);
    } catch (Exception error) {
        fail("Can't connect to test host: " + Config.testHost);
    }
    int code = http.getResponseCode();
    assertTrue(code == 200);
    Bid bid = null;
    System.out.println(s);
    int x = s.indexOf("{bid_id");
    assertTrue(x == -1);
    x = s.indexOf("%7Bbid_id");
    assertTrue(x == -1);
    try {
        bid = new Bid(s);
    } catch (Exception error) {
        error.printStackTrace();
        fail();
    }
    // Now retrieve the bid information from the cache
    Map m = redisson.hgetAll(bid.id);
    assertTrue(!m.isEmpty());
    String price = (String) m.get("PRICE");
    System.out.println("PRICE: " + price);
    assertNotNull(price);
    assertTrue(!price.equals("0.0"));
    /**
		 * Send the win notification
		 */
    try {
        String repl = bid.nurl.replaceAll("\\$", "");
        bid.nurl = repl.replace("{AUCTION_PRICE}", ".05");
        s = http.sendPost(bid.nurl, "");
    } catch (Exception error) {
        error.printStackTrace();
        fail();
    }
    System.out.println(s);
    x = s.indexOf("{creative_");
    assertTrue(x == -1);
    /*
		 * Make sure the returned adm is not crap html 
		 */
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(s));
    //	Document doc = db.parse(is);
    // Check to see the bid was removed from the cache
    m = redisson.hgetAll(bid.id);
    assertNull(m);
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) HttpPostGet(com.xrtb.common.HttpPostGet) StringReader(java.io.StringReader) Bid(com.xrtb.pojo.Bid) Map(java.util.Map) Test(org.junit.Test)

Example 52 with HttpPostGet

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

the class TestWinProcessing method testWinProcessingCappture.

@Test
public void testWinProcessingCappture() throws Exception {
    HttpPostGet http = new HttpPostGet();
    redisson.del("35c22289-06e2-48e9-a0cd-94aeb79fab43");
    // Make the bid
    String s = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexage.txt")))).toString();
    /**
		 * Send the bid
		 */
    try {
        s = http.sendPost("http://" + Config.testHost + "/rtb/bids/cappture", s, 3000000, 3000000);
    } catch (Exception error) {
        error.printStackTrace();
        fail("Can't connect to test host: " + Config.testHost);
    }
    int code = http.getResponseCode();
    assertTrue(code == 200);
    Bid bid = null;
    System.out.println(s);
    int x = s.indexOf("{bid_id");
    assertTrue(x == -1);
    x = s.indexOf("%7Bbid_id");
    assertTrue(x == -1);
    try {
        bid = new Bid(s);
    } catch (Exception error) {
        error.printStackTrace();
        fail();
    }
    // Now retrieve the bid information from the cache
    Map m = redisson.hgetAll(bid.id);
    assertTrue(!m.isEmpty());
    String price = (String) m.get("PRICE");
    assertNotNull(price);
    assertTrue(!price.equals("0"));
    /**
		 * Send the win notification
		 */
    try {
        String repl = bid.nurl.replaceAll("\\$", "");
        bid.nurl = repl.replace("{AUCTION_PRICE}", ".05");
        s = http.sendPost(bid.nurl, "");
    } catch (Exception error) {
        error.printStackTrace();
        fail();
    }
    System.out.println(s);
    x = s.indexOf("{creative_");
    assertTrue(x == -1);
    /*
		 * Make sure the returned adm is not crap html 
		 */
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(s));
    //	Document doc = db.parse(is);
    // Check to see the bid was removed from the cache
    m = redisson.hgetAll(bid.id);
    assertNull(m);
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) HttpPostGet(com.xrtb.common.HttpPostGet) StringReader(java.io.StringReader) Bid(com.xrtb.pojo.Bid) Map(java.util.Map) Test(org.junit.Test)

Example 53 with HttpPostGet

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

the class TestValidBids method testCapptureEncoding.

@Test
public void testCapptureEncoding() throws Exception {
    HttpPostGet http = new HttpPostGet();
    String bid = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexage.txt")))).toString();
    String s = null;
    long time = 0;
    String xtime = null;
    try {
        try {
            time = System.currentTimeMillis();
            s = http.sendPost("http://" + Config.testHost + "/rtb/bids/cappture", bid);
            time = System.currentTimeMillis() - time;
            xtime = http.getHeader("X-TIME");
        } catch (Exception error) {
            fail("Can't connect to test host: " + Config.testHost);
        }
        assertNotNull(s);
        int index = s.indexOf("%3C");
        assertTrue(index == -1);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.toString());
    }
}
Also used : HttpPostGet(com.xrtb.common.HttpPostGet) Test(org.junit.Test)

Example 54 with HttpPostGet

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

the class TestValidBids method testEpomEncoding.

@Test
public void testEpomEncoding() throws Exception {
    HttpPostGet http = new HttpPostGet();
    String bid = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexage.txt")))).toString();
    String s = null;
    long time = 0;
    String xtime = null;
    try {
        try {
            time = System.currentTimeMillis();
            s = http.sendPost("http://" + Config.testHost + "/rtb/bids/epomx", bid);
            time = System.currentTimeMillis() - time;
            xtime = http.getHeader("X-TIME");
        } catch (Exception error) {
            fail("Can't connect to test host: " + Config.testHost);
        }
        assertNotNull(s);
        int index = s.indexOf("%3C");
        assertTrue(index == -1);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.toString());
    }
}
Also used : HttpPostGet(com.xrtb.common.HttpPostGet) Test(org.junit.Test)

Example 55 with HttpPostGet

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

the class TestValidBids method testAtomx.

@Test
public void testAtomx() throws Exception {
    HttpPostGet http = new HttpPostGet();
    String s = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexage.txt")))).toString();
    long time = 0;
    String xtime = null;
    try {
        try {
            time = System.currentTimeMillis();
            s = http.sendPost("http://" + Config.testHost + "/rtb/bids/atomx", s, 100000, 100000);
            time = System.currentTimeMillis() - time;
            xtime = http.getHeader("X-TIME");
        } catch (Exception error) {
            fail("Can't connect to test host: " + Config.testHost);
        }
        assertNotNull(s);
        Map m = null;
        try {
            m = DbTools.mapper.readValue(s, Map.class);
        } catch (Exception error) {
            fail("Bad JSON for bid");
        }
        List list = (List) m.get("seatbid");
        m = (Map) list.get(0);
        assertNotNull(m);
        String test = (String) m.get("seat");
        assertTrue(test.equals("atomxseatid"));
        list = (List) m.get("bid");
        assertEquals(list.size(), 1);
        m = (Map) list.get(0);
        assertNotNull(m);
        test = (String) m.get("impid");
        assertTrue(test.equals("1"));
        test = (String) m.get("id");
        assertTrue(test.equals("35c22289-06e2-48e9-a0cd-94aeb79fab43") || test.equals("123"));
        double d = (Double) m.get("price");
        // assertTrue(d == 1.0);
        test = (String) m.get("adid");
        System.out.println(test);
        assertTrue(test.equals("ben:payday"));
        test = (String) m.get("cid");
        assertTrue(test.equals("ben:payday"));
        list = (List) m.get("adomain");
        test = (String) list.get(0);
        assertTrue(test.equals("originator.com"));
        System.out.println("XTIME: " + xtime);
        System.out.println("RTTIME: " + time);
        System.out.println(s);
        assertFalse(s.contains("pub"));
        assertFalse(s.contains("ad_id"));
        assertFalse(s.contains("bid_id"));
        assertFalse(s.contains("site_id"));
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.toString());
    }
}
Also used : HttpPostGet(com.xrtb.common.HttpPostGet) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Aggregations

HttpPostGet (com.xrtb.common.HttpPostGet)57 Test (org.junit.Test)40 Map (java.util.Map)24 List (java.util.List)13 Bid (com.xrtb.pojo.Bid)9 BufferedReader (java.io.BufferedReader)7 FileReader (java.io.FileReader)7 HashMap (java.util.HashMap)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 StringReader (java.io.StringReader)5 ArrayList (java.util.ArrayList)5 DocumentBuilder (javax.xml.parsers.DocumentBuilder)5 InputSource (org.xml.sax.InputSource)5 GoogleBidResponse (com.xrtb.exchanges.google.GoogleBidResponse)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Campaign (com.xrtb.common.Campaign)2 Creative (com.xrtb.common.Creative)2 AdxBidResponse (com.xrtb.exchanges.adx.AdxBidResponse)2 GoogleBidRequest (com.xrtb.exchanges.google.GoogleBidRequest)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2