package com.jasamedika.medifirst2000.service.test;

import static org.junit.Assert.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import com.jasamedika.medifirst2000.converter.PasienConverter;
import com.jasamedika.medifirst2000.dao.PasienDao;
import com.jasamedika.medifirst2000.entities.PapTandaVital;
import com.jasamedika.medifirst2000.entities.Pasien;
import com.jasamedika.medifirst2000.service.PapTandaVitalService;
import com.jasamedika.medifirst2000.util.DateUtil;
import com.jasamedika.medifirst2000.vo.PapTandaVitalVO;
import com.jasamedika.medifirst2000.vo.PasienVO;
import com.jasamedika.medifirst2000.vo.StatusYaTidakVO;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath*:com/jasamedika/**/applicationContext.xml")
public class PapTandaVitalServiceImplTest {
	
	@Autowired
	private PapTandaVitalService papTandaVitalService;
	
	@Autowired
	private PasienDao pasienDao;
	
	@Autowired
	private PasienConverter pasienConverter;
	
	@Test
	@Transactional
	public void testAddTandaVital() {
		/*PapTandaVitalVO vo = populateModel();
		Map<String,Object> result = papTandaVitalService.addTandaVital(vo);
		assertNotNull(result);
		
		PapTandaVital papTandaVital = (PapTandaVital) result.get("papTandaVital");
		//assertEquals("Reynaldi Ramadhani Pratama", papTandaVital.getPasien().getNamaPasien());
		assertEquals("Tidak", papTandaVital.getKesadaran().getName());
		assertEquals(generateDate(), papTandaVital.getTglInput());*/
	}

	@Test
	@Transactional
	public void testUpdateTandaVital() {
		/*PapTandaVitalVO vo = populateModel();
		Map<String,Object> result = papTandaVitalService.addTandaVital(vo);
		assertNotNull(result);
		
		PapTandaVitalVO voUpdate = populateModel();
		StatusYaTidakVO statusYaTidakVO = new StatusYaTidakVO();
		statusYaTidakVO.setId(2);
		statusYaTidakVO.setName("Ya");
		voUpdate.setKesadaran(statusYaTidakVO);
		Map<String,Object> resultUpdate = papTandaVitalService.addTandaVital(voUpdate);
		assertNotNull(resultUpdate);
		PapTandaVital papTandaVital = (PapTandaVital) resultUpdate.get("papTandaVital");
		assertEquals("Ya",papTandaVital.getKesadaran().getName());*/
	}

	@Test
	@Transactional
	public void testFindByNoCmAndTglInput() {
//		Map<String,Object> result = papTandaVitalService.findByNoCmAndTglInput("000001", DateUtil.toDate("2013-06-07 12:10:56"));
//		Boolean dataFound=new Boolean((boolean) result.get("dataFound"));
//		assertTrue(dataFound);
	}

	@Test
	@Transactional
	public void testFindRegistrasiPelayananPasienByNoCmAndTglRegistrasi() {
//		Map<String,Object> result = papTandaVitalService.findRegistrasiPelayananPasienByNoCmAndTglRegistrasi("000000000000005",(short) 0, DateUtil.toDate("2016-07-17 04:26:00"));
//		Boolean dataFound=new Boolean((boolean) result.get("dataFound"));
//		assertTrue(dataFound);
	}

	@Test
	@Transactional
	public void testFindPasienByNoCm() {
//		Map<String,Object> result = papTandaVitalService.findPasienByNoCm("000000000000005");
//		Boolean dataFound=new Boolean((boolean) result.get("dataFound"));
//		assertTrue(dataFound);
	}
	
	
	@Test
	@Transactional
	public void testPopulateModel(){
//		/*Cek Pasien Dao*/
//		Pasien pasien = pasienDao.findOne(544);
//		assertNotNull(pasien);
//		assertEquals("Reynaldi Ramadhani Pratama",pasien.getNamaPasien());
//		
//		/*Cek Pasien Converter*/
//		PasienVO pasienVO = pasienConverter.transferModelToVO(pasien,new PasienVO());
//		assertNotNull(pasienVO);
//		assertEquals("Reynaldi Ramadhani Pratama",pasienVO.getNamaPasien());
//		
//		/*Cek VO*/
//		PapTandaVitalVO vo = populateModel();
//		//assertEquals("Reynaldi Ramadhani Pratama", vo.getPasien().getNamaPasien());
//		assertEquals("Tidak", vo.getKesadaran().getName());
//		assertEquals(generateDate(), vo.getTglInput());
	}
	
	private PapTandaVitalVO populateModel(){
		PapTandaVitalVO vo = new PapTandaVitalVO();
//		Pasien pasien = pasienDao.findOne(544);
//		PasienVO pasienVO = pasienConverter.transferModelToVO(pasien,new PasienVO());
//		StatusYaTidakVO statusYaTidakVO = new StatusYaTidakVO();
//		statusYaTidakVO.setId(1);
//		statusYaTidakVO.setName("Tidak");
//		
//		//vo.setPasien(pasienVO);
//		vo.setKesadaran(statusYaTidakVO);
//		vo.setTglInput(generateDate());
		return vo;
		
	}
	
	private Date generateDate(){
		SimpleDateFormat formatter = new SimpleDateFormat("EEEE, MMM dd, yyyy HH:mm:ss a");
		String dateInString = "Friday, Jun 7, 2013 12:10:56 PM";
		
		Date date = null;
		try {
			date = formatter.parse(dateInString);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}
	
}
