package examples.templating;

import com.vtence.molecule.WebServer;
import com.vtence.molecule.support.http.DeprecatedHttpRequest;
import com.vtence.molecule.support.http.DeprecatedHttpResponse;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;

import static org.hamcrest.Matchers.containsString;

public class TemplatingAndLayoutTest {

    TemplatingAndLayoutExample templating = new TemplatingAndLayoutExample();
    WebServer server = WebServer.create(9999);

    DeprecatedHttpRequest request = new DeprecatedHttpRequest(9999);
    DeprecatedHttpResponse response;

    @Before
    public void startServer() throws IOException {
        templating.run(server);
    }

    @After
    public void stopServer() throws IOException {
        server.stop();
    }

    @Test
    public void renderingAnHtmlTemplateUsingMustache() throws IOException {
        response = request.get("/hello?name=Frodo");
        response.assertOK();
        response.assertHasContentType("text/html; charset=utf-8");
        response.assertContent(containsString("<p>Hello, Frodo!</p>"));
    }

    @Test
    public void applyingACommonLayoutToASetOfPages() throws IOException {
        response = request.get("/hello");
        response.assertOK();
        response.assertContent(containsString("<title>Layout - Hello World"));
        response.assertContent(containsString("<h1>A simple page</h1>"));
        response.assertContent(containsString("<meta name=\"description\" content=\"Hello World\">"));
        response.assertContent(containsString("Hello, World!"));
    }

    @Test
    public void skippingDecorationWhenResponseStatusIsNotOk() throws IOException {
        response = request.get("/not-found");
        response.assertHasStatusCode(404);
        response.assertContentEqualTo("Not found: /not-found");
    }
}
@@ -88,39 +88,21 @@
 olecule.
-support.http.Deprecated
+test.
 HttpRequ
@@ -137,31 +137,13 @@
 ule.
-support.http.Deprecated
+test.
 Http
@@ -254,16 +254,86 @@
 ption;%0A%0A
+import static com.vtence.molecule.test.HttpResponseAssert.assertThat;%0A
 import s
@@ -543,34 +543,24 @@
 9999);%0A%0A    
-Deprecated
 HttpRequest 
@@ -573,26 +573,16 @@
 t = new 
-Deprecated
 HttpRequ
@@ -600,18 +600,8 @@
     
-Deprecated
 Http
@@ -956,32 +956,43 @@
 %22);%0A        
+assertThat(
 response
 .assertOK();
@@ -975,36 +975,32 @@
 hat(response
-.assert
+).is
 OK()
-;
 %0A        res
@@ -996,32 +996,38 @@
         
-response.assertH
+                    .h
 asConten
@@ -1059,17 +1059,16 @@
 =utf-8%22)
-;
 %0A       
@@ -1068,37 +1068,47 @@
         
-response.assertConten
+                    .hasBodyTex
 t(contai
@@ -1279,32 +1279,43 @@
 %22);%0A        
+assertThat(
 response
 .assertOK();
@@ -1306,20 +1306,16 @@
 onse
-.assert
+).is
 OK()
-;
 %0A   
@@ -1319,37 +1319,47 @@
         
-response.assertConten
+                    .hasBodyTex
 t(contai
@@ -1398,17 +1398,16 @@
 World%22))
-;
 %0A       
@@ -1407,37 +1407,47 @@
         
-response.assertConten
+                    .hasBodyTex
 t(contai
@@ -1477,25 +1477,24 @@
 page%3C/h1%3E%22))
-;
 %0A        res
@@ -1490,37 +1490,47 @@
         
-response.assertConten
+                    .hasBodyTex
 t(contai
@@ -1589,25 +1589,24 @@
  World%5C%22%3E%22))
-;
 %0A        res
@@ -1602,37 +1602,47 @@
         
-response.assertConten
+                    .hasBodyTex
 t(contai
@@ -1651,16 +1651,19 @@
 String(%22
+%3Cp%3E
 Hello, W
@@ -1667,16 +1667,20 @@
 , World!
+%3C/p%3E
 %22));%0A   
@@ -1834,24 +1834,30 @@
     
-response.assertH
+assertThat(response).h
 asSt
@@ -1869,26 +1869,31 @@
 ode(404)
-;
 %0A
+      
         
 response
@@ -1888,37 +1888,34 @@
     
-response.assertContentEqualTo
+              .hasBodyText
 (%22No

Use lite http client in templating and layout example