Search in sources :

Example 56 with HttpPostGet

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

the class TestValidBids method testVideoRespondWithBidAfterRecompile.

/**
	 * Test a valid bid response.
	 * 
	 * @throws Exception
	 *             on networking errors.
	 */
@Test
public void testVideoRespondWithBidAfterRecompile() throws Exception {
    HttpPostGet http = new HttpPostGet();
    String s = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexageVideo.txt")))).toString();
    long time = 0;
    /******** Make one bid to prime the pump */
    try {
        http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", s);
    } catch (Exception error) {
        fail("Network error");
    }
    /*********************************/
    Configuration.getInstance().recompile();
    String xtime = null;
    try {
        s = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexageVideo.txt")))).toString();
        try {
            time = System.currentTimeMillis();
            s = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", s);
            time = System.currentTimeMillis() - time;
            xtime = http.getHeader("X-TIME");
        } catch (Exception error) {
            fail("Can't connect to test host: " + Config.testHost);
        }
        assertNotNull(s);
        System.out.println(s + "\n----------");
        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("99999999"));
        list = (List) m.get("bid");
        assertEquals(list.size(), 1);
        m = (Map) list.get(0);
        assertNotNull(m);
        test = (String) m.get("impid");
        assertTrue(test.equals("35c22289-06e2-48e9-a0cd-94aeb79fab43-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 == 3.0);
        test = (String) m.get("adid");
        assertTrue(test.equals("ben:payday"));
        test = (String) m.get("cid");
        assertTrue(test.equals("ben:payday"));
        test = (String) m.get("crid");
        assertTrue(test.equals("iAmVideo"));
        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)

Example 57 with HttpPostGet

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

the class TestZZZRedis method stopStartBidder.

/**
	 * Test starting and stopping the rtb bidder engine.
	 * 
	 * @throws Exception
	 *             on Redis errors.
	 */
@Test
public void stopStartBidder() throws Exception {
    StopBidder e = new StopBidder();
    e.id = "STOPBIDDER-ID";
    rcv = null;
    latch = new CountDownLatch(1);
    commands.add(e);
    latch.await(5, TimeUnit.SECONDS);
    System.out.println("------------>" + rcv);
    assertTrue(rcv.msg.equals("stopped"));
    // Now make a bid
    HttpPostGet http = new HttpPostGet();
    String s = Charset.defaultCharset().decode(ByteBuffer.wrap(Files.readAllBytes(Paths.get("./SampleBids/nexage.txt")))).toString();
    long time = 0;
    String str = null;
    try {
        str = http.sendPost("http://" + Config.testHost + "/rtb/bids/nexage", s);
    } catch (Exception error) {
        fail("Network error");
    }
    assertNull(str);
    assertTrue(http.getResponseCode() == 204);
    StartBidder ee = new StartBidder();
    ee.id = "STARTBIDDER-ID";
    latch = new CountDownLatch(1);
    commands.add(ee);
    latch.await(5, TimeUnit.SECONDS);
    time = System.currentTimeMillis();
    test = rcv.msg;
    assertTrue(test.equals("running"));
}
Also used : StopBidder(com.xrtb.commands.StopBidder) HttpPostGet(com.xrtb.common.HttpPostGet) CountDownLatch(java.util.concurrent.CountDownLatch) StartBidder(com.xrtb.commands.StartBidder) 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