Skip to content

Commit 97079fc

Browse files
committed
Updated Integration Tests to include connection test between command and query
1 parent 6976435 commit 97079fc

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

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

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public class EdgeServiceIntegrationTests {
4040
public static DockerComposeRule docker = DockerComposeRule.builder().pullOnStartup(true)
4141
.file("src/test/resources/docker-compose.yml")
4242
.waitingForService("userservice", HealthChecks.toHaveAllPortsOpen())
43+
.waitingForService("mongo", HealthChecks.toHaveAllPortsOpen())
44+
.waitingForService("rabbitmq", HealthChecks.toHaveAllPortsOpen())
4345
.waitingForService("tripmanagementcmd", HealthChecks.toHaveAllPortsOpen())
4446
.waitingForService("tripmanagementquery", HealthChecks.toHaveAllPortsOpen())
4547
.waitingForService("gmapsadapter", HealthChecks.toHaveAllPortsOpen())
@@ -57,25 +59,25 @@ public static void initialize() {
5759
.port(8080);
5860
tripCommandURL = String.format("http://%s:%s", tripManagementCommand.getIp(),
5961
tripManagementCommand.getExternalPort());
60-
LOG.info("Trip Command endpoint found: " + tripCommandURL);
62+
LOG.info("Trip Command url found: " + tripCommandURL);
6163

6264
DockerPort tripManagementQuery = docker.containers().container("tripmanagementquery")
6365
.port(8080);
6466
tripQueryURL = String.format("http://%s:%s", tripManagementQuery.getIp(),
6567
tripManagementQuery.getExternalPort());
66-
LOG.info("Trip Query endpoint found: " + tripQueryURL);
68+
LOG.info("Trip Query url found: " + tripQueryURL);
6769

6870
DockerPort gmapsAdapter = docker.containers().container("gmapsadapter")
6971
.port(8080);
7072
gmapsAdapterURL = String.format("http://%s:%s", gmapsAdapter.getIp(),
7173
gmapsAdapter.getExternalPort());
72-
LOG.info("Gmaps Adapter endpoint found: " + gmapsAdapterURL);
74+
LOG.info("Gmaps Adapter url found: " + gmapsAdapterURL);
7375

7476
DockerPort calculationService = docker.containers().container("calculationservice")
7577
.port(8080);
7678
calculationServiceURL = String.format("http://%s:%s", calculationService.getIp(),
7779
calculationService.getExternalPort());
78-
LOG.info("Calculation Service endpoint found: " + calculationServiceURL);
80+
LOG.info("Calculation Service url found: " + calculationServiceURL);
7981

8082
DockerPort userService = docker.containers().container("userservice")
8183
.port(8080);
@@ -85,17 +87,16 @@ public static void initialize() {
8587
(port) -> port.inFormat(userServiceURL)).succeeded()) {
8688
LOG.info("Waiting for user service to respond over HTTP");
8789
}
88-
LOG.info("User Service endpoint found: " + userServiceURL);
90+
LOG.info("User Service url found: " + userServiceURL);
8991
}
9092

9193
private TestRestTemplate restTemplate = new TestRestTemplate();
9294

9395
private String token;
96+
private String tripId;
9497

9598
@Before
9699
public void setUp() throws JSONException {
97-
98-
99100
String plainCreds = "eagleeye:thisissecret";
100101
byte[] plainCredsBytes = plainCreds.getBytes();
101102
byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes);
@@ -121,15 +122,16 @@ public void setUp() throws JSONException {
121122
token = json.getString("access_token");
122123
}
123124

125+
124126
@Test
125127
public void tripCommandPOSTRequestSuccess() {
126128
//given:
127129
HttpHeaders headers = new HttpHeaders();
128130
headers.add("Authorization", "Bearer " + token);
129131
headers.add("Content-Type", "application/json");
130132

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

135137
//when:
@@ -141,10 +143,34 @@ public void tripCommandPOSTRequestSuccess() {
141143
}
142144

143145
@Test
144-
public void tripQueryGETRequestSuccess() {
146+
public void tripQueryGETSpecificTripRequestSuccess() throws JSONException {
145147
//given:
146148
HttpHeaders headers = new HttpHeaders();
147149
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);
163+
164+
//then:
165+
assertThat(response.getStatusCodeValue()).isEqualTo(200);
166+
}
167+
168+
@Test
169+
public void tripQueryGETAllTripsRequestSuccess() {
170+
//given:
171+
HttpHeaders headers = new HttpHeaders();
172+
headers.add("Authorization", "Bearer " + token);
173+
headers.add("Content-Type", "application/json");
148174

149175
//when:
150176
ResponseEntity<String> response = restTemplate.getForEntity(tripQueryURL + "/api/v1/trips", String.class);

0 commit comments

Comments
 (0)