View Javadoc

1   package org.cateproject.view.description;
2   
3   import java.util.ArrayList;
4   import java.util.HashMap;
5   import java.util.HashSet;
6   import java.util.Iterator;
7   import java.util.List;
8   import java.util.Map;
9   import java.util.Set;
10  import java.util.UUID;
11  
12  import org.cateproject.controller.description.FeatureNodeWithLevel;
13  import org.cateproject.controller.description.TextDataWithFeatureTree;
14  import org.cateproject.controller.speciespage.SpeciesPage;
15  import org.cateproject.view.CATEViewTest;
16  import org.junit.Test;
17  import org.springframework.web.servlet.ModelAndView;
18  
19  import eu.etaxonomy.cdm.api.service.pager.Pager;
20  import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
21  import eu.etaxonomy.cdm.model.common.Language;
22  import eu.etaxonomy.cdm.model.common.LanguageString;
23  import eu.etaxonomy.cdm.model.common.IdentifiableSource;
24  import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
25  import eu.etaxonomy.cdm.model.description.Distribution;
26  import eu.etaxonomy.cdm.model.description.Feature;
27  import eu.etaxonomy.cdm.model.description.FeatureNode;
28  import eu.etaxonomy.cdm.model.description.FeatureTree;
29  import eu.etaxonomy.cdm.model.description.TaxonDescription;
30  import eu.etaxonomy.cdm.model.description.TextData;
31  import eu.etaxonomy.cdm.model.location.NamedArea;
32  import eu.etaxonomy.cdm.model.name.NonViralName;
33  import eu.etaxonomy.cdm.model.taxon.Taxon;
34  
35  public class DescriptionViewsTest extends CATEViewTest {
36  	
37  	    @Test
38          public void testIndex() {
39  	    	ModelAndView modelAndView = new ModelAndView("description/index");
40  	    	modelAndView.addObject("taxon", dataSet.getTaxonBases().get(0));
41              TaxonDescription description = ((Taxon)dataSet.getTaxonBases().get(0)).getDescriptions().iterator().next();
42              modelAndView.addObject("object",description);
43              outputMock(modelAndView,"target/generated-sources/mock/description/index.html");
44  	    }
45          
46          @Test
47          public void testDescriptionPage() {
48                  ModelAndView modelAndView = new ModelAndView("description/elements");
49                  modelAndView.addObject("taxon", dataSet.getTaxonBases().get(0));
50                  TaxonDescription taxonDescription = ((Taxon)dataSet.getTaxonBases().get(0)).getDescriptions().iterator().next();
51                  FeatureTree featureTree = dataSet.getFeatureTrees().get(0);
52                
53                  modelAndView.addObject("pager",constructDescriptionElementsWithLevels(new ArrayList<DescriptionElementBase>(taxonDescription.getElements()),getFeatures(featureTree.getRoot(),new HashSet<Feature>()),featureTree));
54                  modelAndView.addObject("featureTree",dataSet.getFeatureTrees().get(0));
55                  Set<NamedArea> geoScopes = new HashSet<NamedArea>();
56                  geoScopes.add((NamedArea)dataSet.getTerms().get(15));
57                  modelAndView.addObject("geoScopes",geoScopes);
58                  modelAndView.addObject("object",taxonDescription);
59                  
60                  outputMock(modelAndView,"target/generated-sources/mock/description/elements.html");
61          } 
62          
63          @Test
64          public void testSourcesPage() {
65                  ModelAndView modelAndView = new ModelAndView("common/sources");
66                  modelAndView.addObject("taxon", dataSet.getTaxonBases().get(0));
67                  
68                  final List<IdentifiableSource> results = new ArrayList<IdentifiableSource>();
69                  for(int i = 0; i < 4; i++) {
70                  	    IdentifiableSource citation = new IdentifiableSource();
71                          citation.setCitation(dataSet.getReferences().get(i));
72                          results.add(citation);
73                  }
74                  
75                  Pager<IdentifiableSource> sources = new DefaultPagerImpl<IdentifiableSource>(0, 4, 30, results) {
76                          protected String getLabel(Integer i) {
77                                  return i.toString();
78                          }
79                  };
80                  
81                  
82                  modelAndView.addObject("pager",sources);
83                  modelAndView.addObject("object",((Taxon)dataSet.getTaxonBases().get(0)).getDescriptions().iterator().next());              
84                  
85                  outputMock(modelAndView,"target/generated-sources/mock/description/Sources.html");
86          }
87          
88          @Test
89          public void testCreateDescriptionElement() {
90          	ModelAndView modelAndView = new ModelAndView("descriptionElement/edit/create");
91          	TaxonDescription description = ((Taxon)dataSet.getTaxonBases().get(0)).getDescriptions().iterator().next();
92              modelAndView.addObject("inDescriptionObj",description);
93              List<Class> availableClasses = new ArrayList<Class>();
94              availableClasses.add(TextData.class);
95              availableClasses.add(Distribution.class);
96              modelAndView.addObject("availableClasses",availableClasses);
97              modelAndView.addObject("featureObj",description.getElements().iterator().next().getFeature());
98              outputMock(modelAndView,"target/generated-sources/mock/descriptionElement/Edit/Create.html");
99          }
100         
101         @Test
102         public void testEditDescriptionElement() {
103         	ModelAndView modelAndView = new ModelAndView("descriptionElement/edit/edit");
104         	TaxonDescription description = ((Taxon)dataSet.getTaxonBases().get(0)).getDescriptions().iterator().next();
105             modelAndView.addObject("inDescriptionObj",description);
106             
107             TextData textData = new TextData();
108             textData.getMultilanguageText().put(Language.DEFAULT(), LanguageString.NewInstance("I wandered lonely as a cloud That floats on high o'er vales and hills, When all at once I saw a crowd, A host, of golden daffodils, Beside the lake, beneath the trees Fluttering and dancing in the breeze.", Language.DEFAULT()));
109             textData.getMultilanguageText().put(Language.FRENCH(), LanguageString.NewInstance("Je suis all� me promener seul comme un nuage qui flotte en haut des collines et de vallons o'er, quand tout � coup, j'ai vu une foule, une foule de jonquilles dor�es, � c�t� du lac, sous les arbres flottant et dansant dans la brise.", Language.FRENCH()));           
110             textData.getMultilanguageText().put(Language.GERMAN(), LanguageString.NewInstance("Ich wanderte einsam wie eine Wolke Das schwimmt auf hohen o'er T�ler und H�gel, wenn alle auf einmal sah ich eine Menschenmenge, einen Host, der goldenen Narzissen, neben der See, unter den B�umen flatterten und Tanz in den Wind.", Language.GERMAN()));
111             textData.addMedia(dataSet.getMedia().get(0));
112             modelAndView.addObject("descriptionElement",textData);
113             modelAndView.addObject("featureObj",description.getElements().iterator().next().getFeature());
114             outputMock(modelAndView,"target/generated-sources/mock/descriptionElement/Edit/Edit.html");
115         }
116         
117         @Test
118         public void testReviewDescriptionElement() {
119         	ModelAndView modelAndView = new ModelAndView("descriptionElement/edit/review");
120         	TaxonDescription description = ((Taxon)dataSet.getTaxonBases().get(0)).getDescriptions().iterator().next();
121             modelAndView.addObject("inDescriptionObj",description);
122             
123             TextData textData = new TextData();
124             textData.getMultilanguageText().put(Language.DEFAULT(), LanguageString.NewInstance("I wandered lonely as a cloud That floats on high o'er vales and hills, When all at once I saw a crowd, A host, of golden daffodils, Beside the lake, beneath the trees Fluttering and dancing in the breeze.", Language.DEFAULT()));
125             textData.getMultilanguageText().put(Language.FRENCH(), LanguageString.NewInstance("Je suis all� me promener seul comme un nuage qui flotte en haut des collines et de vallons o'er, quand tout � coup, j'ai vu une foule, une foule de jonquilles dor�es, � c�t� du lac, sous les arbres flottant et dansant dans la brise.", Language.FRENCH()));           
126             textData.getMultilanguageText().put(Language.GERMAN(), LanguageString.NewInstance("Ich wanderte einsam wie eine Wolke Das schwimmt auf hohen o'er T�ler und H�gel, wenn alle auf einmal sah ich eine Menschenmenge, einen Host, der goldenen Narzissen, neben der See, unter den B�umen flatterten und Tanz in den Wind.", Language.GERMAN()));           
127             modelAndView.addObject("descriptionElement",textData);
128             modelAndView.addObject("featureObj",description.getElements().iterator().next().getFeature());
129             outputMock(modelAndView,"target/generated-sources/mock/descriptionElement/Edit/Review.html");
130         }
131     	
132     	@Test
133     	public void testSearchDistributionPageResults()  {
134     		ModelAndView modelAndView = new ModelAndView("description/list_distribution");
135     		final List<TaxonDescription> results = new ArrayList<TaxonDescription>();
136             results.addAll(((Taxon)dataSet.getTaxonBases().get(0)).getDescriptions());
137             results.addAll(((Taxon)dataSet.getTaxonBases().get(1)).getDescriptions());
138             results.addAll(((Taxon)dataSet.getTaxonBases().get(2)).getDescriptions());
139 
140     		
141             Pager<TaxonDescription> descriptions = new DefaultPagerImpl<TaxonDescription>(0, 3, 30, results) {
142                     protected String getLabel(Integer i) {
143                             NonViralName n = (NonViralName)results.get(i).getTaxon().getName();
144                             return n.getSpecificEpithet();
145                     }
146             };
147             modelAndView.addObject("pager",descriptions);
148             NamedArea namedArea = new NamedArea();
149     		namedArea.setId(1l);
150     		Set<NamedArea> continents = new HashSet<NamedArea>();
151     		continents.add(namedArea);
152     		modelAndView.addObject("continents",continents);
153     		List<String> names = new ArrayList<String>();
154     		names.add("Africa");
155     		modelAndView.addObject("names",names);
156     		
157     		outputMock(modelAndView,"target/generated-sources/mock/description/List_distribution.html");
158     	}
159     	
160     	@Test
161     	public void testSearchDescriptionPageResults()  {
162     		ModelAndView modelAndView = new ModelAndView("description/list_textData");
163             Language language = new Language();
164             FeatureTree topic = FeatureTree.NewInstance();
165     		
166     		List<TextData> textDataResults = new ArrayList<TextData>();
167     		for(TaxonDescription taxonDescription : ((Taxon)dataSet.getTaxonBases().get(0)).getDescriptions()) {
168     			for(DescriptionElementBase descriptionElement : taxonDescription.getElements()) {
169     				if(descriptionElement instanceof TextData) {
170     			     TextData t = (TextData)descriptionElement;
171     			     TextDataWithFeatureTree td = new TextDataWithFeatureTree(t, topic);
172     			     LanguageString ls = LanguageString.NewInstance("<span class=\"result\">Lorem</span> <span class=\"result\">ipsum</span> dolor sit amet, consectetuer.... Vestibulum ante <span class=\"result\">ipsum</span> primis in faucibus orci", language);
173     			     td.getMultilanguageText().put(language, ls);
174     			
175     			        textDataResults.add(td);
176     				}
177     			}
178     		}
179     		
180     		Pager<TextData> results = new DefaultPagerImpl<TextData>(0, 4, 30, textDataResults);
181     		modelAndView.addObject("pager",results);		
182     		modelAndView.addObject("query", "Lorem ipsum");
183     		outputMock(modelAndView,"target/generated-sources/mock/description/List_textData.html");
184     	}
185     	
186     	@Test
187     	public void testFeatureTreePage() {
188     		ModelAndView modelAndView = new ModelAndView("featureTree/index");
189     		modelAndView.addObject("object",dataSet.getFeatureTrees().get(0));
190     		outputMock(modelAndView,"target/generated-sources/mock/featureTree/Index.html");
191     		
192     	}
193     	
194     	@Test
195     	public void testPolytomousKeyPage() {
196     		ModelAndView modelAndView = new ModelAndView("featureTree/index");
197     		modelAndView.addObject("object",dataSet.getFeatureTrees().get(4));
198     		outputMock(modelAndView,"target/generated-sources/mock/featureTree/Index_polytomousKey.html");
199     		
200     	}
201 }