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.PapAlergi;
import com.jasamedika.medifirst2000.entities.Pasien;
import com.jasamedika.medifirst2000.service.PapAlergiService;
import com.jasamedika.medifirst2000.service.PapSkriningNyeriService;
import com.jasamedika.medifirst2000.util.DateUtil;
import com.jasamedika.medifirst2000.vo.AlergiVO;
import com.jasamedika.medifirst2000.vo.PapAlergiVO;
import com.jasamedika.medifirst2000.vo.PasienVO;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath*:com/jasamedika/**/applicationContext.xml")
public class PapAlergiServiceImplTest {/*
	
	@Autowired
	private PapAlergiService papAlergiService;
	
	@Autowired
	private PasienDao pasienDao;
	
	@Autowired
	private PasienConverter pasienConverter;
	
	@Test
	@Transactional
	public void testAddAlergi() {
		PapAlergiVO vo = populateModel();
		Map<String,Object> result = papAlergiService.addAlergi(vo);
		assertNotNull(result);
		
		PapAlergi papAlergi = (PapAlergi) result.get("papAlergi");
		assertEquals("ALEGI SAMPO",papAlergi.getAlergi().getNamaAlergi());
		assertEquals("Keterangan",papAlergi.getKeteranganData());
		assertEquals("Reaksi",papAlergi.getReaksi());
		assertEquals(generateDate(),papAlergi.getTglInput());
	}

	@Test
	@Transactional
	public void testUpdateAlergi() {
		PapAlergiVO vo = populateModel();
		Map<String,Object> result = papAlergiService.addAlergi(vo);
		assertNotNull(result);
		
		PapAlergiVO voUpdate = populateModel();
		voUpdate.setKeteranganData("Keterangan Update");
		voUpdate.setReaksi("Reaksi Update");
		Map<String,Object> resultUpdate = papAlergiService.addAlergi(voUpdate);
		assertNotNull(resultUpdate);
		PapAlergi papAlergi = (PapAlergi) resultUpdate.get("papAlergi");
		assertEquals("Keterangan Update",papAlergi.getKeteranganData());
		assertEquals("Reaksi Update",papAlergi.getReaksi());
		
	}

	@Test
	@Transactional
	public void testFindByNoCmAndTglInput() {
		Map<String,Object> result = papAlergiService.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 = papAlergiService.findRegistrasiPelayananPasienByNoCmAndTglRegistrasi("000001",(short) 0, DateUtil.toDate("2013-06-07 12:10:56"));
		Boolean dataFound=new Boolean((boolean) result.get("dataFound"));
		assertTrue(dataFound);
	}

	@Test
	@Transactional
	public void testFindPasienByNoCm() {
		Map<String,Object> result = papAlergiService.findPasienByNoCm("000001");
		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());
		
		PapAlergiVO vo = populateModel();
		assertEquals("ALEGI SAMPO",vo.getAlergi().getNamaAlergi());
		assertEquals("Keterangan",vo.getKeteranganData());
		assertEquals("Reaksi",vo.getReaksi());
	}
	
	private PapAlergiVO populateModel(){
		PapAlergiVO vo = new PapAlergiVO();
		Pasien pasien = pasienDao.findOne(544);
		PasienVO pasienVO = pasienConverter.transferModelToVO(pasien,new PasienVO());
		AlergiVO alergiVO = new AlergiVO();
		alergiVO.setId(1);
		alergiVO.setNamaAlergi("ALEGI SAMPO");
		vo.setPasien(pasienVO);
		vo.setAlergi(alergiVO);
		vo.setTglInput(generateDate());
		vo.setKeteranganData("Keterangan");
		vo.setReaksi("Reaksi");
		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;
	}
*/}
