Project

General

Profile

Download (1.92 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2016 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.remote;
10

    
11
import org.apache.logging.log4j.LogManager;
12
import org.apache.logging.log4j.Logger;
13
import org.junit.Assert;
14
import org.junit.Before;
15
import org.springframework.web.client.RestTemplate;
16

    
17
/**
18
 * @author a.kohlbecker
19
 * @since Feb 22, 2016
20
 */
21
public class WebServiceTestBase extends Assert {
22

    
23
    public static final Logger logger = LogManager.getLogger(WebServiceTestBase.class);
24

    
25
    private int port = 9180;
26
    private String baseUri = "";
27

    
28
    RestTemplate template = new RestTemplate();
29

    
30
    @Before
31
    public void setUp() {
32
        if(System.getProperty("sun.java.command") != null && System.getProperty("sun.java.command").startsWith("org.eclipse.jdt.internal.junit.runner.RemoteTestRunner")){
33
            port = 8080;
34
            logger.info(" setUp() : \n" +
35
                        "==================================================================\n" +
36
                        " Eclipse ide detected, expecting cdm remote instance at port 8080 \n" +
37
                        "==================================================================");
38
        }
39
        baseUri = String.format("http://localhost:%1$d", port);
40
        logger.info("cdm remote instance url: " + baseUri);
41
    }
42

    
43
    public String getBaseUri() {
44
        return baseUri;
45
    }
46

    
47
    public String httpGetJson(String endPoint, String query) {
48
        StringBuilder uri = new StringBuilder(baseUri);
49
        if(endPoint != null) {
50
            uri.append(endPoint);
51
        }
52
        if(query != null) {
53
            uri.append("?").append(query);
54
        }
55
        logger.debug("httpGetJson: " + uri.toString());
56
        return template.getForObject(uri.toString(), String.class);
57
    }
58
}
(4-4/4)