1 package eu
.etaxonomy
.cdm
.persistence
.dao
.hibernate
;
2 import static org
.junit
.Assert
.assertEquals
;
3 import static org
.junit
.Assert
.assertNotNull
;
4 import static org
.junit
.Assert
.assertTrue
;
8 import org
.apache
.commons
.logging
.Log
;
9 import org
.apache
.commons
.logging
.LogFactory
;
10 import org
.hibernate
.Hibernate
;
11 import org
.junit
.Test
;
12 import org
.unitils
.dbunit
.annotation
.DataSet
;
13 import org
.unitils
.spring
.annotation
.SpringApplicationContext
;
14 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
16 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
17 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
18 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
19 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IDescriptionElementDao
;
20 import eu
.etaxonomy
.cdm
.persistence
.dao
.taxon
.ITaxonDao
;
21 import eu
.etaxonomy
.cdm
.test
.integration
.CdmIntegrationTest
;
24 public class FreeTextSearchIntegration
extends CdmIntegrationTest
{
26 private static Log log
= LogFactory
.getLog(FreeTextSearchIntegration
.class);
32 IDescriptionElementDao descriptionElementDao
;
35 // TaxonAlternativeSpellingSuggestionParser alternativeSpellingSuggestionParser;
38 // public void test() {
39 // taxonDao.rebuildIndex();
40 // taxonDao.optimizeIndex();
42 // descriptionElementDao.rebuildIndex();
43 // descriptionElementDao.optimizeIndex();
47 // public void test1() {
48 // alternativeSpellingSuggestionParser.refresh();
52 public void testSearchTextData() {
53 List
<TextData
> results
= descriptionElementDao
.searchTextData("Lorem",null,null);
55 assertNotNull("searchTextData should return a List",results
);
56 assertEquals("there should be 4 TextData entities in the list",4,results
.size());
59 assertTrue("DescriptionElementBase.feature should be initialized",Hibernate
.isInitialized(results
.get(0).getFeature()));
60 assertTrue("DescriptionElementBase.inDescription should be initialized",Hibernate
.isInitialized(results
.get(0).getInDescription()));
61 assertTrue("inDescription should be an instance of TaxonDescription",results
.get(0).getInDescription() instanceof TaxonDescription
);
62 TaxonDescription taxonDescription
= (TaxonDescription
)results
.get(0).getInDescription();
63 assertTrue("TaxonDescription.taxon should be initialized",Hibernate
.isInitialized(taxonDescription
.getTaxon()));
64 assertEquals("The results should be sorted alphabetically","Aglaodorum Schott sec. cate-araceae.org",taxonDescription
.getTaxon().getTitleCache());
68 public void testCountTextData() {
69 int matches
= descriptionElementDao
.countTextData("Lorem");
70 assertEquals("countTextData should return 4",4,matches
);
74 public void testSearchWord() {
75 List
<TaxonBase
> results
= taxonDao
.searchTaxa("Arum",null, null, null);
76 assertEquals("searchTaxa should return 43 results",43,results
.size());
77 assertTrue("TaxonBase.name should be initialized",Hibernate
.isInitialized(results
.get(0).getName()));
81 public void testSearchCount() {
82 int numberOfResults
= taxonDao
.countTaxa("Arum",null);
83 assertEquals("countTaxa should return 43",43,numberOfResults
);
88 public void testSearchPaged() {
89 List
<TaxonBase
> page1
= taxonDao
.searchTaxa("Arum",null, 30, 0);
90 List
<TaxonBase
> page2
= taxonDao
.searchTaxa("Arum",null, 30, 1);
92 assertEquals("page 1 should contain 30 taxa",30,page1
.size());
93 assertEquals("page 1 should be sorted alphabetically","Arum L.",page1
.get(0).getName().getTitleCache());
94 assertEquals("page 1 should be sorted alphabetically","Arum lucanum Cavara & Grande",page1
.get(29).getName().getTitleCache());
95 assertEquals("page 2 should contain 13 taxa",13,page2
.size());
96 assertEquals("page 2 should be sorted alphabetically","Arum maculatum L.",page2
.get(0).getName().getTitleCache());
97 assertEquals("page 2 should be sorted alphabetically","Arum x sooi TerpĆ³",page2
.get(12).getName().getTitleCache());
101 public void testSearchPhrase() {
102 List
<TaxonBase
> results
= taxonDao
.searchTaxa("\"Arum italicum\"",null, null, null);
103 assertEquals("searchTaxa should return 5 taxa",5,results
.size());
107 public void testSearchWildcard() {
108 List
<TaxonBase
> results
= taxonDao
.searchTaxa("Aroph*", null, null, null);
109 assertEquals("searchTaxa should return 6 taxa",7,results
.size());
113 public void testSuggestSingleTerm() {
114 String suggestion
= taxonDao
.suggestQuery("Aram");
115 assertNotNull("suggestQuery should return a String",suggestion
);
116 assertEquals("The spelling suggestion for \"Aram\" should be \"arum\"","arum",suggestion
);
120 public void testSuggestSingleTermInCompositeQuery() {
121 String suggestion
= taxonDao
.suggestQuery("Aram italicum");
122 assertNotNull("suggestQuery should return a String",suggestion
);
123 assertEquals("The spelling suggestion for \"Aram italicum\" should be \"arum italicum\"","arum italicum",suggestion
);
127 public void testSuggestMultipleTermsInCompositeQuery() {
128 String suggestion
= taxonDao
.suggestQuery("Aram italocum");
129 assertNotNull("suggestQuery should return a String",suggestion
);
130 assertEquals("The spelling suggestion for \"Aram italocum\" should be \"arum italicum\"","arum italicum",suggestion
);
134 public void testSuggestMultipleTermsInCompositeQueryWithAnd() {
135 String suggestion
= taxonDao
.suggestQuery("Aram AND italocum");
136 assertNotNull("suggestQuery should return a String",suggestion
);
137 assertEquals("The spelling suggestion for \"Aram AND italocum\" should be \"+arum +italicum\"","+arum +italicum",suggestion
);