Skip to content

Commit ccae756

Browse files
committed
updated Location integration tests
1 parent cb3c32b commit ccae756

File tree

1 file changed

+71
-17
lines changed

1 file changed

+71
-17
lines changed

javav2/example_code/location/src/test/java/LocationTest.java

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,29 @@
99
import org.junit.jupiter.api.Test;
1010
import org.junit.jupiter.api.TestInstance;
1111
import org.junit.jupiter.api.TestMethodOrder;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
14+
import software.amazon.awssdk.services.location.model.BatchUpdateDevicePositionResponse;
15+
import software.amazon.awssdk.services.location.model.CalculateRouteResponse;
16+
import software.amazon.awssdk.services.location.model.CreateGeofenceCollectionResponse;
17+
import software.amazon.awssdk.services.location.model.CreateRouteCalculatorResponse;
18+
import software.amazon.awssdk.services.location.model.GetDevicePositionRequest;
19+
import software.amazon.awssdk.services.location.model.GetDevicePositionResponse;
20+
import software.amazon.awssdk.services.location.model.PutGeofenceResponse;
21+
1222
import java.util.concurrent.CompletableFuture;
1323
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
24+
import static org.junit.jupiter.api.Assertions.assertFalse;
1425
import static org.junit.jupiter.api.Assertions.assertNotNull;
26+
import static org.junit.jupiter.api.Assertions.assertTrue;
1527

