Project

General

Profile

« Previous | Next » 

Revision 2f65af04

Added by Andreas Kohlbecker almost 5 years ago

fix #8304 redirect from name to taxon page depending on drupal path argument, with test

View differences:

src/main/java/eu/etaxonomy/dataportal/pages/PortalPage.java
10 10
import java.util.ArrayList;
11 11
import java.util.List;
12 12
import java.util.concurrent.TimeUnit;
13
import java.util.regex.Matcher;
14
import java.util.regex.Pattern;
13 15

  
14 16
import org.apache.commons.io.FileUtils;
15 17
import org.apache.log4j.Logger;
......
50 52

  
51 53
    public static final Logger logger = Logger.getLogger(PortalPage.class);
52 54

  
53
    protected final static String DRUPAL_PAGE_QUERY_BASE = "?q=";
55
    protected final static String DRUPAL_PAGE_QUERY = "q=";
56

  
57
    private final static Pattern DRUPAL_PAGE_QUERY_PATTERN = Pattern.compile("q=([^&]*)");
54 58

  
55 59
    public enum MessageType {status, warning, error} // needs to be lowercase
56 60

  
......
67 71

  
68 72
    /**
69 73
     * Implementations of this method will supply the relative
70
     * path to the Drupal page. This path will usally have the form
74
     * path to the Drupal page. This path will usually have the form
71 75
     * <code>cdm_dataportal/{nodetype}</code>. For example the taxon pages all
72 76
     * have the page base <code>cdm_dataportal/taxon</code>
73 77
     */
74 78
    protected abstract String getDrupalPageBase();
75 79

  
76
    private String drupalPagePath;
80
    private String initialDrupalPagePath;
77 81

  
78 82
    protected URL pageUrl;
79 83

  
......
124 128

  
125 129
        this.wait = new JUnitWebDriverWait(driver, WAIT_SECONDS);
126 130

  
127
        this.drupalPagePath = getDrupalPageBase() + (pagePathSuffix != null ? "/" + pagePathSuffix: "");
131
        this.initialDrupalPagePath = getDrupalPageBase() + (pagePathSuffix != null ? "/" + pagePathSuffix: "");
128 132

  
129
        this.pageUrl = new URL(context.getBaseUri().toString() + DRUPAL_PAGE_QUERY_BASE + drupalPagePath);
133
        this.pageUrl = new URL(context.getBaseUri().toString() + "?" + DRUPAL_PAGE_QUERY + initialDrupalPagePath);
130 134

  
131 135
        // tell browser to navigate to the page
132 136
        driver.get(pageUrl.toString());
......
238 242
    }
239 243

  
240 244
    public String getDrupalPagePath() {
241
        return drupalPagePath;
245
        URL currentURL;
246
        try {
247
            currentURL = new URL(driver.getCurrentUrl());
248
            if(currentURL.getQuery() != null && currentURL.getQuery().contains(DRUPAL_PAGE_QUERY)){
249
                Matcher m = DRUPAL_PAGE_QUERY_PATTERN.matcher(currentURL.getQuery());
250
                m.matches();
251
                return m.group(1);
252
            } else {
253
                return currentURL.getPath().replaceFirst("^"+ context.getBaseUri().getPath(), "");
254
            }
255
        } catch (MalformedURLException e) {
256
            throw new RuntimeException(e);
257
        }
258
    }
259

  
260
    /**
261
     * Returns the the page path with which the page has initially been loaded.
262
     * Due to redirects the actual page path which can be retrieved by
263
     * {@link #getDrupalPagePath()} might be different
264
     *
265
     */
266
    public String getInitialDrupalPagePath() {
267
        return initialDrupalPagePath;
242 268
    }
243 269

  
244 270
    /**

Also available in: Unified diff