Project

General

Profile

Download (11.6 KB) Statistics
| Branch: | Tag: | Revision:
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.cichorieae;
11

    
12
import java.net.MalformedURLException;
13
import java.util.List;
14
import java.util.UUID;
15

    
16
import org.apache.log4j.Logger;
17
import org.junit.Before;
18
import org.junit.Test;
19
import org.openqa.selenium.By;
20
import org.openqa.selenium.NoSuchElementException;
21
import org.openqa.selenium.WebElement;
22

    
23
import eu.etaxonomy.dataportal.DataPortalContext;
24
import eu.etaxonomy.dataportal.elements.FeatureBlock;
25
import eu.etaxonomy.dataportal.elements.ImgElement;
26
import eu.etaxonomy.dataportal.elements.LinkElement;
27
import eu.etaxonomy.dataportal.elements.MultipartDescriptionElementRepresentation;
28
import eu.etaxonomy.dataportal.junit.CdmDataPortalTestBase;
29
import eu.etaxonomy.dataportal.junit.DataPortalContextSuite.DataPortalContexts;
30
import eu.etaxonomy.dataportal.pages.TaxonProfilePage;
31

    
32
/**
33
 * @author a.kohlbecker
34
 *
35
 */
36

    
37
@DataPortalContexts( { DataPortalContext.cichorieae })
38
public class Lactuca_triquetra_TaxonProfileTest extends CdmDataPortalTestBase{
39

    
40
    public static final Logger logger = Logger.getLogger(Lactuca_triquetra_TaxonProfileTest.class);
41

    
42
    static UUID taxonUuid = UUID.fromString("ecb7a76e-694a-4706-b1ab-a2eb334173ff");
43

    
44
    TaxonProfilePage p = null;
45

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

    
49
        if(p != null && driver != null ){
50
            logger.debug("TaxonProfilePage p:" + p.getPageURL() + ", driver is at " + driver.getCurrentUrl());
51
        }
52
        p = new TaxonProfilePage(driver, getContext(), taxonUuid);
53

    
54
    }
55

    
56

    
57
    @Test
58
    public void testTitleAndTabs() {
59

    
60
        assertEquals(getContext().prepareTitle("Lactuca triquetra"), p.getTitle());
61
        assertNull("Authorship information should be hidden", p.getAuthorInformationText());
62

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

    
71
    }
72

    
73
    @Test
74
    public void testProfileImage() {
75
        ImgElement profileImage = p.getProfileImage();
76
        assertNotNull("Expecting profile images to be switched on", profileImage);
77
        assertTrue("Expecting image Lactuca_triquetra_Bc_01.jpg but was " + profileImage.getSrcUrl().toString(), profileImage.getSrcUrl().toString().matches("(?i).*Lactuca_triquetra_Bc_01\\.jpg.*"));
78
    }
79

    
80

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

    
87
        FeatureBlock featureBlock;
88
        int featureId = 0;
89

    
90
        int descriptionElementFontSize = 12;
91
        String expectedCssDisplay = "inline";
92
        String expectedListStyleType = "none";
93
        String expectedListStylePosition = "outside";
94
        String expectedListStyleImage = "none";
95
        int indent = 0;
96

    
97
        /* Description */
98
        String featureClass = "description";
99
        String featureLabel = "Description";
100
        String blockTextFull = null;
101
        String blockTextBegin = featureLabel + "\nHerb, perennial, scoparious, 40-80 cm high. Flowering stems erect, triangular, medullary, glaucous-green, soon leafless, strongly branched; branches erect, slender. Cauline leaves few, glabrous.";
102
        String blockTextEnd = "Pappus white, 6.0-7.0 mm long, persistent, fragile, shortly barbellate or scabridulous.\n\nbased on: Meikle, R.D. 1985: Flora auf Cyprus 2. - Kew (as Prenanthes triquetra).";
103
        expectedListStyleType = "none";
104

    
105
        p.testTableOfContentEntry(featureId++,featureLabel, featureClass);
106
        featureBlock = p.getFeatureBlockAt(featureId, featureClass, "div", "span");
107

    
108
        assertTrue(featureBlock.getText().startsWith(blockTextBegin));
109
        assertTrue(featureBlock.getText().endsWith(blockTextEnd));
110
        featureBlock.testDescriptionElementLayout(0, indent, descriptionElementFontSize, expectedCssDisplay, expectedListStyleType, expectedListStylePosition, expectedListStyleImage);
