<commit_before>package gov.healthit.chpl.dao.impl;

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.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
import org.springframework.transaction.annotation.Transactional;

import com.github.springtestdbunit.DbUnitTestExecutionListener;
import com.github.springtestdbunit.annotation.DatabaseSetup;

import gov.healthit.chpl.dao.CertifiedProductSearchResultDAO;
import gov.healthit.chpl.dao.EntityRetrievalException;
import gov.healthit.chpl.domain.SearchRequest;
import gov.healthit.chpl.dto.CertifiedProductDetailsDTO;
import junit.framework.TestCase;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { gov.healthit.chpl.CHPLTestConfig.class })
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class,
    DirtiesContextTestExecutionListener.class,
    TransactionalTestExecutionListener.class,
    DbUnitTestExecutionListener.class })
@DatabaseSetup("classpath:data/testData.xml")
public class CertifiedProductSearchResultDaoTest extends TestCase {

	@Autowired
	private CertifiedProductSearchResultDAO searchResultDAO;
	
	
	@Test
	@Transactional
	public void testCountSearchResults(){
		
		SearchRequest searchRequest = new SearchRequest();
		searchRequest.setVendor("Test");
		searchRequest.setVisibleOnCHPL("YES");
		Long countProducts = searchResultDAO.countMultiFilterSearchResults(searchRequest);
		assertEquals(2, countProducts.intValue());
		
		searchRequest.setVersion("1.0.0");
		Long countProductsVersionSpecific = searchResultDAO.countMultiFilterSearchResults(searchRequest);
		assertEquals(1, countProductsVersionSpecific.intValue());
	}
	
	@Test
	@Transactional
	public void testSearchVendor(){
		
		SearchRequest searchRequest = new SearchRequest();
		searchRequest.setVendor("Test Vendor 1");
		List<CertifiedProductDetailsDTO> products = searchResultDAO.search(searchRequest);
		assertEquals(2, products.size());
		
		for (CertifiedProductDetailsDTO dto : products ){
			assertTrue(dto.getVendorName().startsWith("Test Vendor 1"));
		}
	}
	
	@Test
	@Transactional
	public void testSearchProduct(){
		
		SearchRequest searchRequest = new SearchRequest();
		
		searchRequest.setProduct("Test Product 1");
		List<CertifiedProductDetailsDTO> products = searchResultDAO.search(searchRequest);
		assertEquals(2, products.size());
		
		for (CertifiedProductDetailsDTO dto : products ){
			assertTrue(dto.getProductName().startsWith("Test Product 1"));
		}
		
	}
	
	@Test
	@Transactional
	public void testSearchVersion(){
		
		SearchRequest searchRequest = new SearchRequest();
		searchRequest.setVersion("1.0.1");
		List<CertifiedProductDetailsDTO> products = searchResultDAO.search(searchRequest);
		assertEquals(1, products.size());
		
		for (CertifiedProductDetailsDTO dto : products ){
			assertTrue(dto.getProductVersion().startsWith("1.0.1"));
		}
		
	}
	
	@Test
	@Transactional
	public void testSearchCertificationEdition(){
		
		SearchRequest searchRequest = new SearchRequest();
		searchRequest.setCertificationEdition("2014");
		List<CertifiedProductDetailsDTO> products = searchResultDAO.search(searchRequest);
		assertEquals(2, products.size());
		
		for (CertifiedProductDetailsDTO dto : products ){
			assertTrue(dto.getYear().startsWith("2014"));
		}
	}
	
	@Test
	@Transactional
	public void testSearchCertificationBody(){
		
		SearchRequest searchRequest = new SearchRequest();
		searchRequest.setCertificationBody("InfoGard");
		searchRequest.setVisibleOnCHPL("BOTH");
		List<CertifiedProductDetailsDTO> products = searchResultDAO.search(searchRequest);
		assertEquals(3, products.size());
		
		for (CertifiedProductDetailsDTO dto : products ){
			assertTrue(dto.getCertificationBodyName().startsWith("InfoGard"));
		}
		
	}
	
	
	@Test
	@Transactional
	public void testSearchProductClassificationType(){
		
		SearchRequest searchRequest = new SearchRequest();
		searchRequest.setProductClassification("Complete EHR");
		List<CertifiedProductDetailsDTO> products = searchResultDAO.search(searchRequest);
		assertEquals(1, products.size());
		
		for (CertifiedProductDetailsDTO dto : products ){
			assertTrue(dto.getProductClassificationName().startsWith("Complete EHR"));
		}
		
	}
	
