Project

General

Profile

« Previous | Next » 

Revision b9674e73

Added by Andreas Kohlbecker over 12 years ago

complete test of plamweb taxon profile

View differences:

.gitattributes
305 305
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/diptera/Diptera_OriginalSourceTest.java -text
306 306
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/flMalesiana/FloraMalesianaPolytomousKeyTest.java -text
307 307
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/flMalesiana/FloraMalesiana_OriginalSourceTest.java -text
308
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/palmae/Calamus_acanthospathus_TaxonProfileTest.java -text
308 309
modules/cdm_dataportal/test/phpUnit/TestUtils.php -text
309 310
modules/cdm_dataportal/test/phpUnit/bootstrap.php -text
310 311
modules/cdm_dataportal/test/phpUnit/phpUnit.conf.xml -text
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/elements/BaseElement.java
9 9
 */
10 10
package eu.etaxonomy.dataportal.elements;
11 11

  
12
import java.util.ArrayList;
12 13
import java.util.Arrays;
13 14
import java.util.List;
14 15

  
16
import org.openqa.selenium.By;
15 17
import org.openqa.selenium.WebElement;
16 18

  
17 19
/**
......
22 24
public class BaseElement {
23 25

  
24 26

  
27
	/**
28
	 * Default tolerance for testing sizes and positions
29
	 */
30
	protected static final double PIXEL_TOLERANCE = 0.5;
31

  
25 32
	private WebElement element;
26 33

  
27 34
	private List<String> classAttributes = null;
28 35

  
36
	private List<LinkElement> linksInElement = null;
37

  
29 38
	private String text = null;
30 39

  
31 40

  
......
45 54
		this.classAttributes = classAttributes;
46 55
	}
47 56

  
57
	public double getComputedFontSize(){
58
		return pxSizeToDouble(getElement().getCssValue("font-size") );
59
	}
60

  
61
	public static double pxSizeToDouble(String pxValue){
62
		return Double.valueOf( pxValue.replaceAll("[a-zA-Z]", "") );
63
	}
64

  
65
	public List<LinkElement> getLinksInElement() {
66
		if(linksInElement == null){
67
			linksInElement = new ArrayList<LinkElement>();
68

  
69
			if(getElement().getTagName().equals("a") && getElement().getAttribute("href") == null){
70
				// BaseElement is link itself
71
				linksInElement.add(new LinkElement(getElement()));
72
			} else {
73
				// look for links in subelements
74
				List<WebElement> links = getElement().findElements(By.xpath("./a[@href]"));
75
				for (WebElement link : links) {
76
					linksInElement.add(new LinkElement(link));
77
				}
78

  
79
			}
80
		}
81
		return linksInElement;
82
	}
83

  
48 84
	/**
49 85
	 * @param element
50 86
	 */
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/elements/FeatureBlock.java
13 13
import java.util.List;
14 14

  
15 15
import static junit.framework.Assert.*;
16
import static org.junit.Assert.assertEquals;
16 17

  
17 18
import org.openqa.selenium.By;
18 19
import org.openqa.selenium.WebElement;
......
44 45
		return footNotes;
45 46
	}
