package org.stagemonitor.core.util;

import java.io.IOException;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class HttpClientTest {

	private HttpClient httpClient;

	@Before
	public void setup() {
		httpClient = new HttpClient();
	}

	@Test
	public void testNoNullPointerExceptionOnSend() throws IOException {
		try {
			httpClient.send("POST", "incorrect-url", null, null);
		} catch (NullPointerException t) {
			Assert.fail("Shouldn't throw NPE");
		} catch (Exception ignore) {
			//whatever
		}
	}
}

@@ -41,62 +41,329 @@
 ort 
-java.io.IOException;%0A%0Aimport org.junit.Assert;
+org.eclipse.jetty.server.Request;%0Aimport org.eclipse.jetty.server.Server;%0Aimport org.eclipse.jetty.server.handler.AbstractHandler;%0Aimport org.junit.*;%0A%0Aimport java.io.IOException;%0A%0Aimport javax.servlet.ServletException;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0A
 %0Aimport 
 org.
@@ -350,32 +350,39 @@
 sponse;%0A%0Aimport 
+static 
 org.junit.Before
@@ -375,22 +375,35 @@
 g.junit.
-Before
+Assert.assertEquals
 ;%0Aimport
@@ -395,32 +395,39 @@
 tEquals;%0Aimport 
+static 
 org.junit.Test;%0A
@@ -420,20 +420,33 @@
 g.junit.
-Test
+Assert.assertTrue
 ;%0A%0Apubli
@@ -501,16 +501,59 @@
 tpClient
+ = new HttpClient();%0A%09private Server server
 ;%0A%0A%09@Bef
@@ -576,44 +576,130 @@
  set
-u
+U
 p() 
-%7B%0A%09%09httpClient = new HttpClient
+throws Exception %7B%0A%09%09server = new Server(41234);%0A%09%7D%0A%0A%09@After%0A%09public void tearDown() throws Exception %7B%0A%09%09server.stop
 ();%0A
@@ -883,16 +883,26 @@
 t) %7B%0A%09%09%09
+org.junit.
 Assert.f
@@ -980,11 +980,590 @@
 r%0A%09%09%7D%0A%09%7D
+%0A%0A%09@Test%0A%09public void testBasicAuth() throws Exception %7B%0A%09%09final boolean%5B%5D handled = %7Bfalse%7D;%0A%09%09server.setHandler(new AbstractHandler() %7B%0A%09%09%09@Override%0A%09%09%09public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException %7B%0A%09%09%09%09baseRequest.setHandled(true);%0A%09%09%09%09assertEquals(%22Basic dXNlcjpwYXNz%22, request.getHeader(%22Authorization%22));%0A%09%09%09%09handled%5B0%5D = true;%0A%09%09%09%7D%0A%09%09%7D);%0A%09%09server.start();%0A%0A%09%09assertEquals(200, httpClient.send(%22GET%22, %22http://user:pass@localhost:41234/%22));%0A%09%09assertTrue(handled%5B0%5D);%0A%09%7D
 %0A%7D%0A

Test HttpClient basic auth