7
7
import java .nio .file .Paths ;
8
8
import java .util .ArrayList ;
9
9
import java .util .List ;
10
- import java .util .concurrent .TimeUnit ;
11
10
import java .util .concurrent .TimeoutException ;
12
11
13
12
import org .apache .commons .io .FileUtils ;
23
22
import org .springframework .boot .test .context .SpringBootTest .WebEnvironment ;
24
23
import org .springframework .boot .web .server .LocalServerPort ;
25
24
import org .springframework .http .HttpStatus ;
26
- import org .springframework .http .ResponseEntity ;
27
25
import org .springframework .test .context .ContextConfiguration ;
28
26
import org .springframework .test .context .TestExecutionListeners ;
29
27
import org .springframework .test .context .junit4 .SpringRunner ;
30
28
import org .springframework .test .context .support .AbstractTestExecutionListener ;
31
29
import org .springframework .test .context .support .DependencyInjectionTestExecutionListener ;
32
30
33
31
import com .ericsson .ei .utils .AMQPCommunication ;
34
- import com .ericsson .ei .utils .HttpRequest ;
35
- import com .ericsson .ei .utils .HttpRequest .HttpMethod ;
32
+ import com .ericsson .eiffelcommons .utils .HttpRequest ;
33
+ import com .ericsson .eiffelcommons .utils .HttpRequest .HttpMethod ;
34
+ import com .ericsson .eiffelcommons .utils .ResponseEntity ;
36
35
37
36
import cucumber .api .java .Before ;
38
37
import cucumber .api .java .en .Given ;
47
46
public class CommonSteps extends AbstractTestExecutionListener {
48
47
49
48
@ LocalServerPort
50
- private int frontendPort ;
51
- private String frontendHost = "localhost" ;
49
+ private int frontEndPort ;
50
+ private String frontEndHost = "localhost" ;
51
+ private String protocol = "http" ;
52
+ private String baseURL ;
52
53
private String rabbitHost ;
53
54
private int rabbitPort ;
54
55
private String rabbitUsername ;
@@ -58,7 +59,7 @@ public class CommonSteps extends AbstractTestExecutionListener {
58
59
59
60
private List <HttpRequest > httpRequestList = new ArrayList <>();
60
61
private HttpRequest httpRequest ;
61
- private ResponseEntity < String > response ;
62
+ private ResponseEntity response ;
62
63
63
64
private static final String RESOURCE_PATH = "src/integrationtest/resources/" ;
64
65
private static final String BODIES_PATH = "bodies/" ;
@@ -67,6 +68,11 @@ public class CommonSteps extends AbstractTestExecutionListener {
67
68
68
69
private static final Logger LOGGER = LoggerFactory .getLogger (CommonSteps .class );
69
70
71
+ @ Before
72
+ public void beforeAllScenarios () {
73
+ baseURL = String .format ("%s://%s:%d" , protocol , frontEndHost , frontEndPort );
74
+ }
75
+
70
76
@ Before ("@QueryByIdScenario or @QueryFreestyleScenario" )
71
77
public void beforeQueryScenario () {
72
78
rabbitHost = System .getProperty ("rabbit.host" );
@@ -79,8 +85,8 @@ public void beforeQueryScenario() {
79
85
80
86
@ Given ("^frontend is up and running$" )
81
87
public void frontend_running () {
82
- LOGGER .debug ("Front-end port: {}" , frontendPort );
83
- assertEquals (true , frontendPort != 0 );
88
+ LOGGER .debug ("Front-end port: {}" , frontEndPort );
89
+ assertEquals (true , frontEndPort != 0 );
84
90
}
85
91
86
92
@ Given ("^an aggregated object is created$" )
@@ -99,7 +105,7 @@ public void aggregated_object_created() throws IOException, TimeoutException {
99
105
public void request_to_rest_api (String method , String endpoint ) throws Throwable {
100
106
LOGGER .debug ("Method: {}, Endpoint: {}" , method , endpoint );
101
107
httpRequest = new HttpRequest (HttpMethod .valueOf (method ));
102
- httpRequest .setHost ( frontendHost ). setPort ( frontendPort ).setEndpoint (endpoint );
108
+ httpRequest .setBaseUrl ( baseURL ).setEndpoint (endpoint );
103
109
}
104
110
105
111
@ When ("^\' (.*)\' endpoint is set in request list at index (\\ d+)$" )
@@ -158,8 +164,8 @@ public void request_sent_body_not_received(int seconds, int statusCode) throws T
158
164
long stopTime = System .currentTimeMillis () + (seconds * 1000 );
159
165
do {
160
166
response = httpRequest .performRequest ();
161
- } while (response .getStatusCode (). value () == statusCode && stopTime > System .currentTimeMillis ());
162
- assertEquals (HttpStatus .OK , response .getStatusCode ());
167
+ } while (response .getStatusCode () == statusCode && stopTime > System .currentTimeMillis ());
168
+ assertEquals (HttpStatus .OK . value () , response .getStatusCode ());
163
169
}
164
170
165
171
@ Then ("^request is saved to request list at index (\\ d+)$" )
@@ -171,7 +177,7 @@ public void request_is_saved_to_list(int index) throws Throwable {
171
177
@ Then ("^response code (\\ d+) is received$" )
172
178
public void get_response_code (int statusCode ) throws Throwable {
173
179
LOGGER .debug ("Response code: {}" , response .getStatusCode ());
174
- assertEquals (HttpStatus . valueOf ( statusCode ) , response .getStatusCode ());
180
+ assertEquals (statusCode , response .getStatusCode ());
175
181
}
176
182
177
183
@ Then ("^response body \' (.*)\' is received$" )
0 commit comments