package com.danchu.momuck.controller;

import static org.hamcrest.Matchers.hasKey;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import com.danchu.momuck.dao.AccountDao;
import com.danchu.momuck.dao.RestaurantDao;

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = { "classpath:/root-context.xml", "classpath:servlet-context.xml" })
public class RestaurantControllerTest {

	private static final String NAME = "리틀 파스타";
	private static final float AVG_SCORE = 0;
	private static final String LOCATION_COORD = "0,0";
	private static final String LOCATION_TEXT = "서울시 동작구";
	private static final String PHONE_NUMBER = "01044444444";
	private static final String IMAGE_MAIN = "test.jpg";
	private static final String IMAGE_EXTRA = "test_extra.jpg";

	@Autowired
	private WebApplicationContext wac;

	private MockMvc mockMvc;

	@Autowired
	private RestaurantDao restaurantDao;

	@Before
	public void setup() {
		this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
	}

	@Test
	public void insertRestaurant() throws Exception {
		String jsonParm = "{" + "\"name\" : \"" + NAME + "\"," + "\"avg_score\" : " + AVG_SCORE + "," + "\"location_coord\" : \""
				+ LOCATION_COORD + "\"," + "\"location_text\" : \"" + LOCATION_TEXT + "\"," + "\"phone_number\" : \""
				+ PHONE_NUMBER + "\"," + "\"image_main\" : \"" + IMAGE_MAIN + "\","+ "\"image_extra\" : \"" + IMAGE_EXTRA + "\"}";

		this.mockMvc.perform(post("/restaurants").contentType(MediaType.APPLICATION_JSON).content(jsonParm))
				.andExpect(status().isOk())
				.andExpect(content().contentType("application/json;charset=UTF-8"))
				.andExpect(jsonPath("$", hasKey("code")))
				.andExpect(jsonPath("$.code").value("200"))
				.andReturn();
	}
	
	@After
	public void clear() {
		restaurantDao.deleteRestaurant(NAME);
	}
}
@@ -76,16 +76,103 @@
 hasKey;%0A
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;%0A
 import s
@@ -247,24 +247,24 @@
 lders.post;%0A
-
 import stati
@@ -1648,20 +1648,22 @@
 R = %22010
+-
 4444
+-
 4444%22;%0A%09
@@ -2711,24 +2711,24 @@
 lue(%22200%22))%0A
-
 %09%09%09%09.andRetu
@@ -2738,16 +2738,393 @@
 );%0A%09%7D%0A%09%0A
+%09@Test%0A%09public void selectRestaurant() throws Exception %7B%0A%09%09this.mockMvc.perform(get(%22/restaurants/%7Brestaurant_id%7D%22, 7).contentType(MediaType.APPLICATION_JSON))%0A%09%09%09.andExpect(status().isOk())%0A%09%09%09.andExpect(content().contentType(%22application/json;charset=UTF-8%22))%0A%09%09%09.andExpect(jsonPath(%22$%22, hasKey(%22code%22)))%0A%09%09%09.andExpect(jsonPath(%22$.code%22).value(%22200%22))%0A%09%09%09.andReturn();%0A%09%7D%0A%09%0A
 %09@After%0A

Add selectRestaurant Test