package com.nisum.myteam.controller;

import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;

import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.nisum.myteam.controller.ResourceController;
import com.nisum.myteam.model.dao.Employee;
import com.nisum.myteam.model.dao.Resource;
import com.nisum.myteam.repository.EmployeeVisaRepo;
import com.nisum.myteam.service.IEmployeeService;
import com.nisum.myteam.service.IProjectService;
import com.nisum.myteam.service.impl.ResourceService;

public class ResourceControllerTest {

	@Mock
	IEmployeeService employeeService;
	
	@Mock
	IProjectService projectService;
	
	@Mock
	EmployeeVisaRepo employeeVisaRepo;
	
	@Mock
	ResourceService resourceService;
	
	 @InjectMocks
	 ResourceController resourceController;
	
	private MockMvc mockMvc;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        mockMvc = MockMvcBuilders.standaloneSetup(resourceController).build();
    }

    @Test
    public void testCreateResource() throws Exception {
//    	Resource employeeList = null;
//		when(resourceService.validateBillingStartEndDateAgainstProjectStartEndDate(null, null)).thenReturn(true);
//		when(resourceService.validateBillingStartDateAgainstDOJ(null)).thenReturn(true);
//		when(resourceService.isResourceAssignedToAnyProject(null)).thenReturn(false);
//		when(resourceService.validateAllocationAgainstPrevAllocation(null)).thenReturn(true);
//		when(resourceService.addResource(null, null)).thenReturn(employeeList);
//
//		mockMvc.perform(post("/resources").param("domainId", "ACC001"))
//				.andExpect(MockMvcResultMatchers.status().isOk());
//		
		
		Resource employeePersisted = new Resource();
		Resource employeeReq = new Resource();
		ObjectMapper mapper = new ObjectMapper();
		String jsonString = mapper.writeValueAsString(employeeReq);
//		when(resourceService.validateBillingStartEndDateAgainstProjectStartEndDate(null, null)).thenReturn(true);
//		when(resourceService.validateBillingStartDateAgainstDOJ(null)).thenReturn(true);
//		when(resourceService.isResourceAssignedToAnyProject(null)).thenReturn(false);
//		when(resourceService.validateAllocationAgainstPrevAllocation(null)).thenReturn(true);
		when(resourceService.addResource(null, null)).thenReturn(employeePersisted);
		mockMvc.perform(post("/resources").contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString))
				.andExpect(MockMvcResultMatchers.status().isOk());
    }
    
	
}
