package net.lightbody.bmp.proxy;

import java.util.List;

import net.lightbody.bmp.core.har.Har;
import net.lightbody.bmp.core.har.HarEntry;
import net.lightbody.bmp.core.har.HarLog;

import org.apache.http.client.methods.HttpGet;
import static org.hamcrest.CoreMatchers.*;
import org.junit.Assert;
import org.junit.Test;

public class HarResultsTest extends DummyServerTest {
    @Test
    public void testRequestAndResponseSizesAreSet() throws Exception {

        // see https://github.com/lightbody/browsermob-proxy/pull/36 for history

        proxy.setCaptureContent(true);
        proxy.newHar("test");

        HttpGet get = new HttpGet("http://127.0.0.1:8080/a.txt");
        client.execute(get);

        Har har = proxy.getHar();
        HarLog log = har.getLog();
        List<HarEntry> entries = log.getEntries();
        HarEntry entry = entries.get(0);

        Assert.assertEquals(100, entry.getRequest().getHeadersSize());
        Assert.assertEquals(0, entry.getRequest().getBodySize());
        // 226 for Windows, 227 for other platforms? Can it be that simple?
        Assert.assertThat((int)entry.getResponse().getHeadersSize(), anyOf(is(226),is(227)));
        Assert.assertEquals(13, entry.getResponse().getBodySize());
    }

}

@@ -874,31 +874,223 @@
     
-Assert.assertEquals(100
+/*%0A        Request headers should be something like this:%0A%0A        Host: 127.0.0.1:8080%0A        User-Agent: bmp.lightbody.net/2.0-beta-10-SNAPSHOT%0A         */%0A        Assert.assertTrue(%22Minimum header size not seen%22
 , en
@@ -1118,24 +1118,29 @@
 eadersSize()
+ %3E 70
 );%0A        A
@@ -1192,24 +1192,25 @@
 odySize());%0A
+%0A
         // 2
@@ -1210,106 +1210,389 @@
    /
-/ 226 for Windows, 227 for other platforms? Can it be that simple?%0A        Assert.assertThat((int)
+*%0A        Response headers should be something like this:%0A%0A        Date: Sun, 31 Aug 2014 16:08:44 GMT%0A        Server: Jetty/5.1.x (Mac OS X/10.9.4 x86_64 java/1.7.0_09%0A        Content-Type: text/plain%0A        Content-Length: 13%0A        Last-Modified: Sun, 17 Nov 2013 05:37:58 GMT%0A        Accept-Ranges: bytes%0A         */%0A        Assert.assertTrue(%22Minimum header size not seen%22, 
 entr
@@ -1627,32 +1627,14 @@
 ze()
-, anyOf(is(226),is(227))
+ %3E 200
 );%0A 

test passes more reliably