package jp.hashiwa.accountbook;

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("/accountbook/show"))
      .andDo(print())
      .andExpect(status().isOk())
      .andExpect(content().contentType(TEXT_HTML_UTF8))
      .andExpect(content().string(containsString("<title>Account Book</title>")))
      .andExpect(content().string(containsString("table table-striped")))
      .andExpect(content().string(containsString("Date")))
      .andExpect(content().string(containsString("Amount")))
      .andExpect(content().string(containsString("Name")))
      .andExpect(content().string(containsString("Type")))
      .andExpect(content().string(containsString("Description")))
      .andExpect(content().string(containsString("Remarks")));
  }

  @Test
  public void testTodoListCreate() throws Exception {
    this.mockMvc.perform(get("/accountbook/create"))
      .andDo(print())
      .andExpect(status().isOk())
      .andExpect(content().contentType(TEXT_HTML_UTF8))
      .andExpect(content().string(containsString("<title>Account Book</title>")))
      .andExpect(content().string(containsString("<form action=\"/accountbook/create\" method=\"post\">")))
      .andExpect(content().string(containsString("<label for=\"inputDate\">Date</label>")))
      .andExpect(content().string(containsString("<label for=\"inputAmount\">Amount</label>")))
      .andExpect(content().string(containsString("<label for=\"inputName\">Name</label>")))
      .andExpect(content().string(containsString("<label for=\"inputType\">Type</label>")))
      .andExpect(content().string(containsString("<label for=\"inputDesc\">Description</label>")))
      .andExpect(content().string(containsString("<label for=\"inputRemarks\">Remarks</label>")));
  }

}

@@ -165,16 +165,104 @@
 rs.get;%0A
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;%0A
 import s
@@ -3216,10 +3216,721 @@
 );%0A  %7D%0A%0A
+  @Test%0A  public void testTodoListCreate2() throws Exception %7B%0A    this.mockMvc.perform(post(%22/accountbook/create%22).param(%22date%22, %222016-12-15%22).param(%22amount%22, %221000%22).param(%22name%22, %22test%22).param(%22type%22, %22xxx%22).param(%22desc%22, %22%22).param(%22remarks%22, %22%22))%0A      .andDo(print())%0A      .andExpect(status().isOk())%0A      .andExpect(content().contentType(TEXT_HTML_UTF8))%0A      .andExpect(content().string(containsString(%22Created:%22)))%0A      .andExpect(content().string(containsString(%22xxx%22)));%0A    this.mockMvc.perform(get(%22/accountbook/show%22))%0A      .andDo(print())%0A      .andExpect(status().isOk())%0A      .andExpect(content().contentType(TEXT_HTML_UTF8))%0A      .andExpect(content().string(containsString(%22xxx%22)));%0A  %7D%0A
 %7D%0A

add create test