	@Test
	@Transactional
	public void testSearchPracticeType(){
		
		SearchRequest searchRequest = new SearchRequest();
		searchRequest.setPracticeType("Ambulatory");
		searchRequest.setVisibleOnCHPL("BOTH");
		List<CertifiedProductDetailsDTO> products = searchResultDAO.search(searchRequest);
		assertEquals(3, products.size());
		
		for (CertifiedProductDetailsDTO dto : products ){
			assertTrue(dto.getPracticeTypeName().startsWith("Ambulatory"));
		}
		
	}
	
	
	@Test
	@Transactional
	public void testSearchVisibleOnCHPL(){
		
		SearchRequest searchRequest = new SearchRequest();
		searchRequest.setVisibleOnCHPL("YES");
		List<CertifiedProductDetailsDTO> products = searchResultDAO.search(searchRequest);
		assertEquals(2, products.size());
		
		for (CertifiedProductDetailsDTO dto : products ){
			assertTrue(dto.getVisibleOnChpl());
		}
		
	}
	
	
	@Test
	@Transactional
	public void testSearchHasCAP(){
		
		SearchRequest searchRequest = new SearchRequest();
		searchRequest.setHasCAP("YES");
		List<CertifiedProductDetailsDTO> products = searchResultDAO.search(searchRequest);
		assertEquals(1, products.size());
		
		for (CertifiedProductDetailsDTO dto : products ){
			assertTrue(dto.getCountCorrectiveActionPlans() > 0);
		}
		
	}
	
	
	
	@Test
	@Transactional
	public void testSearch(){
		
		SearchRequest searchRequest = new SearchRequest();
		
		searchRequest.setSearchTerm("Test");
		searchRequest.setVendor("Test Vendor");<commit_msg>(OCD-319) Work on has-CAP search.<commit_after>package gov.healthit.chpl.dao.impl;

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.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
import org.springframework.transaction.annotation.Transactional;

import com.github.springtestdbunit.DbUnitTestExecutionListener;
import com.github.springtestdbunit.annotation.DatabaseSetup;

import gov.healthit.chpl.dao.CertifiedProductSearchResultDAO;
import gov.healthit.chpl.dao.EntityRetrievalException;
import gov.healthit.chpl.domain.SearchRequest;
import gov.healthit.chpl.dto.CertifiedProductDetailsDTO;
import junit.framework.TestCase;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { gov.healthit.chpl.CHPLTestConfig.class })
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class,
    DirtiesContextTestExecutionListener.class,
    TransactionalTestExecutionListener.class,
    DbUnitTestExecutionListener.class })
@DatabaseSetup("classpath:data/testData.xml")
public class CertifiedProductSearchResultDaoTest extends TestCase {

	@Autowired
	private CertifiedProductSearchResultDAO searchResultDAO;
	
	
	@Test
	@Transactional
	public void testCountSearchResults(){
		
		SearchRequest searchRequest = new SearchRequest();
		searchRequest.setVendor("Test");
		searchRequest.setVisibleOnCHPL("YES");
		Long countProducts = searchResultDAO.countMultiFilterSearchResults(searchRequest);
		assertEquals(2, countProducts.intValue());
		
		searchRequest.setVersion("1.0.0");
		Long countProductsVersionSpecific = searchResultDAO.countMultiFilterSearchResults(searchRequest);
		assertEquals(1, countProductsVersionSpecific.intValue());
	}
	
	@Test
	@Transactional
	public void testSearchVendor(){
		
		SearchRequest searchRequest = new SearchRequest();
		searchRequest.setVendor("Test Vendor 1");
		List<CertifiedProductDetailsDTO> products = searchResultDAO.search(searchRequest);
		assertEquals(2, products.size());
		
		for (CertifiedProductDetailsDTO dto : products ){
			assertTrue(dto.getVendorName().startsWith("Test Vendor 1"));
		}
	}
	
