package io.crowdcode.flaschenlager.customer.controller;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

import io.crowdcode.flaschenlager.customer.fixture.CustomerFixture;
import io.crowdcode.flaschenlager.customer.model.Customer;
import io.crowdcode.flaschenlager.customer.repository.CustomerRepository;
import io.crowdcode.flaschenlager.customer.repository.EmployeeRepository;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringRunner.class)
@WebMvcTest(EmployeeController.class)
public class EmployeeControllerTest {

	@Autowired
	private MockMvc mvc;

	@MockBean
	private CustomerRepository customerRepository;

	@MockBean
	private EmployeeRepository employeeRepository;

	@Test
	public void testDeleteEmployeeReference() throws Exception {
		mvc.perform(MockMvcRequestBuilders.delete("/customers/{customerId}/employee/{userId}", 1l,2l)
				.contentType(MediaType.APPLICATION_JSON)
				.accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk());

		verify(employeeRepository, times(1) ).deleteByUserId(2l);
	}

	@Test
	public void testAddAsEmployeeReference() throws Exception {
		when(customerRepository.getOne(any())).thenReturn(CustomerFixture.buildDefaultCustomer());
		mvc.perform(MockMvcRequestBuilders.put("/customers/{customerId}/employee/{userId}", 1l,5l)
				.contentType(MediaType.APPLICATION_JSON)
				.accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk());

		verify(customerRepository, times(1) ).getOne(1l);
		verify(customerRepository, times(1) ).save(any(Customer.class));



	}
}
@@ -50,16 +50,291 @@
 oller;%0A%0A
+import io.crowdcode.flaschenlager.customer.fixture.CustomerFixture;%0Aimport io.crowdcode.flaschenlager.customer.model.Customer;%0Aimport io.crowdcode.flaschenlager.customer.repository.CustomerRepository;%0Aimport io.crowdcode.flaschenlager.customer.repository.EmployeeRepository;%0A
 import o
@@ -824,438 +824,76 @@
 ort 
-io.crowdcode.flaschenlager.customer.fixture.CustomerFixture;%0Aimport io.crowdcode.flaschenlager.customer.model.Customer;%0Aimport io.crowdcode.flaschenlager.customer.repository.CustomerRepository;%0Aimport io.crowdcode.flaschenlager.customer.repository.EmployeeRepository;%0A%0Aimport static org.mockito.Matchers.any;%0Aimport static org.mockito.Mockito.times;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.when
+static org.mockito.Matchers.any;%0Aimport static org.mockito.Mockito.*
 ;%0Aim
@@ -1085,17 +1085,20 @@
 Test %7B%0A%0A
-%09
+    
 @Autowir
@@ -1100,17 +1100,20 @@
 towired%0A
-%09
+    
 private 
@@ -1126,17 +1126,20 @@
 c mvc;%0A%0A
-%09
+    
 @MockBea
@@ -1132,33 +1132,36 @@
 %0A%0A    @MockBean%0A
-%09
+    
 private Customer
@@ -1192,17 +1192,20 @@
 itory;%0A%0A
-%09
+    
 @MockBea
@@ -1206,17 +1206,20 @@
 ockBean%0A
-%09
+    
 private 
@@ -1258,24 +1258,30 @@
 itory;%0A%0A
-%09
+    
 @Test%0A
-%09
+    
 public v
@@ -1333,18 +1333,24 @@
 ption %7B%0A
-%09%09
+        
 mvc.perf
@@ -1435,16 +1435,29 @@
  1l,
+ 
 2l)%0A
-%09%09%09%09
+                
 .con
@@ -1485,36 +1485,48 @@
 PLICATION_JSON)%0A
-%09%09%09%09
+                
 .accept(MediaTyp
@@ -1571,26 +1571,32 @@
 ).isOk());%0A%0A
-%09%09
+        
 verify(emplo
@@ -1618,17 +1618,16 @@
 times(1)
- 
 ).delete
@@ -1644,20 +1644,29 @@
 l);%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 @Test%0A
-%09
+    
 publ
@@ -1721,18 +1721,24 @@
 ption %7B%0A
-%09%09
+        
 when(cus
@@ -1820,18 +1820,24 @@
 mer());%0A
-%09%09
+        
 mvc.perf
@@ -1919,16 +1919,29 @@
  1l,
+ 
 5l)%0A
-%09%09%09%09
+                
 .con
@@ -1981,12 +1981,24 @@
 ON)%0A
-%09%09%09%09
+                
 .acc
@@ -2059,18 +2059,24 @@
 Ok());%0A%0A
-%09%09
+        
 verify(c
@@ -2102,17 +2102,16 @@
 times(1)
- 
 ).getOne
@@ -2120,10 +2120,16 @@
 l);%0A
-%09%09
+        
 veri
@@ -2159,17 +2159,16 @@
 times(1)
- 
 ).save(a
@@ -2192,11 +2192,11 @@
 ));%0A
-%0A%0A%0A%09
+    
 %7D%0A%7D

add test