Skip to content

Commit 0e7c264

Browse files
authored
Merge branch 'master' into edgeWork
2 parents 30a65f4 + 7145892 commit 0e7c264

File tree

3 files changed

+105
-31
lines changed

3 files changed

+105
-31
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ services:
5050
- discovery-service
5151
- mysqlserver
5252
ports:
53-
- '8091:8091'
53+
- '8080'
5454

5555
mongo:
5656
image: 'mongo:3.4.1'

src/test/java/aist/edge/edgeservice/EdgeServiceIntegrationTests.java

Lines changed: 92 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@
33
import static org.assertj.core.api.Java6Assertions.assertThat;
44

55
import com.palantir.docker.compose.DockerComposeRule;
6+
import com.palantir.docker.compose.connection.DockerPort;
67
import com.palantir.docker.compose.connection.waiting.HealthChecks;
78

89
import java.util.*;
910

1011
import org.json.JSONException;
1112
import org.json.JSONObject;
1213
import org.junit.Before;
14+
import org.junit.BeforeClass;
1315
import org.junit.ClassRule;
1416
import org.junit.Test;
1517
import org.junit.runner.RunWith;
1618

19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
1721
import org.springframework.boot.test.context.SpringBootTest;
1822
import org.springframework.boot.test.web.client.TestRestTemplate;
1923
import org.springframework.http.*;
@@ -23,27 +27,73 @@
2327
@RunWith(SpringJUnit4ClassRunner.class)
2428
@SpringBootTest(classes = EdgeServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
2529
public class EdgeServiceIntegrationTests {
30+
protected static final Logger LOG = LoggerFactory.getLogger(EdgeServiceIntegrationTests.class);
2631

32+
private static String tripCommandURL;
33+
private static String tripQueryURL;
34+
private static String gmapsAdapterURL;
35+
private static String calculationServiceURL;
36+
private static String userServiceURL;
37+
38+
//Wait for all services to have ports open
2739
@ClassRule
2840
public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true)
2941
.file("src/test/resources/docker-compose.yml")
30-
.waitingForService("microservice--user-service", HealthChecks.toHaveAllPortsOpen())
31-
.waitingForService("microservice--user-service", HealthChecks.toRespondOverHttp(8091,
32-
(port) -> port.inFormat("http://localhost:8091")))
33-
.waitingForService("trip-management-cmd", HealthChecks.toHaveAllPortsOpen())
34-
.waitingForService("trip-management-cmd", HealthChecks.toRespondOverHttp(8080,
35-
(port) -> port.inFormat("http://localhost:8092")))
36-
.waitingForService("trip-management-query", HealthChecks.toHaveAllPortsOpen())
37-
.waitingForService("trip-management-query", HealthChecks.toRespondOverHttp(8080,
38-
(port) -> port.inFormat("http://localhost:8093")))
42+
.waitingForService("userservice", HealthChecks.toHaveAllPortsOpen())
43+
.waitingForService("mongo", HealthChecks.toHaveAllPortsOpen())
44+
.waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen())
45+
.waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen())
46+
.waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen())
47+
.waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen())
48+
.waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen())
3949
.waitingForService("discovery-service", HealthChecks.toHaveAllPortsOpen())
4050
.waitingForService("discovery-service", HealthChecks.toRespondOverHttp(8761,
4151
(port) -> port.inFormat("http://localhost:8761")))
4252
.build();
4353

54+
//Get IP addresses and ports to run tests on
55+
@BeforeClass
56+
public static void initialize() {
57+
LOG.info("Initializing ports from Docker");
58+
DockerPort tripManagementCommand = docker.containers().container("tripmanagementcmd")
59+
.port(8080);
60+
tripCommandURL = String.format("http://%s:%s", tripManagementCommand.getIp(),
61+
tripManagementCommand.getExternalPort());
62+
LOG.info("Trip Command url found: " + tripCommandURL);
63+
64+
DockerPort tripManagementQuery = docker.containers().container("tripmanagementquery")
65+
.port(8080);
66+
tripQueryURL = String.format("http://%s:%s", tripManagementQuery.getIp(),
67+
tripManagementQuery.getExternalPort());
68+
LOG.info("Trip Query url found: " + tripQueryURL);
69+
70+
DockerPort gmapsAdapter = docker.containers().container("gmapsadapter")
71+
.port(8080);
72+
gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(),
73+
gmapsAdapter.getExternalPort());
74+
LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL);
75+
76+
DockerPort calculationService = docker.containers().container("calculationservice")
77+
.port(8080);
78+
calculationServiceURL = String.format("http://%s:%s", calculationService.getIp(),
79+
calculationService.getExternalPort());
80+
LOG.info("Calculation Service url found: " + calculationServiceURL);
81+
82+
DockerPort userService = docker.containers().container("userservice")
83+
.port(8080);
84+
userServiceURL = String.format("http://%s:%s", userService.getIp(),
85+
userService.getExternalPort());
86+
while (!docker.containers().container("userservice").portIsListeningOnHttp(8080,
87+
(port) -> port.inFormat(userServiceURL)).succeeded()) {
88+
LOG.info("Waiting for user service to respond over HTTP");
89+
}
90+
LOG.info("User Service url found: " + userServiceURL);
91+
}
92+
4493
private TestRestTemplate restTemplate = new TestRestTemplate();
4594

4695
private String token;
96+
private String tripId;
4797

