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.log4j.Logger;
|
12
|
import org.junit.Assert;
|
13
|
import org.junit.Before;
|
14
|
import org.springframework.web.client.RestTemplate;
|
15
|
|
16
|
|
17
|
/**
|
18
|
* @author a.kohlbecker
|
19
|
\* @since Feb 22, 2016
|
20
|
*
|
21
|
*/
|
22
|
public class WebServiceTestBase extends Assert {
|
23
|
|
24
|
public static final Logger logger = Logger.getLogger(WebServiceTestBase.class);
|
25
|
|
26
|
|
27
|
private int port = 9180;
|
28
|
private String baseUri = "";
|
29
|
|
30
|
RestTemplate template = new RestTemplate();
|
31
|
|
32
|
@Before
|
33
|
public void setUp() {
|
34
|
if(System.getProperty("sun.java.command") != null && System.getProperty("sun.java.command").startsWith("org.eclipse.jdt.internal.junit.runner.RemoteTestRunner")){
|
35
|
port = 8080;
|
36
|
logger.info(" setUp() : \n" +
|
37
|
"==================================================================\n" +
|
38
|
" Eclipse ide detected, expecting cdm remote instance at port 8080 \n" +
|
39
|
"==================================================================");
|
40
|
}
|
41
|
baseUri = String.format("http://localhost:%1$d", port);
|
42
|
logger.info("cdm remote instance url: " + baseUri);
|
43
|
}
|
44
|
|
45
|
public String getBaseUri() {
|
46
|
return baseUri;
|
47
|
}
|
48
|
|
49
|
public String httpGetJson(String endPoint, String query) {
|
50
|
StringBuilder uri = new StringBuilder(baseUri);
|
51
|
if(endPoint != null) {
|
52
|
uri.append(endPoint);
|
53
|
}
|
54
|
if(query != null) {
|
55
|
uri.append("?").append(query);
|
56
|
}
|
57
|
logger.debug("httpGetJson: " + uri.toString());
|
58
|
return template.getForObject(uri.toString(), String.class);
|
59
|
}
|
60
|
|
61
|
}
|