package com.trendrr.oss.tests;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.channels.SocketChannel;
import java.nio.charset.Charset;

import javax.net.SocketFactory;
import javax.net.ssl.SSLSocketFactory;

import junit.framework.Assert;

import org.junit.Test;

import com.trendrr.oss.DynMap;
import com.trendrr.oss.TypeCast;
import com.trendrr.oss.exceptions.TrendrrException;
import com.trendrr.oss.exceptions.TrendrrIOException;
import com.trendrr.oss.exceptions.TrendrrNetworkingException;
import com.trendrr.oss.networking.SocketChannelWrapper;
import com.trendrr.oss.networking.http.Http;
import com.trendrr.oss.networking.http.HttpRequest;
import com.trendrr.oss.networking.http.HttpResponse;

public class HttpTests {

	public static final String GET_url = "https://www.youtube.com/watch?v=jgMutAOEQ5I&feature=g-vrec";

	@Test
	public void GETTest() throws TrendrrException, UnsupportedEncodingException{
		HttpRequest request = new HttpRequest();
		request.setUrl(GET_url);
		request.setMethod("GET");
		HttpResponse response = Http.request(request);
		String html = new String(response.getContent(), "utf8").trim();
		System.out.println(html);
		//check that we read the whole html content
		Assert.assertTrue(html.endsWith("</html>"));
	}
	
	@Test
	public void pingTest() throws TrendrrNetworkingException {
		DynMap result = DynMap.instance(Http.get("strest.trendrr.com/ping"));
		Assert.assertEquals("PONG", result.getString("data"));
	}
	
	
//	@Test
	public void testRequest() throws TrendrrException, IOException{
		HttpRequest request = new HttpRequest();
		request.setUrl(GET_url);
		request.setMethod("GET");

//		request.setUrl("https://tools.questionmarket.com/verveindex/trendrr_ping.pl");
//		request.setMethod("POST");
//		request.setContent("application/json", "this is a test".getBytes());

		HttpResponse response = Http.request(request);
		String result = new String(response.getContent());
		Assert.assertEquals("{ \"status\":\"ok\" }", result);
	}
	
	
	

}

@@ -1739,16 +1739,80 @@
 ption %7B%0A
+//%09%09System.out.println(Http.get(%22strest.trendrr.com/ping%22));%0A%09%09%0A
 %09%09DynMap
@@ -1939,18 +1939,16 @@
 %0A%09%7D%0A%09%0A%09%0A
-//
 %09@Test%0A%09
@@ -2058,66 +2058,9 @@
 ();%0A
-%09%09request.setUrl(GET_url);%0A%09%09request.setMethod(%22GET%22);%0A%0A//
+%0A
 %09%09re
@@ -2132,26 +2132,24 @@
 _ping.pl%22);%0A
-//
 %09%09request.se
@@ -2165,18 +2165,16 @@
 POST%22);%0A
-//
 %09%09reques

update tests