package com.jasamedika.medifirst2000.dao.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.List;

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.dao.GenericViewDao;
import com.jasamedika.medifirst2000.dao.PapSirkulasiDao;
import com.jasamedika.medifirst2000.entities.GenericView;
import com.jasamedika.medifirst2000.entities.PapSirkulasi;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath*:com/jasamedika/**/applicationContext.xml")
public class PapSirkulasiDaoTest {

	@Autowired
	private GenericViewDao genericViewDao;
	@Autowired
	private PapSirkulasiDao papSirkulasiDao;
	/*
	@Test
	@Transactional
	public void testGenericDaoSelect() {
		GenericView intensitasNadi = populateGenericView("Intensitas Nadi");
		GenericView akral = populateGenericView("Akral");
		GenericView crt = populateGenericView("CRT");
		assertNotNull(intensitasNadi);
		assertNotNull(akral);
		assertNotNull(crt);
    	assertEquals("1", String.valueOf(intensitasNadi.getKdGenericView()));
    	assertEquals("1", String.valueOf(akral.getKdGenericView()));
    	assertEquals("1", String.valueOf(crt.getKdGenericView()));
	}

	@Test
	@Transactional
	public void testPAPSirkulasiDaoSave() {
		PapSirkulasi model = populateModel();
		PapSirkulasi resultModel=papSirkulasiDao.save(model);
		assertNotNull(resultModel);
    	assertNotNull(resultModel.getIntensitasNadi());
    	assertNotNull(resultModel.getAkral());
    	assertNotNull(resultModel.getCrt());
    	assertEquals("1", String.valueOf(resultModel.getIntensitasNadi().getKdGenericView()));
    	assertEquals("1", String.valueOf(resultModel.getAkral().getKdGenericView()));
    	assertEquals("1", String.valueOf(resultModel.getCrt().getKdGenericView()));
    	assertEquals(true,resultModel.getIsSianosis());
    	assertEquals(true,resultModel.getIsPucat());
    	assertEquals(true,resultModel.getIsIramaNadi());
    	assertEquals(true,resultModel.getIsEdema());
    	assertEquals(true,resultModel.getIsClubbingFinger());
    	PapSirkulasi resultModel2=papSirkulasiDao.findOne(resultModel.getNoRec());
		assertNotNull(resultModel2);
    	assertNotNull(resultModel2.getIntensitasNadi());
    	assertNotNull(resultModel2.getAkral());
    	assertNotNull(resultModel2.getCrt());
    	assertEquals("1", String.valueOf(resultModel2.getIntensitasNadi().getKdGenericView()));
    	assertEquals("1", String.valueOf(resultModel2.getAkral().getKdGenericView()));
    	assertEquals("1", String.valueOf(resultModel2.getCrt().getKdGenericView()));
    	assertEquals(true,resultModel.getIsSianosis());
    	assertEquals(true,resultModel.getIsPucat());
    	assertEquals(true,resultModel.getIsIramaNadi());
    	assertEquals(true,resultModel.getIsEdema());
    	assertEquals(true,resultModel.getIsClubbingFinger());
	}

	private PapSirkulasi populateModel() {
		PapSirkulasi model=new PapSirkulasi();
		GenericView intensitasNadi = populateGenericView("Intensitas Nadi");
		GenericView akral = populateGenericView("Akral");
		GenericView crt = populateGenericView("CRT");
		model.setIntensitasNadi(intensitasNadi);
		model.setAkral(akral);
		model.setCrt(crt);
		model.setIsSianosis(true);
		model.setIsPucat(true);
		model.setIsIramaNadi(true);
		model.setIsEdema(true);
		model.setIsClubbingFinger(true);
		return model;
	}

	private GenericView populateGenericView(String previx) {
		GenericView genericView=new GenericView();
		List<GenericView> list=genericViewDao.findGenericViewByPrevix(previx);
		for (GenericView gv:list) {
			if(gv.getKdGenericView()==1){
				genericView=gv;
			}
		}
		return genericView;
	}
	
	@Test
	@Transactional
	public void testPAPSirkulasiDaoFindAll() {
		PapSirkulasi model1 = populateModel();
		PapSirkulasi resultModel1=papSirkulasiDao.save(model1);
		PapSirkulasi model2 = populateModel();
		PapSirkulasi resultModel2=papSirkulasiDao.save(model2);
		assertNotNull(resultModel1);
		assertNotNull(resultModel2);
		List<PapSirkulasi> results = (List<PapSirkulasi>) papSirkulasiDao.findAll();
		assertTrue(results.size() > 0);
		assertNotNull(results);
		assertTrue(results.size() == 2);
	}
	*/
}
