Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin Update Kotlin Build files #6069

Merged
merged 7 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ rust_dev_preview
.vectors
# .snippets are created temporarily as build artifacts
.snippets
# Ignore build-related files and directories in kotlin/services/
kotlin/services/**/build/
kotlin/services/**/gradle/
kotlin/services/**/gradlew
kotlin/services/**/gradlew.bat
27 changes: 21 additions & 6 deletions kotlin/services/apigateway/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.7.10"
kotlin("jvm") version "1.9.0"
application
}

group = "me.scmacdon"
version = "1.0-SNAPSHOT"

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

buildscript {
repositories {
maven("https://plugins.gradle.org/m2/")
Expand All @@ -19,18 +24,28 @@ buildscript {

repositories {
mavenCentral()
jcenter()
}
apply(plugin = "org.jlleitschuh.gradle.ktlint")
dependencies {
implementation("aws.sdk.kotlin:apigateway:1.0.0")
implementation("aws.sdk.kotlin:secretsmanager:1.0.0")
implementation("aws.sdk.kotlin:apigateway:1.0.30")
implementation("aws.sdk.kotlin:secretsmanager:1.0.30")
implementation("aws.smithy.kotlin:http-client-engine-okhttp:0.30.0")
implementation("aws.smithy.kotlin:http-client-engine-crt:0.30.0")
implementation("com.google.code.gson:gson:2.10")
testImplementation("org.junit.jupiter:junit-jupiter:5.9.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
implementation("com.fasterxml.jackson.core:jackson-databind:2.14.2")
implementation("com.google.code.gson:gson:2.10")
}
tasks.withType<KotlinCompile>() {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.jvmTarget = "17"
}
tasks.test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}

// Define the test source set
testClassesDirs += files("build/classes/kotlin/test")
classpath += files("build/classes/kotlin/main", "build/resources/main")
}
111 changes: 111 additions & 0 deletions kotlin/services/apigateway/src/test/kotlin/APIGatewayTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import aws.sdk.kotlin.runtime.auth.credentials.EnvironmentCredentialsProvider
import aws.sdk.kotlin.services.apigateway.ApiGatewayClient
import aws.sdk.kotlin.services.secretsmanager.SecretsManagerClient
import aws.sdk.kotlin.services.secretsmanager.model.GetSecretValueRequest
import com.google.gson.Gson
import com.kotlin.gateway.createAPI
import com.kotlin.gateway.deleteAPI
import com.kotlin.gateway.getAllDeployments
import com.kotlin.gateway.getAllStages
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Order
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.TestMethodOrder
import java.util.Random

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(OrderAnnotation::class)
class APIGatewayTest {
lateinit var apiGatewayClient: ApiGatewayClient
private var restApiId = ""
private var httpMethod = ""
private var restApiName = ""
private var stageName = ""
private var newApiId = ""

@BeforeAll
fun setup() = runBlocking {
apiGatewayClient = ApiGatewayClient { region = "us-east-1" }
// Get values from AWS Secrets Manager.
val random = Random()
val randomNum = random.nextInt(10000 - 1 + 1) + 1
val gson = Gson()
val json: String = getSecretValues()
val values: SecretValues = gson.fromJson(json, SecretValues::class.java)
restApiId = values.restApiId.toString()
httpMethod = values.httpMethod.toString()
restApiName = values.restApiName.toString() + randomNum
stageName = values.stageName.toString()

/*
val input: InputStream = this.javaClass.getClassLoader().getResourceAsStream("config.properties")
val prop = Properties()

// load the properties file.
prop.load(input)

// Populate the data members required for all tests
restApiId = prop.getProperty("restApiId")
resourceId = prop.getProperty("resourceId")
httpMethod = prop.getProperty("httpMethod")
restApiName = prop.getProperty("restApiName")
stageName = prop.getProperty("stageName")
*/
}

@Test
@Order(1)
fun createRestApiTest() = runBlocking {
newApiId = createAPI(restApiId).toString()
println("Test 2 passed")
}

@Test
@Order(2)
fun getDeploymentsTest() = runBlocking {
getAllDeployments(newApiId)
println("Test 4 passed")
}

@Test
@Order(3)
fun getAllStagesTest() = runBlocking {
getAllStages(newApiId)
println("Test 5 passed")
}

@Test
@Order(4)
fun DeleteRestApi() = runBlocking {
deleteAPI(newApiId)
println("Test 6 passed")
}

private suspend fun getSecretValues(): String {
val secretName = "test/apigateway"
val valueRequest = GetSecretValueRequest {
secretId = secretName
}
SecretsManagerClient { region = "us-east-1"; credentialsProvider = EnvironmentCredentialsProvider() }.use { secretClient ->
val valueResponse = secretClient.getSecretValue(valueRequest)
return valueResponse.secretString.toString()
}
}

@Nested
@DisplayName("A class used to get test values from test/apigateway (an AWS Secrets Manager secret)")
internal class SecretValues {
val restApiId: String? = null
val restApiName: String? = null
val httpMethod: String? = null
val stageName: String? = null
}
}
8 changes: 4 additions & 4 deletions kotlin/services/appsync/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ repositories {
}
apply(plugin = "org.jlleitschuh.gradle.ktlint")
dependencies {
implementation("aws.sdk.kotlin:appsync:1.0.0")
implementation("aws.sdk.kotlin:sts:1.0.0")
implementation("aws.sdk.kotlin:s3:1.0.0")
implementation("aws.sdk.kotlin:secretsmanager:1.0.0")
implementation("aws.sdk.kotlin:appsync:1.0.30")
implementation("aws.sdk.kotlin:sts:1.0.30")
implementation("aws.sdk.kotlin:s3:1.0.30")
implementation("aws.sdk.kotlin:secretsmanager:1.0.30")
implementation("aws.smithy.kotlin:http-client-engine-okhttp:0.30.0")
implementation("aws.smithy.kotlin:http-client-engine-crt:0.30.0")
implementation("com.google.code.gson:gson:2.10")
Expand Down
83 changes: 53 additions & 30 deletions kotlin/services/appsync/src/test/kotlin/AppSyncTest.kt
Original file line number Diff line number Diff line change
@@ -1,106 +1,129 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import aws.sdk.kotlin.runtime.auth.credentials.EnvironmentCredentialsProvider
import aws.sdk.kotlin.services.secretsmanager.SecretsManagerClient
import aws.sdk.kotlin.services.secretsmanager.model.GetSecretValueRequest
import com.example.appsync.createDS
import com.example.appsync.createKey
import com.example.appsync.deleteDS
import com.example.appsync.deleteKey
import com.example.appsync.getDS
import com.example.appsync.getKeys
import com.google.gson.Gson
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Order
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.TestMethodOrder
import java.io.InputStream
import java.util.Properties

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(OrderAnnotation::class)
class AppSyncTest {

private var apiId = ""
private var dsName = ""
private var dsRole = ""
private var tableName = ""
private var keyId = "" // gets dynamically set in a test.
private var dsARN = "" // gets dynamically set in a test.
private var keyId = ""

@BeforeAll
fun setup() {
fun setup() = runBlocking {
// Get test values from AWS Secrets Manager.
val gson = Gson()
val json = getSecretValues()
val values = gson.fromJson(json, SecretValues::class.java)
apiId = values.apiId.toString()
dsName = values.dsName.toString()
dsRole = values.dsRole.toString()
tableName = values.tableName.toString()

// Uncomment this code block if you prefer using a config.properties file to retrieve AWS values required for these tests.
/*
val input: InputStream = this.javaClass.getClassLoader().getResourceAsStream("config.properties")
val prop = Properties()
prop.load(input)
apiId = prop.getProperty("apiId")
dsName = prop.getProperty("dsName")
dsRole = prop.getProperty("dsRole")
tableName = prop.getProperty("tableName")
*/
}

@Test
@Order(1)
fun whenInitializingAWSService_thenNotNull() = runBlocking {
assertTrue(!apiId.isEmpty())
assertTrue(!dsName.isEmpty())
assertTrue(!dsRole.isEmpty())
assertTrue(!tableName.isEmpty())
println("Test 1 passed")
}

@Test
@Order(2)
fun CreateApiKey() = runBlocking {
keyId = createKey(apiId).toString()
assertTrue(!keyId.isEmpty())
println("Test 2 passed")
println("Test 1 passed")
}

@Test
@Order(3)
@Order(2)
fun CreateDataSource() = runBlocking {
val dsARN = createDS(dsName, dsRole, apiId, tableName)
if (dsARN != null) {
assertTrue(!dsARN.isEmpty())
assertTrue(dsARN.isNotEmpty())
}
println("Test 3 passed")
println("Test 2 passed")
}

@Test
@Order(4)
@Order(3)
fun GetDataSource() = runBlocking {
getDS(apiId, dsName)
println("Test 4 passed")
println("Test 3 passed")
}

@Test
@Order(5)
@Order(4)
fun ListGraphqlApis() = runBlocking {
getKeys(apiId)
println("Test 5 passed")
println("Test 4 passed")
}

@Test
@Order(6)
@Order(5)
fun ListApiKeys() = runBlocking {
getKeys(apiId)
println("Test 6 passed")
println("Test 5 passed")
}

@Test
@Order(7)
@Order(6)
fun DeleteDataSource() = runBlocking {
deleteDS(apiId, dsName)
println("Test 7 passed")
println("Test 6 passed")
}

@Test
@Order(8)
@Order(7)
fun DeleteApiKey() = runBlocking {
deleteKey(keyId, apiId)
println("Test 8 passed")
println("Test 7 passed")
}

private suspend fun getSecretValues(): String {
val secretName = "test/appsync"
val valueRequest = GetSecretValueRequest {
secretId = secretName
}
SecretsManagerClient { region = "us-east-1"; credentialsProvider = EnvironmentCredentialsProvider() }.use { secretClient ->
val valueResponse = secretClient.getSecretValue(valueRequest)
return valueResponse.secretString.toString()
}
}

@Nested
@DisplayName("A class used to get test values from test/appsync (an AWS Secrets Manager secret)")
internal class SecretValues {
val apiId: String? = null
val dsName: String? = null
val dsRole: String? = null
val tableName: String? = null
}
}
4 changes: 2 additions & 2 deletions kotlin/services/athena/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ repositories {
}
apply(plugin = "org.jlleitschuh.gradle.ktlint")
dependencies {
implementation("aws.sdk.kotlin:athena:1.0.0")
implementation("aws.sdk.kotlin:secretsmanager:1.0.0")
implementation("aws.sdk.kotlin:athena:1.0.30")
implementation("aws.sdk.kotlin:secretsmanager:1.0.30")
implementation("aws.smithy.kotlin:http-client-engine-okhttp:0.30.0")
implementation("aws.smithy.kotlin:http-client-engine-crt:0.30.0")
implementation("com.google.code.gson:gson:2.10")
Expand Down
Loading
Loading