Skip to content

Commit 777d66b

Browse files
committed
Updated docker compose files in resources and in main, updated Integration Tests
1 parent 6bd3efc commit 777d66b

File tree

3 files changed

+83
-25
lines changed

3 files changed

+83
-25
lines changed

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ services:
4646
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
4747
MYSQL_DATABASE: 'user_service'
4848

49-
microservice--user-service:
49+
userservice:
5050
image: aista/user-service
5151
depends_on:
5252
- discovery-service
5353
- mysql-server
54-
container_name: microservice--user-service
54+
container_name: userservice
5555
ports:
5656
- '8091:8091'
5757

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

Lines changed: 58 additions & 13 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,24 +27,65 @@
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 userServiceEndpoint;
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("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen())
44+
.waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen())
45+
.waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen())
46+
.waitingForService("calculationservice", HealthChecks.toHaveAllPortsOpen())
3947
.waitingForService("discovery-service", HealthChecks.toHaveAllPortsOpen())
48+
.waitingForService("userservice", HealthChecks.toRespondOverHttp(8091,
49+
(port) -> port.inFormat("http://localhost:8091")))
4050
.waitingForService("discovery-service", HealthChecks.toRespondOverHttp(8761,
41-
(port) -> port.inFormat("http://localhost:8761")))
51+
(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 endpoint 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 endpoint 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 endpoint 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 endpoint found: " + calculationServiceURL);
81+
82+
// DockerPort userService = docker.containers().container("userservice")
83+
// .port(8091);
84+
// userServiceEndpoint = String.format("http://%s:%s", userService.getIp(),
85+
// userService.getExternalPort());
86+
// LOG.info("User Service Endpoint found: " + userServiceEndpoint);
87+
}
88+
4489
private TestRestTemplate restTemplate = new TestRestTemplate();
4590

4691
private String token;
@@ -83,10 +128,10 @@ public void tripCommandPOSTRequestSuccess() {
83128
HttpEntity<String> request = new HttpEntity<>(body, headers);
84129

85130
//when:
86-
ResponseEntity<String> response = restTemplate.postForEntity("http://localhost:8092/api/trip", request, String.class);
131+
ResponseEntity<String> response = restTemplate.postForEntity(tripCommandURL + "/api/v1/trip", request, String.class);
87132

88133
//then:
89-
assertThat(response.getStatusCodeValue()).isEqualTo(200);
134+
assertThat(response.getStatusCodeValue()).isEqualTo(201);
90135
}
91136

92137
@Test
@@ -96,7 +141,7 @@ public void tripQueryGETRequestSuccess() {
96141
headers.add("Authorization", "Bearer " + token);
97142

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

101146
//then:
102147
assertThat(response.getStatusCodeValue()).isEqualTo(200);

src/test/resources/docker-compose.yml

Lines changed: 23 additions & 10 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
@@ -26,7 +25,6 @@ services:
2625

2726
mysql-server:
2827
image: mysql:5.7
29-
container_name: mysql-server
3028
volumes:
3129
- mysql-data:/var/lib/mysql:rw
3230
restart: always
@@ -39,12 +37,11 @@ services:
3937
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
4038
MYSQL_DATABASE: 'user_service'
4139

42-
microservice--user-service:
40+
userservice:
4341
image: aista/user-service
4442
depends_on:
4543
- discovery-service
4644
- mysql-server
47-
container_name: microservice--user-service
4845
ports:
4946
- '8091:8091'
5047

@@ -63,32 +60,48 @@ services:
6360
- "5672:5672"
6461
- "15672:15672"
6562

66-
trip-management-cmd:
63+
tripmanagementcmd:
6764
image: aista/trip-management-cmd
68-
container_name: trip-management-cmd
6965
environment:
7066
- RABBIT_HOST=rabbitmq
7167
- MONGO_HOST=mongo
7268
ports:
73-
- '8092:8080'
69+
- '8080'
7470
depends_on:
7571
- discovery-service
7672
- rabbitmq
7773
- mongo
7874

79-
trip-management-query:
75+
tripmanagementquery:
8076
image: aista/trip-management-query
81-
container_name: trip-management-query
8277
environment:
8378
- RABBIT_HOST=rabbitmq
8479
- MONGO_HOST=mongo
8580
ports:
86-
- '8093:8080'
81+
- '8080'
8782
depends_on:
8883
- rabbitmq
8984
- mongo
9085
- discovery-service
9186

87+
gmapsadapter:
88+
image: aista/gmaps-adapter
89+
environment:
90+
- EUREKA_SERVER=discovery-service
91+
ports:
92+
- '8080'
93+
depends_on:
94+
- discovery-service
95+
96+
calculationservice:
97+
image: aista/calculation-service
98+
environment:
99+
- EUREKA_SERVER=discovery-service
100+
ports:
101+
- '8080'
102+
depends_on:
103+
- discovery-service
104+
92105
volumes:
93106
mongo:
94107
mysql-data:

0 commit comments

Comments
 (0)