package com.fenixinfotech.simple.framework.playpen;

import com.fenixinfotech.simple.framework.playpen.SimpleFrameworkServer;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.lang.Exception;

import static junit.framework.Assert.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static org.junit.Assert.assertTrue;

public class SimpleFrameworkServerTest
{
    SimpleFrameworkServer simpleFrameworkServer;

    @Before
    public void init() throws IOException
    {
        simpleFrameworkServer = new SimpleFrameworkServer();
        simpleFrameworkServer.runServer();
    }


    @After
    public void tidyup() throws IOException
    {
        simpleFrameworkServer.stopServer();
    }

    @Test
    public void testRunServer() throws Exception
    {
        assertNotNull(simpleFrameworkServer);
        HttpUriRequest request = new HttpGet( "http://localhost:" + SimpleFrameworkServer.defaultPort);
        HttpResponse response = HttpClientBuilder.create().build().execute(request);

        int    responseCode = response.getStatusLine().getStatusCode();
        String responseBody = EntityUtils.toString(response.getEntity()).trim();

        assertEquals(HttpStatus.SC_OK,                          responseCode);
        assertEquals(SimpleFrameworkServer.defaultResponseBody, responseBody);
    }
}
@@ -276,16 +276,64 @@
 ttpGet;%0A
+import org.apache.http.client.methods.HttpPost;%0A
 import o
@@ -569,16 +569,73 @@
 it.Test;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aimport
@@ -875,16 +875,115 @@
 rTest%0A%7B%0A
+    private static final Logger logger = LoggerFactory.getLogger(SimpleFrameworkServerTest.class);%0A
     Simp
@@ -1419,16 +1419,59 @@
 erver);%0A
+%0A        logger.info(%22testing http GET%22);%0A%0A
         
@@ -1485,17 +1485,20 @@
 Request 
-r
+getR
 equest =
@@ -1590,17 +1590,20 @@
 esponse 
-r
+getR
 esponse 
@@ -1647,17 +1647,20 @@
 execute(
-r
+getR
 equest);
@@ -1673,31 +1673,68 @@
     
-int    responseCode = r
+assertEquals(HttpStatus.SC_OK,                          getR
 espo
@@ -1768,16 +1768,17 @@
 usCode()
+)
 ;%0A      
@@ -1783,16 +1783,51 @@
     
-String r
+assertEquals(SimpleFrameworkServer.defaultR
 espo
@@ -1833,18 +1833,17 @@
 onseBody
- =
+,
  EntityU
@@ -1856,17 +1856,20 @@
 oString(
-r
+getR
 esponse.
@@ -1887,16 +1887,263 @@
 ).trim()
+);%0A%0A        logger.info(%22testing http POST%22);%0A%0A        HttpUriRequest postRequest = new HttpPost( %22http://localhost:%22 + SimpleFrameworkServer.defaultPort);%0A        HttpResponse postResponse = HttpClientBuilder.create().build().execute(postRequest)
 ;%0A%0A     
@@ -2205,20 +2205,52 @@
     
-r
+postR
 esponse
+.getStatusLine().getStatus
 Code
+()
 );%0A 
@@ -2316,20 +2316,61 @@
 dy, 
-responseBody
+EntityUtils.toString(postResponse.getEntity()).trim()
 );%0A 

Test both GET and POST.