@@ -77,6 +77,10 @@ public static void initialize() {
7777 .port (8080 );
7878 calculationServiceURL = String .format ("http://%s:%s" , calculationService .getIp (),
7979 calculationService .getExternalPort ());
80+ while (!docker .containers ().container ("calculationservice" ).portIsListeningOnHttp (8080 ,
81+ (port ) -> port .inFormat (calculationServiceURL )).succeeded ()) {
82+ LOG .info ("Waiting for calculation service to respond over HTTP" );
83+ }
8084 LOG .info ("Calculation Service url found: " + calculationServiceURL );
8185
8286 DockerPort userService = docker .containers ().container ("userservice" )
@@ -152,14 +156,16 @@ public void tripQueryGETSpecificTripRequestSuccess() throws JSONException {
152156 String body = "{ \" originAddress\" : \" Weston, FL\" , \" destinationAddress\" : "
153157 + "\" Miami, FL\" , \" userId\" : \" 123e4567-e89b-12d3-a456-426655440000\" }" ;
154158 HttpEntity <String > request = new HttpEntity <>(body , headers );
155- ResponseEntity <String > postResponse = restTemplate .postForEntity (tripCommandURL + "/api/v1/trip" , request , String .class );
159+ ResponseEntity <String > postResponse = restTemplate .postForEntity (tripCommandURL + "/api/v1/trip" , request ,
160+ String .class );
156161 assertThat (postResponse .getStatusCodeValue ()).isEqualTo (201 );
157162
158163 JSONObject json = new JSONObject (postResponse .getBody ());
159164 tripId = json .getString ("id" );
160165
161166 //when:
162- ResponseEntity <String > response = restTemplate .getForEntity (tripQueryURL + "/api/v1/trip/" + tripId , String .class );
167+ ResponseEntity <String > response = restTemplate .getForEntity (tripQueryURL + "/api/v1/trip/" + tripId ,
168+ String .class );
163169
164170 //then:
165171 assertThat (response .getStatusCodeValue ()).isEqualTo (200 );
@@ -178,4 +184,23 @@ public void tripQueryGETAllTripsRequestSuccess() {
178184 //then:
179185 assertThat (response .getStatusCodeValue ()).isEqualTo (200 );
180186 }
187+
188+ @ Test
189+ public void calculationServiceRequestSuccess () {
190+ //given:
191+ HttpHeaders headers = new HttpHeaders ();
192+ headers .add ("Authorization" , "Bearer " + token );
193+ headers .add ("Content-Type" , "application/json" );
194+
195+ String body = "{ \" origin\" : \" Weston, FL\" , \" destination\" : \" Miami, FL\" }" ;
196+ HttpEntity <String > request = new HttpEntity <>(body , headers );
197+
198+ //when:
199+ ResponseEntity <String > response = restTemplate .postForEntity (calculationServiceURL + "/api/v1/cost" , request ,
200+ String .class );
201+
202+ //then:
203+ assertThat (response .getStatusCodeValue ()).isEqualTo (200 );
204+
205+ }
181206}
0 commit comments