1628
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
1729
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
1830
public class LocationTest {
1931

2032
private static final LocationActions locationActions = new LocationActions();
2133

34+
private static final Logger logger = LoggerFactory.getLogger(LocationTest.class);
2235
private static final String mapName = "TestMap";
2336

2437
private static final String keyName = "TestKey";
@@ -37,102 +50,143 @@ public void testCreateMap() {
3750
assertDoesNotThrow(() -> {
3851
mapArn = locationActions.createMap(mapName).join();
3952
assertNotNull(mapArn);
53+
logger.info("Test 1 passed");
4054
});
4155
}
4256

4357
@Test
4458
@Tag("IntegrationTest")
4559
@Order(2)
4660
public void testCreateKey() {
61+
CompletableFuture<String> future = locationActions.createKey(keyName, mapArn);
4762
assertDoesNotThrow(() -> {
48-
locationActions.createKey(keyName, mapArn).join();
63+
String keyArn = future.join();
64+
assertNotNull(keyArn, "Expected key ARN to be non-null");
65+
assertFalse(keyArn.isEmpty(), "Expected key ARN to be non-empty");
66+
logger.info("Test 2 passed");
4967
});
5068
}
5169

5270
@Test
5371
@Tag("IntegrationTest")
5472
@Order(3)
5573
public void testCreateGeofenceCollection() {
74+
CompletableFuture<CreateGeofenceCollectionResponse> future = locationActions.createGeofenceCollection(collectionName);
5675
assertDoesNotThrow(() -> {
57-
locationActions.createGeofenceCollection(collectionName).join();
76+
CreateGeofenceCollectionResponse response = future.join();
77+
assertNotNull(response, "Expected response to be non-null");
78+
assertNotNull(response.collectionArn(), "Expected collection ARN to be non-null");
79+
assertFalse(response.collectionArn().isEmpty(), "Expected collection ARN to be non-empty");
80+
logger.info("Test 3 passed");
5881
});
5982
}
6083

6184
@Test
6285
@Tag("IntegrationTest")
6386
@Order(4)
6487
public void testPutGeoCollection() {
88+
CompletableFuture<PutGeofenceResponse> future = locationActions.putGeofence(collectionName, geoId);
6589
assertDoesNotThrow(() -> {
66-
locationActions.putGeofence(collectionName, geoId).join();
90+
PutGeofenceResponse response = future.join();
91+
assertNotNull(response, "Expected response to be non-null");
92+
logger.info("Test 4 passed");
6793
});
6894
}
6995

7096
@Test
7197
@Tag("IntegrationTest")
72-
@Order(6)
98+
@Order(5)
7399
public void testHelloService() {
74100
assertDoesNotThrow(() -> {
75101
CompletableFuture<Void> future = HelloLocation.listGeofences(collectionName);
76102
future.join(); // Wait for the asynchronous operation to complete
103+
logger.info("Test 5 passed");
77104
});
78105
}
79106

80107
@Test
81108
@Tag("IntegrationTest")
82-
@Order(7)
109+
@Order(6)
83110
public void testCreateTracker() {
111+
CompletableFuture<String> future = locationActions.createTracker(trackerName);
84112
assertDoesNotThrow(() -> {
85-
locationActions.createTracker(trackerName).join();
113+
String trackerArn = future.join();
114+
assertNotNull(trackerArn, "Expected tracker ARN to be non-null");
115+
assertFalse(trackerArn.isEmpty(), "Expected tracker ARN to be non-empty");
116+
logger.info("Test 6 passed");
86117
});
87118
}
88119

89120
@Test
90121
@Tag("IntegrationTest")
91-
@Order(8)
122+
@Order(7)
92123
public void testUpdateDevice() {
124+
CompletableFuture<BatchUpdateDevicePositionResponse> future = locationActions.updateDevicePosition(trackerName, deviceId);
93125
assertDoesNotThrow(() -> {
94-
locationActions.updateDevicePosition(trackerName, deviceId).join();
126+
BatchUpdateDevicePositionResponse response = future.join();
127+
assertNotNull(response, "Expected response to be non-null");
128+
assertTrue(response.errors().isEmpty(), "Expected no errors while updating device position");
129+
logger.info("Test 7 passed");
95130
});
96131
}
97132

98133
@Test
99134
@Tag("IntegrationTest")
100-
@Order(9)
135+
@Order(8)
101136
public void testGetDevicePosition() {
137+
CompletableFuture<GetDevicePositionResponse> future = locationActions.getDevicePosition(trackerName, deviceId);
102138
assertDoesNotThrow(() -> {
103-
locationActions.getDevicePosition(trackerName, deviceId).join();
139+
GetDevicePositionResponse response = future.join();
140+
assertNotNull(response, "Expected response to be non-null");
141+
assertNotNull(response.position(), "Expected position data to be non-null");
142+
assertFalse(response.position().isEmpty(), "Expected position data to be non-empty");
143+
assertNotNull(response.receivedTime(), "Expected received time to be non-null");
144+
logger.info("Test 8 passed");
104145
});
105146
}
106147

107148
@Test
108149
@Tag("IntegrationTest")
109-
@Order(10)
150+
@Order(9)
110151
public void testCreateRouteCalculator() {
152+
CompletableFuture<CreateRouteCalculatorResponse> future = locationActions.createRouteCalculator(calculatorName);
111153
assertDoesNotThrow(() -> {
112-
locationActions.createRouteCalculator(calculatorName).join();
154+
CreateRouteCalculatorResponse response = future.join();
155+
assertNotNull(response, "Expected response to be non-null");
156+
assertNotNull(response.calculatorArn(), "Expected calculator ARN to be non-null");
157+
assertFalse(response.calculatorArn().isEmpty(), "Expected calculator ARN to be non-empty");
158+
logger.info("Test 9 passed");
113159
});
114160
}
115161

116162
@Test
117163
@Tag("IntegrationTest")
118-
@Order(11)
119-
public void testCreateRDistance() {
164+
@Order(10)
165+
public void testCalcDistance() {
166+
CompletableFuture<CalculateRouteResponse> future = locationActions.calcDistanceAsync(calculatorName);
120167
assertDoesNotThrow(() -> {
121-
locationActions.calcDistanceAsync(calculatorName).join();
168+
CalculateRouteResponse response = future.join();
169+
assertNotNull(response);
170+
assertNotNull(response.summary());
171+
double distance = response.summary().distance();
172+
double duration = response.summary().durationSeconds();
173+
assertTrue(distance > 0, "Expected distance to be greater than 0");
174+
assertTrue(duration > 0, "Expected duration to be greater than 0");
175+
logger.info("Test 10 passed");
122176
});
123177
}
124178

125179
@Test
126180
@Tag("IntegrationTest")
127-
@Order(12)
181+
@Order(11)
128182
public void testDeleteLocationResources() {
129183
assertDoesNotThrow(() -> {
130184
locationActions.deleteMap(mapName).join();
131185
locationActions.deleteKey(keyName).join();
132186
locationActions.deleteGeofenceCollectionAsync(collectionName).join();
133187
locationActions.deleteTracker(trackerName).join();
134188
locationActions.deleteRouteCalculator(calculatorName).join();
189+
logger.info("Test 11 passed");
135190
});
136191
}
137-
138192
}

0 commit comments

Comments
 (0)