111
        assertEquals(0, featureBlock.getOriginalSourcesSections().size());
112

    
113
        /* Distribution */
114
        expectedCssDisplay = "block";
115
        featureClass = "distribution";
116
        featureLabel = "Distribution";
117
        // below some assertions have been adapted to a bug in the library: TODO remove below comments when ticket is reviewed
118
        //       see  #3475 (DescriptionServiceImpl.getOrderedDistributions loses distributions)
119
        //
120
        // original expectation disabled as bug occured:
121
//        blockTextFull = featureLabel + "\nAsia-Temperate:\nCyprus 1,2; Lebanon-Syria (Lebanon 3,4,5); Palestine (Israel 5,6).\n1. Meikle, R. D., Flora of Cyprus 2. 1985, 2. Osorio-Tafall, B. H. & Serafim, G. M., List of the vascular plants of Cyprus. 1973, 3. Mouterde, P., Nouvelle flore du Liban et de la Syrie. Texte 3. 1978-1984, 4. Boissier, E., Flora Orientalis 3. 1875, 5. Post, G. E. , Flora of Syria, Palestine, and Sinai 2. 1933, 6. Zohary, M. & Feinbrun-Dothan, N., Flora Palaestina 3. 1978)";
122
        // interim expectation as long bug was not fixed:
123
//        blockTextFull = featureLabel + "\n\n\nAsia-Temperate:\nCyprus 1,2; Lebanon-Syria (Lebanon 3,4,5); Palestine (Israel 6).\n1. Meikle, R. D., Flora of Cyprus 2. 1985, 2. Osorio-Tafall, B. H. & Serafim, G. M., List of the vascular plants of Cyprus. 1973, 3. Mouterde, P., Nouvelle flore du Liban et de la Syrie. Texte 3. 1978-1984, 4. Boissier, E., Flora Orientalis 3. 1875, 5. Post, G. E. , Flora of Syria, Palestine, and Sinai 2. 1933, 6. Zohary, M. & Feinbrun-Dothan, N., Flora Palaestina 3. 1978";
124
        // after fixig the bug #3475, more sources are now displayed than ever before:
125
        // after layout changes there is an additional space: blockTextFull = featureLabel + "\n\nAsia-Temperate:\nCyprus 1,2; Lebanon-Syria (Lebanon 3,4,5); Palestine (Israel 5,6,7).\n1. Meikle, R. D., Flora of Cyprus 2. 1985, 2. Osorio-Tafall, B. H. & Serafim, G. M., List of the vascular plants of Cyprus. 1973, 3. Mouterde, P., Nouvelle flore du Liban et de la Syrie. Texte 3. 1978-1984, 4. Boissier, E., Flora Orientalis 3. 1875, 5. Post, G. E. , Flora of Syria, Palestine, and Sinai 2. 1933, 7. Zohary, M. & Feinbrun-Dothan, N., Flora Palaestina 3. 19786. (N)";
126
        blockTextFull = featureLabel + "\n\nAsia-Temperate:\nCyprus A,B; Lebanon-Syria (Lebanon C,D,E); Palestine (Israel E,1,F).\n"
127
                + "A. Meikle, R. D., Flora of Cyprus 2. 1985 (as Prenanthes triquetra), B. Osorio-Tafall, B. H. & Serafim, G. M., List of the vascular plants of Cyprus. 1973, C. Mouterde, P., Nouvelle flore du Liban et de la Syrie. Texte 3. 1978-1984 (as Scariola triquetra), D. Boissier, E., Flora Orientalis 3. 1875, E. Post, G. E. , Flora of Syria, Palestine, and Sinai 2. 1933, F. Zohary, M. & Feinbrun-Dothan, N., Flora Palaestina 3. 1978\n1. (N)";
128
        p.testTableOfContentEntry(featureId++, featureLabel, featureClass);
129
        featureBlock = p.getFeatureBlockAt(featureId, featureClass, "div", "dt", "dd");
130

    
131
        // TODO  after #4166 (Map legend causes inconsistent spacing below map) is fixed the below trick which relaxes this test can be removed
132
        String relaxedBlockText = featureBlock.getText().replaceFirst("\n\n\n", "\n\n");
133

    
134
        // FIXME ignore until #4411 is decided
135
        boolean is4411_OK = false;