4898
@Before
4999
public void setUp() throws JSONException {
@@ -63,40 +113,67 @@ public void setUp() throws JSONException {
63113
HttpEntity<String> request = new HttpEntity<>(body, headers);
64114

65115
//when:
66-
ResponseEntity<String> response = restTemplate.postForEntity("http://localhost:8091/auth/oauth/token", request, String.class, parameters);
116+
ResponseEntity<String> response = restTemplate.postForEntity(userServiceURL + "/auth/oauth/token",
117+
request, String.class, parameters);
67118

68119
//then:
69120
assertThat(response.getStatusCodeValue()).isEqualTo(200);
70121
JSONObject json = new JSONObject(response.getBody());
71122
token = json.getString("access_token");
72123
}
73124

125+
74126
@Test
75127
public void tripCommandPOSTRequestSuccess() {
76128
//given:
77129
HttpHeaders headers = new HttpHeaders();
78130
headers.add("Authorization", "Bearer " + token);
79131
headers.add("Content-Type", "application/json");
80132

81-
String body = "{ \"originAddress\": \"Somewhere of the origin\", \"destinationAddress\": "
82-
+ "\"Somewhere destination\", \"userId\": \"123e4567-e89b-12d3-a456-426655440000\" }";
133+
String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": "
134+
+ "\"Miami, FL\", \"userId\": \"123e4567-e89b-12d3-a456-426655440000\" }";
83135
HttpEntity<String> request = new HttpEntity<>(body, headers);
84136

85137
//when:
86-
ResponseEntity<String> response = restTemplate.postForEntity("http://localhost:8092/api/trip", request, String.class);
138+
ResponseEntity<String> response = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request,
139+
String.class);
140+
141+
//then:
142+
assertThat(response.getStatusCodeValue()).isEqualTo(201);
143+
}
144+
145+
@Test
146+
public void tripQueryGETSpecificTripRequestSuccess() throws JSONException {
147+
//given:
148+
HttpHeaders headers = new HttpHeaders();
149+
headers.add("Authorization", "Bearer " + token);
150+
headers.add("Content-Type", "application/json");
151+
152+
String body = "{ \"originAddress\": \"Weston, FL\", \"destinationAddress\": "
153+
+ "\"Miami, FL\", \"userId\": \"123e4567-e89b-12d3-a456-426655440000\" }";
154+
HttpEntity<String> request = new HttpEntity<>(body, headers);
155+
ResponseEntity<String> postResponse = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, String.class);
156+
assertThat(postResponse.getStatusCodeValue()).isEqualTo(201);
157+
158+
JSONObject json = new JSONObject(postResponse.getBody());
159+
tripId = json.getString("id");
160+
161+
//when:
162+
ResponseEntity<String> response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trip/" + tripId, String.class);
87163

88164
//then:
89165
assertThat(response.getStatusCodeValue()).isEqualTo(200);
90166
}
91167

92168
@Test
93-
public void tripQueryGETRequestSuccess() {
169+
public void tripQueryGETAllTripsRequestSuccess() {
94170
//given:
95171
HttpHeaders headers = new HttpHeaders();
96172
headers.add("Authorization", "Bearer " + token);
173+
headers.add("Content-Type", "application/json");
97174

98175
//when:
99-
ResponseEntity<String> response = restTemplate.getForEntity("http://localhost:8093/api/trips", String.class);
176+
ResponseEntity<String> response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trips", String.class);
100177

101178
//then:
102179
assertThat(response.getStatusCodeValue()).isEqualTo(200);

src/test/resources/docker-compose.yml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ services:
66
image: springcloud/eureka
77
ports:
88
- "8761:8761"
9-
container_name: eureka-server
109

1110
# hystrix-dashboard:
1211
# image: kbastani/hystrix-dashboard
@@ -24,9 +23,9 @@ services:
2423
# ports:
2524
# - 8888:8888
2625

27-
mysql-server:
26+
mysqlserver:
2827
image: mysql:5.7
29-
container_name: mysql-server
28+
container_name: mysqlserver
3029
volumes:
3130
- mysql-data:/var/lib/mysql:rw
3231
restart: always
@@ -39,14 +38,14 @@ services:
3938
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
4039
MYSQL_DATABASE: 'user_service'
4140

42-
microservice--user-service:
41+
userservice:
4342
image: aista/user-service
43+
container_name: userservice
4444
depends_on:
4545
- discovery-service
46-
- mysql-server
47-
container_name: microservice--user-service
46+
- mysqlserver
4847
ports:
49-
- '8091:8091'
48+
- '8080'
5049

5150
mongo:
5251
image: 'mongo:3.4.1'
@@ -63,33 +62,31 @@ services:
6362
- "5672:5672"
6463
- "15672:15672"
6564

66-
trip-management-cmd:
65+
tripmanagementcmd:
6766
image: aista/trip-management-cmd
68-
container_name: trip-management-cmd
6967
environment:
7068
- RABBIT_HOST=rabbitmq
7169
- MONGO_HOST=mongo
7270
ports:
73-
- '8092:8080'
71+
- '8080'
7472
depends_on:
7573
- discovery-service
7674
- rabbitmq
7775
- mongo
7876

79-
trip-management-query:
77+
tripmanagementquery:
8078
image: aista/trip-management-query
81-
container_name: trip-management-query
8279
environment:
8380
- RABBIT_HOST=rabbitmq
8481
- MONGO_HOST=mongo
8582
ports:
86-
- '8093:8080'
83+
- '8080'
8784
depends_on:
8885
- rabbitmq
8986
- mongo
9087
- discovery-service
9188

92-
gmaps-adapter:
89+
gmapsadapter:
9390
image: aista/gmaps-adapter
9491
environment:
9592
- EUREKA_SERVER=discovery-service
@@ -98,7 +95,7 @@ services:
9895
depends_on:
9996
- discovery-service
10097

101-
calculation-service:
98+
calculationservice:
10299
image: aista/calculation-service
103100
environment:
104101
- EUREKA_SERVER=discovery-service

0 commit comments

Comments
 (0)