package com.pm.server.controller;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.util.Arrays;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import com.pm.server.ControllerTestTemplate;
import com.pm.server.datatype.Coordinate;
import com.pm.server.datatype.CoordinateImpl;
import com.pm.server.repository.PacmanRepository;
import com.pm.server.utils.JsonUtils;

public class PacmanControllerTest extends ControllerTestTemplate {

	@Autowired
	private PacmanRepository pacmanRepository;

	private static final List<Coordinate> randomCoordinateList = Arrays.asList(
			new CoordinateImpl(12941.49901, 39231.05893),
			new CoordinateImpl(03912.08312, 11293.34921)
	);

	private static final String BASE_MAPPING = "/pacman";

	private static final Logger log =
			LogManager.getLogger(GhostControllerTest.class.getName());

	@Autowired
	private WebApplicationContext webApplicationContext;

	private MockMvc mockMvc;

	@Before
	public void setUp() {

		mockMvc = MockMvcBuilders
				.webAppContextSetup(this.webApplicationContext)
				.build();

	}

	@After
	public void cleanUp() {

		pacmanRepository.clearPlayers();
		assert(pacmanRepository.numOfPlayers() == 0);

	}

	@Test
	public void unitTest_createPacman() throws Exception {

		// Given
		final String path = pathForCreatePacman();

		Coordinate location = randomCoordinateList.get(0);
		final String body = JsonUtils.objectToJson(location);

		// When
		mockMvc
				.perform((post(path))
						.header("Content-Type", "application/json")
						.content(body)
				)

		// Then
				.andExpect(status().isOk());

	}

	private static String pathForCreatePacman() {
		return BASE_MAPPING;
	}

}
@@ -28,16 +28,230 @@
 oller;%0A%0A
+import static org.junit.Assert.fail;%0Aimport static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;%0Aimport static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;%0A
 import s
@@ -2306,76 +2306,1131 @@
 %7D%0A%0A%09
-private static String pathForCreatePacman() %7B%0A%09%09return BASE_MAPPING;
+@Test%0A%09public void unitTest_deletePacman() throws Exception %7B%0A%0A%09%09// Given%0A%09%09Coordinate location = randomCoordinateList.get(0);%0A%09%09createPacman_failUponException(location);%0A%0A%09%09final String pathForDeletePacman = pathForDeletePacman();%0A%09%09final String pathForGetPacmanState = pathForGetPacmanState();%0A%0A%09%09// When%0A%09%09mockMvc%0A%09%09%09%09.perform(delete(pathForDeletePacman))%0A%0A%09%09// Then%0A%09%09%09%09.andExpect(status().isOk());%0A%0A%09%09mockMvc%0A%09%09%09%09.perform(get(pathForGetPacmanState))%0A%09%09%09%09.andExpect(status().isNotFound());%0A%0A%09%7D%0A%0A%09private static String pathForCreatePacman() %7B%0A%09%09return BASE_MAPPING;%0A%09%7D%0A%0A%09private static String pathForDeletePacman() %7B%0A%09%09return BASE_MAPPING;%0A%09%7D%0A%0A%09private static String pathForGetPacmanState() %7B%0A%09%09return BASE_MAPPING + %22/state%22;%0A%09%7D%0A%0A%09private void createPacman_failUponException(Coordinate location) %7B%0A%0A%09%09String path = pathForCreatePacman();%0A%09%09String body = JsonUtils.objectToJson(location);%0A%0A%09%09try %7B%0A%09%09%09mockMvc%0A%09%09%09%09%09.perform(post(path)%0A%09%09%09%09%09%09%09.content(body)%0A%09%09%09%09%09%09%09.header(%22Content-Type%22, %22application/json%22)%0A%09%09%09%09%09)%0A%09%09%09%09%09.andExpect(status().isOk());%0A%09%09%7D%0A%09%09catch(Exception e) %7B%0A%09%09%09log.error(e.getMessage());%0A%09%09%09fail();%0A%09%09%7D%0A
 %0A%09%7D%0A

Write smoke test for delete Pacman endpoint