136
        if(is4411_OK ) {
137
            assertEquals(blockTextFull, relaxedBlockText);
138

    
139
            MultipartDescriptionElementRepresentation descriptionElement = (MultipartDescriptionElementRepresentation) featureBlock.getDescriptionElement(0);
140
            logger.info(descriptionElement.getText());
141
            featureBlock.testDescriptionElementLayout(0, indent, descriptionElementFontSize, expectedCssDisplay, expectedListStyleType, expectedListStylePosition, expectedListStyleImage);
142
            assertEquals(0, featureBlock.getOriginalSourcesSections().size());
143
    //        assertEquals("Expecting 7 FootnoteKeys", 7, featureBlock.getFootNoteKeys().size()); //original version
144
    //        assertEquals("Expecting 6 FootnoteKeys", 6, featureBlock.getFootNoteKeys().size());   //version after bug #3475
145
            assertEquals("Expecting 8 FootnoteKeys", 8, featureBlock.countFootNoteKeys()); // new version #3475 fixed
146
            assertEquals("Expecting 7 Footnotes", 7, featureBlock.countFootNotes());
147
        }
148

    
149
        assertNotNull("Expecting an OpenLayers map", featureBlock.getElement().findElement(By.id("openlayers-map-distribution")));
150
        WebElement mapCaptionElement = null;
151
        try {
152
            mapCaptionElement = featureBlock.getElement().findElement(By.className("distribution_map_caption"));
153
        } catch (NoSuchElementException e){
154
            /* IGNORE */
155
        }
156
        assertNull(mapCaptionElement);
157

    
158
        /* Uses */
159
        featureClass = "ecology";
160
        featureLabel = "Ecology";
161
        blockTextFull = featureLabel + "\n500 m. On chalky cliffs or in flushes on serpentine.\n\nfrom: Meikle, R. D. 1985: Flora of Cyprus 2. – Kew. (as Prenanthes triquetra)";
162
        expectedCssDisplay = "inline";
163

    
164
        p.testTableOfContentEntry(featureId++, featureLabel, featureClass);
165
        featureBlock = p.getFeatureBlockAt(featureId, featureClass, "div", "span");
166

    
167
        assertEquals(blockTextFull, featureBlock.getText());
168
        featureBlock.testDescriptionElementLayout(0, indent, descriptionElementFontSize, expectedCssDisplay, expectedListStyleType, expectedListStylePosition, expectedListStyleImage);
169
        assertEquals(0, featureBlock.getOriginalSourcesSections().size());
170
        assertEquals("Expecting no FootnoteKeys", 0, featureBlock.countFootNoteKeys());
171
        assertEquals("Expecting no Footnotes", 0, featureBlock.countFootNotes());
172

    
173

    
174
        /* Common names */
175
        featureClass = "common-names";
176
        featureLabel = "Common names";
177
        expectedCssDisplay = "block";
178
        // after bug #3475 was fixed the number of footnotes increased by one
179
        blockTextFull = featureLabel + "\nArabic (Lebanon): سْكَرْيولَة ثُلاثِيَّة الأَرْكانG,2\nG. Nehmé, M., Dictionnaire Etymologique de la Flore du Liban. 2000 (as Scariola triquetra (Labill.) Soják)\n2. recommended";
180

    
181
        p.testTableOfContentEntry(featureId++, featureLabel, featureClass);
182
        featureBlock = p.getFeatureBlockAt(featureId, featureClass, "div", "span");
183

    
184
        assertEquals(blockTextFull, featureBlock.getText());
185

    
186

    
187
        /* Credits */
188
        featureClass = "credits";
189
        featureLabel = "Credits";
190
        blockTextFull = featureLabel + "\nChristodoulou C. S. 2009: Images (1 added).\nMakris C. 2009: Images (1 added).";
191
        expectedCssDisplay = "block";
192

    
193
        p.testTableOfContentEntry(featureId++, featureLabel, featureClass);
194
        featureBlock = p.getFeatureBlockAt(featureId, featureClass, "div", "span");
195

    
196
        assertEquals(blockTextFull, featureBlock.getText());
197
        featureBlock.testDescriptionElementLayout(0, indent, descriptionElementFontSize, expectedCssDisplay, expectedListStyleType, expectedListStylePosition, expectedListStyleImage);
198
        assertEquals(0, featureBlock.getOriginalSourcesSections().size());
199
        assertEquals("Expecting no FootnoteKeys", 0, featureBlock.countFootNoteKeys());
200
        assertEquals("Expecting no Footnotes", 0, featureBlock.countFootNotes());
201

    
202
    }
203

    
204
}
(12-12/13)