	@Test
	@Transactional
	public void testSearchProduct(){
		
		SearchRequest searchRequest = new SearchRequest();
		
		searchRequest.setProduct("Test Product 1");
		List<CertifiedProductDetailsDTO> products = searchResultDAO.search(searchRequest);
		assertEquals(2, products.size());
		
		for (CertifiedProductDetailsDTO dto : products ){
			assertTrue(dto.getProductName().startsWith("Test Product 1"));
		}
		
	}
	
	@Test
	@Transactional
	public void testSearchVersion(){
		
		SearchRequest searchRequest = new SearchRequest();
		searchRequest.setVersion("1.0.1");
		List<CertifiedProductDetailsDTO> products = searchResultDAO.search(searchRequest);
		assertEquals(1, products.size());
		
		for (CertifiedProductDetailsDTO dto : products ){
			assertTrue(dto.getProductVersion().startsWith("1.0.1"));
		}
		
	}
	
	@Test
	@Transactional
	public void testSearchCertificationEdition(){
		
		SearchRequest searchRequest = new SearchRequest();
		searchRequest.setCertificationEdition("2014");
		List<CertifiedProductDetailsDTO> products = searchResultDAO.search(searchRequest);
		assertEquals(2, products.size());
		
		for (CertifiedProductDetailsDTO dto : products ){
			assertTrue(dto.getYear().startsWith("2014"));
		}
	}
	
	@Test
	@Transactional
	public void testSearchCertificationBody(){
		
		SearchRequest searchRequest = new SearchRequest();
		searchRequest.setCertificationBody("InfoGard");
		searchRequest.setVisibleOnCHPL("BOTH");
		List<CertifiedProductDetailsDTO> products = searchResultDAO.search(searchRequest);
		assertEquals(3, products.size());
		
		for (CertifiedProductDetailsDTO dto : products ){
			assertTrue(dto.getCertificationBodyName().startsWith("InfoGard"));
		}
		
	}
	
	@Test
	@Transactional
	public void testSearchProductClassificationType(){
		
		SearchRequest searchRequest = new SearchRequest();
		searchRequest.setProductClassification("Complete EHR");
		List<CertifiedProductDetailsDTO> products = searchResultDAO.search(searchRequest);
		assertEquals(1, products.size());
		
		for (CertifiedProductDetailsDTO dto : products ){
			assertTrue(dto.getProductClassificationName().startsWith("Complete EHR"));
		}
		
	}
	
	@Test
	@Transactional
	public void testSearchPracticeType(){
		
		SearchRequest searchRequest = new SearchRequest();
		searchRequest.setPracticeType("Ambulatory");
		searchRequest.setVisibleOnCHPL("BOTH");
		List<CertifiedProductDetailsDTO> products = searchResultDAO.search(searchRequest);
		assertEquals(3, products.size());
		
		for (CertifiedProductDetailsDTO dto : products ){
			assertTrue(dto.getPracticeTypeName().startsWith("Ambulatory"));
		}
		
	}
	
	@Test
	@Transactional
	public void testSearchVisibleOnCHPL(){
		
		SearchRequest searchRequest = new SearchRequest();
		searchRequest.setVisibleOnCHPL("YES");
		List<CertifiedProductDetailsDTO> products = searchResultDAO.search(searchRequest);
		assertEquals(2, products.size());
		
		for (CertifiedProductDetailsDTO dto : products ){
			assertTrue(dto.getVisibleOnChpl());
		}
		
	}
	
	@Test
	@Transactional
	public void testSearchHasCAP(){
		
		SearchRequest searchRequest = new SearchRequest();
		searchRequest.setHasCAP("YES");
		List<CertifiedProductDetailsDTO> products = searchResultDAO.search(searchRequest);
		assertEquals(1, products.size());
		
		for (CertifiedProductDetailsDTO dto : products ){
			assertTrue(dto.getCountCorrectiveActionPlans() > 0);
		}
		
	}
	
	
	
	@Test
	@Transactional
	public void testSearch(){
		
		SearchRequest searchRequest = new SearchRequest();
		
		searchRequest.setSearchTerm("Test");
		searchRequest.setVendor("Test Vendor");
{'fraction_non_alphanumeric': 0.10238713868139006, 'fraction_numerical': 0.006089639493341994, 'mean_word_length': 6.331547619047619, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1225141', 'n_tokens_mistral': 3831, 'n_tokens_neox': 3459, 'n_words': 569}