Skip to content

Commit 272ed31

Browse files
authored
Merge pull request lightbody#669 from jekh/remove-har-tests-with-external-dependencies
Removed tests from legacy HarTest that used external websites
2 parents 46aa6c6 + a4c5e4a commit 272ed31

File tree

1 file changed

+0
-194
lines changed
  • browsermob-legacy/src/test/java/net/lightbody/bmp/proxy

1 file changed

+0
-194
lines changed

browsermob-legacy/src/test/java/net/lightbody/bmp/proxy/HarTest.java

Lines changed: 0 additions & 194 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
import net.lightbody.bmp.core.har.HarEntry;
66
import net.lightbody.bmp.core.har.HarLog;
77
import net.lightbody.bmp.core.har.HarNameValuePair;
8-
import net.lightbody.bmp.core.har.HarNameVersion;
98
import net.lightbody.bmp.core.har.HarPage;
109
import net.lightbody.bmp.core.har.HarPageTimings;
1110
import net.lightbody.bmp.core.har.HarPostData;
1211
import net.lightbody.bmp.core.har.HarRequest;
1312
import net.lightbody.bmp.core.har.HarResponse;
14-
import net.lightbody.bmp.core.har.HarTimings;
1513
import net.lightbody.bmp.proxy.test.util.LocalServerTest;
1614
import net.lightbody.bmp.proxy.util.IOUtils;
1715
import org.apache.http.HttpEntity;
@@ -20,7 +18,6 @@
2018
import org.apache.http.client.methods.HttpPost;
2119
import org.apache.http.entity.StringEntity;
2220
import org.apache.http.message.BasicNameValuePair;
23-
import org.apache.http.util.EntityUtils;
2421
import org.junit.Test;
2522

2623
import java.io.ByteArrayOutputStream;
@@ -30,7 +27,6 @@
3027
import java.util.Collections;
3128
import java.util.List;
3229
import java.util.Random;
33-
import java.util.concurrent.TimeUnit;
3430
import java.util.zip.GZIPInputStream;
3531

3632
import static org.hamcrest.Matchers.containsString;
@@ -285,82 +281,6 @@ public void testThatGzippedContentIsProperlyCapturedInHar() throws IOException,
285281
assertEquals("Text not matched", "this is a.txt", text);
286282
}
287283

