Skip to content

Commit 68bdbf1

Browse files
committed
updated Kotlin tests
1 parent 6a48fbb commit 68bdbf1

File tree

3 files changed

+39
-26
lines changed

3 files changed

+39
-26
lines changed

kotlin/services/location/src/main/java/com/example/location/HelloLocation.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package com.example.location
55

66
import aws.sdk.kotlin.services.location.LocationClient
77
import aws.sdk.kotlin.services.location.model.ListGeofencesRequest
8+
import kotlin.system.exitProcess
89

910
// snippet-start:[location.kotlin.hello.main]
1011
/**
@@ -31,11 +32,11 @@ suspend fun main(args: Array<String>) {
3132
3233
""".trimIndent()
3334

34-
//if (args.size != 1) {
35-
/// println(usage)
36-
// exitProcess(0)
37-
// }
38-
val colletionName = "Collection100" //args[0]
35+
if (args.size != 1) {
36+
println(usage)
37+
exitProcess(0)
38+
}
39+
val colletionName = args[0]
3940
listGeofences(colletionName)
4041
}
4142

@@ -44,15 +45,14 @@ suspend fun main(args: Array<String>) {
4445
*
4546
* @param collectionName the name of the geofence collection
4647
*/
47-
private suspend fun listGeofences(collectionName: String) {
48+
suspend fun listGeofences(collectionName: String) {
4849
val request = ListGeofencesRequest {
4950
this.collectionName = collectionName
5051
}
5152

5253
LocationClient { region = "us-east-1" }.use { client ->
5354
val response = client.listGeofences(request)
5455
val geofences = response.entries
55-
5656
if (geofences.isNullOrEmpty()) {
5757
println("No Geofences found")
5858
} else {

kotlin/services/location/src/main/java/com/example/location/scenario/LocationScenario.kt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import aws.sdk.kotlin.services.location.model.PositionFiltering
3434
import aws.sdk.kotlin.services.location.model.PutGeofenceRequest
3535
import aws.sdk.kotlin.services.location.model.TravelMode
3636
import java.util.Scanner
37+
import kotlin.system.exitProcess
3738

3839
// snippet-start:[location.kotlin.scenario.main]
3940
/**
@@ -47,7 +48,6 @@ https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html
4748
val scanner = Scanner(System.`in`)
4849
val DASHES = String(CharArray(80)).replace("\u0000", "-")
4950
suspend fun main(args: Array<String>) {
50-
5151
val usage = """
5252
5353
Usage: <mapName> <keyName> <collectionName> <geoId> <trackerName> <calculatorName> <deviceId>
@@ -63,18 +63,18 @@ suspend fun main(args: Array<String>) {
6363
6464
""".trimIndent()
6565

66-
// if (args.size != 7) {
67-
// println(usage)
68-
// exitProcess(0)
69-
// }
66+
if (args.size != 7) {
67+
println(usage)
68+
exitProcess(0)
69+
}
7070

71-
val mapName = "AWSMap301"; //args[0]
72-
val keyName = "AWSApiKey301"; //args[1]
73-
val collectionName = "AWSLocationCollection301"; //args[2]
74-
val geoId = "geoId301";//args[3]
75-
val trackerName = "geoTracker301" // args[4]
76-
val calculatorName = "AWSRouteCalc301"; //args[5]
77-
val deviceId = "iPhone-112356"
71+
val mapName = args[0]
72+
val keyName = args[1]
73+
val collectionName = args[2]
74+
val geoId = args[3]
75+
val trackerName = args[4]
76+
val calculatorName = args[5]
77+
val deviceId = args[6]
7878

7979
println(
8080
"""
@@ -328,7 +328,6 @@ suspend fun deleteTracker(trackerName: String) {
328328
LocationClient { region = "us-east-1" }.use { client ->
329329
client.deleteTracker(trackerRequest)
330330
println("The tracker $trackerName was deleted.")
331-
332331
}
333332
}
334333
// snippet-end:[location.kotlin.delete.tracker.main]

kotlin/services/location/src/test/java/LocationTest.kt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
import com.example.location.listGeofences
45
import com.example.location.scenario.calcDistance
56
import com.example.location.scenario.createGeofenceCollection
67
import com.example.location.scenario.createKey
@@ -22,17 +23,20 @@ import kotlinx.coroutines.runBlocking
2223
import org.junit.jupiter.api.Assertions
2324
import org.junit.jupiter.api.MethodOrderer
2425
import org.junit.jupiter.api.Order
25-
import org.junit.jupiter.api.Tag
2626
import org.junit.jupiter.api.Test
2727
import org.junit.jupiter.api.TestInstance
2828
import org.junit.jupiter.api.TestMethodOrder
29+
import org.slf4j.Logger
30+
import org.slf4j.LoggerFactory
2931

3032
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
3133
@TestMethodOrder(MethodOrderer.OrderAnnotation::class)
3234
class LocationTest {
35+
private val logger: Logger = LoggerFactory.getLogger(LocationTest::class.java)
3336
private val mapName = "TestMap"
3437
private val keyName = "TestKey"
3538
private val collectionName = "TestCollection"
39+
private val existingCollectione = "Collection100"
3640
private val geoId = "TestGeo"
3741
private val trackerName = "TestTracker"
3842
private var mapArn = ""
@@ -41,7 +45,6 @@ class LocationTest {
4145
var deviceId = "iPhone-112359" // Use the iPhone's identifier from Swift
4246

4347
@Test
44-
@Tag("IntegrationTest")
4548
@Order(1)
4649
fun testScenario() = runBlocking {
4750
println("===== Starting Full Location Service Scenario Test =====")
@@ -52,15 +55,15 @@ class LocationTest {
5255
.onFailure { it.printStackTrace() }
5356
.getOrThrow()
5457

55-
println("Created Map: $mapArn")
58+
logger.info("Created Map: $mapArn")
5659

5760
// Step 2: Create Key
5861
keyArn = runCatching { createKey(keyName, mapArn) }
5962
.onSuccess { Assertions.assertNotNull(it, "Expected key ARN to be non-null") }
6063
.onFailure { it.printStackTrace() }
6164
.getOrThrow()
6265

63-
println("Created Key: $keyArn")
66+
logger.info("Created Key: $keyArn")
6467

6568
// Step 3: Geofencing
6669
runCatching { createGeofenceCollection(collectionName) }
@@ -130,9 +133,20 @@ class LocationTest {
130133
val cleanupSuccess = cleanupResults.all { it.isSuccess }
131134
Assertions.assertTrue(cleanupSuccess, "Some resources failed to delete")
132135

133-
println("===== Cleanup Completed Successfully =====")
136+
logger.info("===== Cleanup Completed Successfully =====")
134137
}
135138

136-
println("🎉 Test 1 Passed Successfully!")
139+
logger.info("🎉 Test 1 Passed Successfully!")
140+
}
141+
142+
@Test
143+
@Order(2)
144+
fun testHello() = runBlocking {
145+
runCatching { listGeofences(existingCollectione) }
146+
.onSuccess { println("Hello passed") }
147+
.onFailure { it.printStackTrace() }
148+
.getOrThrow()
149+
150+
logger.info("🎉 Test 2 Passed Successfully!")
137151
}
138152
}

0 commit comments

Comments
 (0)