46 47

  
47
	public List<BaseElement> getOriginalSources() {
48
	public List<BaseElement> getOriginalSourcesSections() {
48 49
		return originalSources;
49 50
	}
50 51

  
......
81 82

  
82 83
		WebElement descriptionElementsRepresentation =  element.findElement(By.className("description"));
83 84
		featureType = descriptionElementsRepresentation.getAttribute("id");
85

  
86
		//TODO throw exception instead of making an assetion! selenium should have appropriate exeptions
84 87
		assertEquals("Unexpected tag enclosing description element representations", enclosingTag, descriptionElementsRepresentation.getTagName());
85 88

  
86 89
		for(WebElement el : descriptionElementsRepresentation.findElements(By.tagName(elementTag))){
......
89 92

  
90 93
	}
91 94

  
95
	/**
96
	 * @param indent
97
	 * @param computedFontSize
98
	 * @param expectedCssDisplay
99
	 * @param expectedListStyleType only applies if cssDisplay equals list-item
100
	 * @param expectedListStylePosition only applies if cssDisplay equals list-item
101
	 * @param expectedListStyleImage only applies if cssDisplay equals list-item
102
	 */
103
	public void testDescriptionElementLayout(int descriptionElementId, int indent, int computedFontSize
104
			, String expectedCssDisplay, String expectedListStyleType, String expectedListStylePosition, String expectedListStyleImage) {
105

  
106
		DescriptionElementRepresentation firstDescriptionElement = getDescriptionElements().get(descriptionElementId);
92 107

  
108
		int parentX = getElement().getLocation().getX();
109
		int elementX = firstDescriptionElement.getElement().getLocation().getX();
110
		double elementPadLeft = pxSizeToDouble(firstDescriptionElement.getElement().getCssValue("padding-left"));
93 111

  
112
		assertEquals(indent, elementX - parentX + elementPadLeft, PIXEL_TOLERANCE);
113
		assertEquals(computedFontSize, firstDescriptionElement.getComputedFontSize(), 0.5);
114
		assertEquals(expectedCssDisplay, firstDescriptionElement.getElement().getCssValue("display"));
115

  
116
		if(expectedCssDisplay.equals("list-item")){
117
			assertEquals(expectedListStylePosition, firstDescriptionElement.getElement().getCssValue("list-style-position"));
118
			assertEquals(expectedListStyleImage, firstDescriptionElement.getElement().getCssValue("list-style-image"));
119
			assertEquals(expectedListStyleType, firstDescriptionElement.getElement().getCssValue("list-style-type"));
120
		}
121
	}
94 122

  
95 123
}
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/elements/LinkElement.java
10 10

  
11 11
package eu.etaxonomy.dataportal.elements;
12 12

  
13
import static org.junit.Assert.assertEquals;
14

  
13 15
import org.openqa.selenium.WebElement;
14 16

  
15 17
/**
......
49 51
		return super.toSting() + ": " + getUrl() + "";
50 52
	}
51 53

  
54
	public static boolean testIfLinkElement(BaseElement element, String text, String href) {
55
		return testIfLinkElement(element.getElement(), text, href);
56
	}
57

  
58
	public static boolean testIfLinkElement(WebElement element, String text, String href) {
59
		assertEquals("a", element.getTagName());
60
		assertEquals(href, element.getAttribute("href"));
61
		assertEquals(text, element.getText());
62
		return true;
63
	}
64

  
52 65
}
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/pages/TaxonProfilePage.java
132 132
	}
133 133

  
134 134
	/**
135
	 * Finds the {@link FeatureBlock} specified by the <code>featureName</code> parameter.
136
	 * The following document structure is expected:
137
	 * <pre>
138
	 * &lt;div id="block-cdm_dataportal-feature-${featureName}" class="clear-block block block-cdm_dataportal-feature"&gt;
139
	 *   &lt;div class="content"&gt;
140
	 *     &lt;${enclosingTag} id="${featureName}" class="description"&gt;
141
	 *       &lt;${elementTag}&gt;DescriptionElement 1&lt;/${elementTag}&gt;
142
	 *       &lt;${elementTag}&gt;DescriptionElement 2&lt;/${elementTag}&gt;
143
	 *     &lt;/${enclosingTag}&gt;
144
	 *    &lt;/div&gt;
145
	 * </pre>
146
	 *
147
	 * The DescriptionElements can be get from the <code>FeatureBlock</code> by {@link FeatureBlock#getDescriptionElements()}.
148
	 *
135 149
	 * @param position Zero based index of position in list of feature blocks
136 150
	 * 			(only used to check against total number of feature blocks)
137
	 * @param featureName the fature name as it is used in the class attribute: <code>block-cdm_dataportal-feature-${featureName}</code>
151
	 * @param featureName the feature name as it is used in the class attribute: <code>block-cdm_dataportal-feature-${featureName}</code>
138 152
	 * @param enclosingTag
139 153
	 * @param elementTag
140 154
	 * @return
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/palmae/Calamus_acanthospathus_TaxonProfileTest.java
1
// $Id$
2
/**
3
 * Copyright (C) 2009 EDIT
4
 * European Distributed Institute of Taxonomy
5
 * http://www.e-taxonomy.eu
6
 *
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * See LICENSE.TXT at the top of this package for the full license terms.
9
 */
10
package eu.etaxonomy.dataportal.selenium.tests.palmae;
11

  
12
import static org.junit.Assert.*;
13

  
14
import java.net.MalformedURLException;
15
import java.util.List;
16
import java.util.UUID;
17

  
18
import org.apache.commons.lang.StringUtils;
19
import org.junit.After;
20
import org.junit.Before;
21
import org.junit.Test;
22
import org.openqa.selenium.By;
23
import org.openqa.selenium.WebElement;
24

  
25
import eu.etaxonomy.dataportal.DataPortalContext;
26
import eu.etaxonomy.dataportal.elements.BaseElement;
27
import eu.etaxonomy.dataportal.elements.DescriptionElementRepresentation;
28
import eu.etaxonomy.dataportal.elements.FeatureBlock;
29
import eu.etaxonomy.dataportal.elements.ImgElement;
30
import eu.etaxonomy.dataportal.elements.LinkElement;
31
import eu.etaxonomy.dataportal.junit.CdmDataPortalTestBase;
32
import eu.etaxonomy.dataportal.junit.DataPortalContextSuite.DataPortalContexts;
33
import eu.etaxonomy.dataportal.pages.TaxonProfilePage;
34

  
35
/**
36
 * @author a.kohlbecker
37
 *
38
 */