288-
@Test
289-
public void testHarTimingsPopulated() throws IOException, InterruptedException {
290-
proxy.setCaptureHeaders(true);
291-
proxy.newHar("testHarTimingsPopulated");
292-
293-
HttpGet httpGet = new HttpGet("https://www.msn.com");
294-
EntityUtils.consumeQuietly(client.execute(httpGet).getEntity());
295-
296-
Thread.sleep(500);
297-
Har har = proxy.getHar();
298-
assertNotNull("Har is null", har);
299-
HarLog log = har.getLog();
300-
assertNotNull("Log is null", log);
301-
302-
assertNotNull("No log entries", log.getEntries());
303-
assertThat("No log entries", log.getEntries(), not(empty()));
304-
305-
HarEntry firstEntry = log.getEntries().get(0);
306-
HarTimings timings = firstEntry.getTimings();
307-
308-
assertNotNull("No har timings", timings);
309-
assertThat("blocked timing should be greater than 0", timings.getBlocked(TimeUnit.NANOSECONDS), greaterThan(0L));
310-
assertThat("dns timing should be greater than 0", timings.getDns(TimeUnit.NANOSECONDS), greaterThan(0L));
311-
assertThat("connect timing should be greater than 0", timings.getConnect(TimeUnit.NANOSECONDS), greaterThan(0L));
312-
assertThat("send timing should be greater than 0", timings.getSend(TimeUnit.NANOSECONDS), greaterThan(0L));
313-
assertThat("wait timing should be greater than 0", timings.getWait(TimeUnit.NANOSECONDS), greaterThan(0L));
314-
assertThat("receive timing should be greater than 0", timings.getReceive(TimeUnit.NANOSECONDS), greaterThan(0L));
315-
assertThat("ssl timing should be greater than 0", timings.getSsl(TimeUnit.NANOSECONDS), greaterThan(0L));
316-
}
317-
318-
@Test
319-
public void testChunkedRequestSizeAndSendTimingPopulated() throws IOException, InterruptedException {
320-
proxy.setCaptureContent(true);
321-
proxy.newHar("testChunkedRequestSizeAndSendTimingPopulated");
322-
323-
// using this POST dumping ground so that we get a "reasonable" send time. using the server at localhost
324-
// may not actually take more than 1ms. that would cause the send time to be 0ms, which would be indistinguishable
325-
// for testing purposes from a failed-to--populate-send-time error condition.
326-
// thanks to Henry Cipolla for creating this POST testing website!
327-
HttpPost post = new HttpPost("http://posttestserver.com/");
328-
329-
// fill the POST data with some random ascii text
330-
String lengthyPost = createRandomString(30000);
331-
332-
HttpEntity entity = new StringEntity(lengthyPost);
333-
post.setEntity(entity);
334-
post.addHeader("Content-Type", "text/unknown; charset=UTF-8");
335-
336-
String body = IOUtils.toStringAndClose(client.execute(post).getEntity().getContent());
337-
338-
Thread.sleep(500);
339-
Har har = proxy.getHar();
340-
assertNotNull("Har is null", har);
341-
HarLog log = har.getLog();
342-
assertNotNull("Log is null", log);
343-
344-
assertNotNull("No log entries", log.getEntries());
345-
assertThat("No log entries", log.getEntries(), not(empty()));
346-
347-
HarEntry firstEntry = log.getEntries().get(0);
348-
HarTimings timings = firstEntry.getTimings();
349-
350-
HarResponse response = firstEntry.getResponse();
351-
assertNotNull("Response is null", response);
352-
HarRequest request = firstEntry.getRequest();
353-
assertNotNull("Request is null", request);
354-
HarPostData postdata = request.getPostData();
355-
assertNotNull("PostData is null", postdata);
356-
357-
assertEquals("Expected body size to match POST length", lengthyPost.length(), request.getBodySize());
358-
359-
assertNotNull("No har timings", timings);
360-
361-
assertThat("send timing should be greater than 0", timings.getSend(TimeUnit.NANOSECONDS), greaterThan(0L));
362-
}
363-
364284
@Test
365285
public void testHarPagesPopulated() throws IOException, InterruptedException {
366286
proxy.newHar("testpage1");
@@ -439,120 +359,6 @@ public void testHarPageTitlePopulated() throws Exception {
439359
assertEquals("incorrect har page title", "Test Page 2", page2.getTitle());
440360
}
441361

442-
@Test
443-
public void testEntryFieldsPopulatedForHttp() throws IOException, InterruptedException {
444-
proxy.newHar("testEntryFieldsPopulatedForHttp");
445-
446-
// not using localhost so we get >0ms timing
447-
HttpGet get = new HttpGet("http://www.msn.com");
448-
IOUtils.toStringAndClose(client.execute(get).getEntity().getContent());
449-
450-
proxy.endPage();
451-
452-
Thread.sleep(500);
453-
Har firstPageHar = proxy.getHar();
454-
assertNotNull("Har is null", firstPageHar);
455-
HarLog firstPageHarLog = firstPageHar.getLog();
456-
assertNotNull("Log is null", firstPageHarLog);
457-
458-
List<HarEntry> firstPageEntries = firstPageHarLog.getEntries();
459-
assertNotNull("Entries are null", firstPageEntries);
460-
assertThat("Entries are empty", firstPageEntries, not(empty()));
461-
462-
HarEntry firstPageEntry = firstPageHarLog.getEntries().get(0);
463-
assertNotEquals("entry time should be greater than 0 but was " + firstPageEntry.getTime(), firstPageEntry.getTime(), 0L);
464-
assertNotNull("entry startedDateTime is null", firstPageEntry.getStartedDateTime());
465-
466-
assertEquals("entry pageref is incorrect", "testEntryFieldsPopulatedForHttp", firstPageEntry.getPageref());
467-
468-
assertNotNull("entry ip address is not populated", firstPageEntry.getServerIPAddress());
469-
470-
// make a second request for the same page, and make sure the address is still populated
471-
proxy.newPage("testEntryFieldsPopulatedForHttp - page 2");
472-
IOUtils.toStringAndClose(client.execute(get).getEntity().getContent());
473-
474-
proxy.endPage();
475-
476-
// this is technically the same HAR, but aliasing for clarity
477-
Har secondPageHar = proxy.getHar();
478-
assertNotNull("Har is null", secondPageHar);
479-
HarLog secondPageHarLog = secondPageHar.getLog();
480-
assertNotNull("Log is null", secondPageHarLog);
481-
482-
List<HarEntry> secondPageEntries = secondPageHarLog.getEntries();
483-
assertNotNull("Entries are null", secondPageEntries);
484-
assertThat("Entries are empty", secondPageEntries, not(empty()));
485-
486-
HarEntry secondPageEntry = secondPageHarLog.getEntries().get(1);
487-
assertNotEquals("entry time should be greater than 0 but was " + secondPageEntry.getTime(), secondPageEntry.getTime(), 0L);
488-
assertNotNull("entry startedDateTime is null", secondPageEntry.getStartedDateTime());
489-
490-
assertEquals("entry pageref is incorrect", "testEntryFieldsPopulatedForHttp - page 2", secondPageEntry.getPageref());
491-
492-
// this fails on the jetty implementation, but it shouldn't
493-
if (Boolean.getBoolean("bmp.use.littleproxy")) {
494-
assertNotNull("entry ip address is not populated", secondPageEntry.getServerIPAddress());
495-
assertEquals("expected ip address of first and second request to same host to be equal", firstPageEntry.getServerIPAddress(), secondPageEntry.getServerIPAddress());
496-
}
497-
}
498-
499-
@Test
500-
public void testEntryFieldsPopulatedForHttps() throws IOException, InterruptedException {
501-
proxy.newHar("testEntryFieldsPopulatedForHttps");
502-
503-
// not using localhost so we get >0ms timing
504-
HttpGet get = new HttpGet("https://www.msn.com");
505-
IOUtils.toStringAndClose(client.execute(get).getEntity().getContent());
506-
507-
proxy.endPage();
508-
509-
Thread.sleep(500);
510-
Har firstPageHar = proxy.getHar();
511-
assertNotNull("Har is null", firstPageHar);
512-
HarLog firstPageHarLog = firstPageHar.getLog();
513-
assertNotNull("Log is null", firstPageHarLog);
514-
515-
List<HarEntry> firstPageEntries = firstPageHarLog.getEntries();
516-
assertNotNull("Entries are null", firstPageEntries);
517-
assertThat("Entries are empty", firstPageEntries, not(empty()));
518-
519-
HarEntry firstPageEntry = firstPageHarLog.getEntries().get(0);
520-
assertNotEquals("entry time should be greater than 0 but was " + firstPageEntry.getTime(), firstPageEntry.getTime(), 0L);
521-
assertNotNull("entry startedDateTime is null", firstPageEntry.getStartedDateTime());
522-
523-
assertEquals("entry pageref is incorrect", "testEntryFieldsPopulatedForHttps", firstPageEntry.getPageref());
524-
525-
assertNotNull("entry ip address is not populated", firstPageEntry.getServerIPAddress());
526-
527-
// make a second request for the same page, and make sure the address is still populated
528-
proxy.newPage("testEntryFieldsPopulatedForHttps - page 2");
529-
IOUtils.toStringAndClose(client.execute(get).getEntity().getContent());
530-
531-
proxy.endPage();
532-
533-
// this is technically the same HAR, but aliasing for clarity
534-
Har secondPageHar = proxy.getHar();
535-
assertNotNull("Har is null", secondPageHar);
536-
HarLog secondPageHarLog = secondPageHar.getLog();
537-
assertNotNull("Log is null", secondPageHarLog);
538-
539-
List<HarEntry> secondPageEntries = secondPageHarLog.getEntries();
540-
assertNotNull("Entries are null", secondPageEntries);
541-
assertThat("Entries are empty", secondPageEntries, not(empty()));
542-
543-
HarEntry secondPageEntry = secondPageHarLog.getEntries().get(1);
544-
assertNotEquals("entry time should be greater than 0 but was " + secondPageEntry.getTime(), secondPageEntry.getTime(), 0L);
545-
assertNotNull("entry startedDateTime is null", secondPageEntry.getStartedDateTime());
546-
547-
assertEquals("entry pageref is incorrect", "testEntryFieldsPopulatedForHttps - page 2", secondPageEntry.getPageref());
548-
549-
// this fails on the jetty implementation, but it shouldn't
550-
if (Boolean.getBoolean("bmp.use.littleproxy")) {
551-
assertNotNull("entry ip address is not populated", secondPageEntry.getServerIPAddress());
552-
assertEquals("expected ip address of first and second request to same host to be equal", firstPageEntry.getServerIPAddress(), secondPageEntry.getServerIPAddress());
553-
}
554-
}
555-
556362
@Test
557363
public void testIpAddressPopulatedForLocalhost() throws IOException, InterruptedException {
558364
proxy.newHar("testIpAddressPopulated");

0 commit comments

Comments
 (0)