package jp.hashiwa.todolist;

import static org.hamcrest.Matchers.containsString;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.nio.charset.Charset;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class ApplicationTest {

  private static final MediaType TEXT_HTML_UTF8 = new MediaType(MediaType.TEXT_HTML, Charset.forName("utf-8"));

  @Autowired
  private MockMvc mockMvc;

  @Test
  public void shouldReturnDefaultMessage() throws Exception {
    this.mockMvc.perform(get("/"))
      .andDo(print())
      .andExpect(status().isOk());
      //.andExpect(content().string(containsString("List of Applications")));
  }

  @Test
  public void testTodoListShow() throws Exception {
    this.mockMvc.perform(get("/todolist/show"))
      .andDo(print())
      .andExpect(status().isOk())
      .andExpect(content().contentType(TEXT_HTML_UTF8))
      .andExpect(content().string(containsString("<title>Todo List</title>")))
      .andExpect(content().string(containsString("table table-striped")))
      .andExpect(content().string(containsString("Id")))
      .andExpect(content().string(containsString("Title")))
      .andExpect(content().string(containsString("Memo")))
      .andExpect(content().string(containsString("Deadline")));
  }

  @Test
  public void testTodoListCreate() throws Exception {
    this.mockMvc.perform(get("/todolist/create"))
      .andDo(print())
      .andExpect(status().isOk())
      .andExpect(content().contentType(TEXT_HTML_UTF8))
      .andExpect(content().string(containsString("<title>Todo List</title>")))
      .andExpect(content().string(containsString("<form action=\"/todolist/create\" method=\"post\">")))
      .andExpect(content().string(containsString("<label for=\"inputTitle\">Title</label>")))
      .andExpect(content().string(containsString("<label for=\"inputMemo\">Memo</label>")))
      .andExpect(content().string(containsString("<label for=\"inputDeadline\">Deadline</label>")));
  }


}

@@ -12,24 +12,27 @@
 hashiwa.
-todolist
+accountbook
 ;%0A%0Aimpor
@@ -1476,24 +1476,27 @@
 m(get(%22/
-todolist
+accountbook
 /show%22))
@@ -1661,33 +1661,36 @@
 ing(%22%3Ctitle%3E
-Todo List
+Account Book
 %3C/title%3E%22)))
@@ -1818,10 +1818,12 @@
 ng(%22
-Id
+Date
 %22)))
@@ -1873,20 +1873,80 @@
 String(%22
-Titl
+Amount%22)))%0A      .andExpect(content().string(containsString(%22Nam
 e%22)))%0A  
@@ -1993,20 +1993,20 @@
 String(%22
-Memo
+Type
 %22)))%0A   
@@ -2054,22 +2054,87 @@
 ring(%22De
-adline
+scription%22)))%0A      .andExpect(content().string(containsString(%22Remarks
 %22)));%0A  
@@ -2229,24 +2229,27 @@
 m(get(%22/
-todolist
+accountbook
 /create%22
@@ -2424,17 +2424,20 @@
 tle%3E
-Todo List
+Account Book
 %3C/ti
@@ -2515,16 +2515,19 @@
 =%5C%22/
-todolist
+accountbook
 /cre
@@ -2625,20 +2625,18 @@
 nput
-Title%5C%22%3ETitl
+Date%5C%22%3EDat
 e%3C/l
@@ -2717,19 +2717,23 @@
 nput
-Memo%5C%22%3EMemo
+Amount%5C%22%3EAmount
 %3C/la
@@ -2813,27 +2813,308 @@
 nput
-Deadline%5C%22%3EDeadline
+Name%5C%22%3EName%3C/label%3E%22)))%0A      .andExpect(content().string(containsString(%22%3Clabel for=%5C%22inputType%5C%22%3EType%3C/label%3E%22)))%0A      .andExpect(content().string(containsString(%22%3Clabel for=%5C%22inputDesc%5C%22%3EDescription%3C/label%3E%22)))%0A      .andExpect(content().string(containsString(%22%3Clabel for=%5C%22inputRemarks%5C%22%3ERemarks
 %3C/la
@@ -3128,11 +3128,10 @@
 );%0A  %7D%0A%0A
-%0A
 %7D%0A

fix tests