39

  
40
@DataPortalContexts( { DataPortalContext.palmae })
41
public class Calamus_acanthospathus_TaxonProfileTest extends CdmDataPortalTestBase{
42

  
43
	static UUID taxonUuid = UUID.fromString("bb340c78-880e-4dd0-91ff-81788a482b31");
44

  
45
	TaxonProfilePage p = null;
46

  
47
	@Before
48
	public void setUp() throws MalformedURLException {
49

  
50
		p = new TaxonProfilePage(driver, getContext(), taxonUuid);
51

  
52
	}
53

  
54

  
55
	@Test
56
	public void testTitleAndTabs() {
57

  
58
		assertEquals(getContext().prepareTitle("Calamus acanthospathus Griff., Calcutta J. Nat. Hist. 5: 39. 1845"), p.getTitle());
59
		assertNull("Authorship information should be hidden", p.getAuthorInformationText());
60

  
61
		List<LinkElement> primaryTabs = p.getPrimaryTabs();
62
		int tabId = 0;
63
		assertEquals("General", primaryTabs.get(tabId++).getText());
64
		assertEquals("Synonymy", primaryTabs.get(tabId++).getText());
65
		assertEquals("Images", primaryTabs.get(tabId++).getText());
66
		assertEquals("Specimens", primaryTabs.get(tabId++).getText());
67
		assertEquals("Expecting " + tabId + " tabs", tabId, primaryTabs.size());
68

  
69
	}
70

  
71
	@Test
72
	public void testProfileImage() {
73
		ImgElement profileImage = p.getProfileImage();
74
		assertNotNull("Expecting profile images to be switched on", profileImage);
75
		assertTrue("Expoecting image palm_tc_29336_1.jpg", profileImage.getSrcUrl().toString().endsWith("/palm_tc_29336_1.jpg"));
76
	}
77

  
78

  
79
	@Test
80
	public void testFeatures() {
81
		assertEquals("Content", p.getTableOfContentHeader());
82
		List<LinkElement> links = p.getTableOfContentLinks();
83
		assertNotNull("Expecting a list of TOC links in the profile page.", links);
84

  
85
		FeatureBlock featureBlock;
86
		int featureId = 0;
87

  
88
		int descriptionElementFontSize = 11;
89
		String expectedCssDisplay = "inline";
90
		String expectedListStyleType = "none";
91
		String expectedListStylePosition = "outside";
92
		String expectedListStyleImage = "none";
93
		int indent = 23;
94

  
95
		/* distribution */
96
		String featureClass = "distribution";
97
		String featureLabel = "Distribution";
98
		String blockTextFull = featureLabel + "\n\n\nMap accurate to TDWG level 3 distributions\n\nAssam, China South-Central, China Southeast, East Himalaya, India, Laos, Myanmar, Nepal, Thailand, Tibet (World Checklist of Monocotyledons)\nIndia (North-east), Bhutan, Myanmar, China (Tibet, South-east and South Yunnan), Thailand (North) and Laos (North). (T. Evans et al. 2002)";
99

  
100
		p.testTableOfContentEntry(featureId++, featureLabel, featureClass);
101
		featureBlock = p.getFeatureBlockAt(featureId, featureClass, "p", "span");
102

  
103
		assertEquals(blockTextFull, featureBlock.getText());
104
		featureBlock.testDescriptionElementLayout(0, indent, descriptionElementFontSize, expectedCssDisplay, expectedListStyleType, expectedListStylePosition, expectedListStyleImage);
105
		assertEquals(2, featureBlock.getOriginalSourcesSections().size());
106
		assertTrue(LinkElement.testIfLinkElement(featureBlock.getOriginalSourcesSections().get(0).getLinksInElement().get(0), "World Checklist of Monocotyledons", "http://127.0.0.1/palmae/"));
107
		assertTrue(LinkElement.testIfLinkElement(featureBlock.getOriginalSourcesSections().get(1).getLinksInElement().get(0), "T. Evans et al. 2002", "http://127.0.0.1/palmae/?q=cdm_dataportal/reference/706c5e5e-1dac-4fb2-b849-8e99ad7d63aa"));
108

  
109
		assertNotNull("Expecting an OpenLayers map", featureBlock.getElement().findElement(By.id("openlayers_map")));
110
		assertEquals("Map accurate to TDWG level 3 distributions", featureBlock.getElement().findElement(By.className("distribution_map_caption")).getText());
111

  
112

  
113
		/* Biology And Ecology */
114
		featureClass = "biology_and_ecology";
115
		featureLabel = "Biology And Ecology";
116
		blockTextFull = featureLabel + "\nEvergreen forest. In Laos at 1800 m, in Thailand at 1500 - 1700 m, in South Yunnan at 1600 m. (T. Evans et al. 2002)";
117
		expectedCssDisplay = "list-item";
118
		expectedListStyleType = "none";
119

  
120
		p.testTableOfContentEntry(featureId++,featureLabel, featureClass);
121
		featureBlock = p.getFeatureBlockAt(featureId, featureClass, "ul", "li");
122

  
123
		assertEquals(blockTextFull, featureBlock.getText());
124
		featureBlock.testDescriptionElementLayout(0, indent, descriptionElementFontSize, expectedCssDisplay, expectedListStyleType, expectedListStylePosition, expectedListStyleImage);
125
		assertEquals(1, featureBlock.getOriginalSourcesSections().size());
126
		assertTrue(LinkElement.testIfLinkElement(featureBlock.getOriginalSourcesSections().get(0).getLinksInElement().get(0), "T. Evans et al. 2002", "http://127.0.0.1/palmae/?q=cdm_dataportal/reference/706c5e5e-1dac-4fb2-b849-8e99ad7d63aa"));
127

  
128

  
129
		/* Conservation */
130
		featureClass = "conservation";
131
		featureLabel = "Conservation";
132
		blockTextFull = featureLabel + "\nOf moderate concern. In Indochina it apparently produces at most one or two additional stems and so probably regenerates poorly after harvesting, putting it at elevated risk even though it is widespread and occurs in high altitude forests, which are less threatened by agriculture and logging. It had declined severely due to harvesting in Sikkim over 100 years ago (Anderson 1869). (T. Evans et al. 2002)";
133
		expectedCssDisplay = "list-item";
134
		expectedListStyleType = "none";
135

  
136
		p.testTableOfContentEntry(featureId++, featureLabel, featureClass);
137
		featureBlock = p.getFeatureBlockAt(featureId, featureClass, "ul", "li");
138

  
139
		assertEquals(blockTextFull, featureBlock.getText());
140
		featureBlock.testDescriptionElementLayout(0, indent, descriptionElementFontSize, expectedCssDisplay, expectedListStyleType, expectedListStylePosition, expectedListStyleImage);
141
		assertEquals(1, featureBlock.getOriginalSourcesSections().size());
142
		assertTrue(LinkElement.testIfLinkElement(featureBlock.getOriginalSourcesSections().get(0).getLinksInElement().get(0), "T. Evans et al. 2002", "http://127.0.0.1/palmae/?q=cdm_dataportal/reference/706c5e5e-1dac-4fb2-b849-8e99ad7d63aa"));
143

  
144
		/* Common Name */
145
		featureClass = "common_name";
146
		featureLabel = "Common Name";
147
		blockTextFull = featureLabel + "\nwai hom (Lao Loum), blong eur (Khamu), wai hawm (Thailand) (T. Evans et al. 2002)";
148
		expectedCssDisplay = "list-item";
149
		expectedListStyleType = "none";
150

  
151
		p.testTableOfContentEntry(featureId++, featureLabel, featureClass);
152
		featureBlock = p.getFeatureBlockAt(featureId, featureClass, "ul", "li");
153

  
154
		assertEquals(blockTextFull, featureBlock.getText());
155
		featureBlock.testDescriptionElementLayout(0, indent, descriptionElementFontSize, expectedCssDisplay, expectedListStyleType, expectedListStylePosition, expectedListStyleImage);
156
		assertEquals(1, featureBlock.getOriginalSourcesSections().size());
157
		assertTrue(LinkElement.testIfLinkElement(featureBlock.getOriginalSourcesSections().get(0).getLinksInElement().get(0), "T. Evans et al. 2002", "http://127.0.0.1/palmae/?q=cdm_dataportal/reference/706c5e5e-1dac-4fb2-b849-8e99ad7d63aa"));
158

  
159
		/* Uses */
160
		featureClass = "uses";
161
		featureLabel = "Uses";
162
		blockTextFull = featureLabel + "\nThis species is highly valued for its excellent quality small-diameter cane throughout its range. There are small trial plantations in South Yunnan. (T. Evans et al. 2002)";
163
		expectedCssDisplay = "list-item";
164
		expectedListStyleType = "none";
165

  
166
		p.testTableOfContentEntry(featureId++, featureLabel, featureClass);
167
		featureBlock = p.getFeatureBlockAt(featureId, featureClass, "ul", "li");
168

  
169
		assertEquals(blockTextFull, featureBlock.getText());
170
		featureBlock.testDescriptionElementLayout(0, indent, descriptionElementFontSize, expectedCssDisplay, expectedListStyleType, expectedListStylePosition, expectedListStyleImage);
171
		assertEquals(1, featureBlock.getOriginalSourcesSections().size());
172
		assertTrue(LinkElement.testIfLinkElement(featureBlock.getOriginalSourcesSections().get(0).getLinksInElement().get(0), "T. Evans et al. 2002", "http://127.0.0.1/palmae/?q=cdm_dataportal/reference/706c5e5e-1dac-4fb2-b849-8e99ad7d63aa"));
173

  
174
		/* Discussion */
175
		featureClass = "discussion";
176
		featureLabel = "Discussion";
177
		String blockTextBegin = featureLabel + "\nBeccari (1908) confidently synonymised C. montanus under C. acanthospathus on the basis of the protologue and some detached fruits at K. They match well but";
178
		String blockTextEnd = "represent arbitrary divisions in a continuum between more and less robust individuals. There is no doubt about their identity with C. acanthospathus, a conclusion also reached by Wei (1986). (T. Evans et al. 2002)";
179
		expectedCssDisplay = "list-item";
180
		expectedListStyleType = "none";
181

  
182
		p.testTableOfContentEntry(featureId++, featureLabel, featureClass);
183
		featureBlock = p.getFeatureBlockAt(featureId, featureClass, "ul", "li");
184

  
185
		assertTrue(featureBlock.getText().startsWith(blockTextBegin));
186
		assertTrue(featureBlock.getText().endsWith(blockTextEnd));
187
		featureBlock.testDescriptionElementLayout(0, indent, descriptionElementFontSize, expectedCssDisplay, expectedListStyleType, expectedListStylePosition, expectedListStyleImage);
188
		assertEquals(1, featureBlock.getOriginalSourcesSections().size());
189
		assertTrue(LinkElement.testIfLinkElement(featureBlock.getOriginalSourcesSections().get(0).getLinksInElement().get(0), "T. Evans et al. 2002", "http://127.0.0.1/palmae/?q=cdm_dataportal/reference/706c5e5e-1dac-4fb2-b849-8e99ad7d63aa"));
190

  
191
		/* Discussion */
192
		featureClass = "materials_examined";
193
		featureLabel = "Materials Examined";
194
		blockTextBegin = featureLabel + "\nINDIA (NORTH-EAST): Sikkim, undated, (fr.), Hooker s.n. E72 (K); Khasia, undated, (pist.), Griffith 503 (K). BHUTAN: Sarbhang Distr., 2.5 km below Getchu on Chirang Road, 12 March 1982, (ster.)";
195
		blockTextEnd = "A. 5293 (K, BM, BK). LAOS (NORTH): Huaphanh Province, Viengthong Distr., Ban Sakok, Phou Loeuy Noy, 21 June 1999, (fr.), Oulathong OL 231 (FRCL, K). (T. Evans et al. 2002)";
196
		expectedCssDisplay = "list-item";
197
		expectedListStyleType = "none";
198

  
199
		p.testTableOfContentEntry(featureId++, featureLabel, featureClass);
200
		featureBlock = p.getFeatureBlockAt(featureId, featureClass, "ul", "li");
201

  
202
		assertTrue(featureBlock.getText().startsWith(blockTextBegin));
203
		assertTrue(featureBlock.getText().endsWith(blockTextEnd));
204
		featureBlock.testDescriptionElementLayout(0, indent, descriptionElementFontSize, expectedCssDisplay, expectedListStyleType, expectedListStylePosition, expectedListStyleImage);
205
		assertEquals(1, featureBlock.getOriginalSourcesSections().size());
206
		assertTrue(LinkElement.testIfLinkElement(featureBlock.getOriginalSourcesSections().get(0).getLinksInElement().get(0), "T. Evans et al. 2002", "http://127.0.0.1/palmae/?q=cdm_dataportal/reference/706c5e5e-1dac-4fb2-b849-8e99ad7d63aa"));
207

  
208
	}
209

  
210
}

Also available in: Unified diff