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 Updated Gradle Build files and tests #6098

Merged
merged 6 commits into from
Feb 9, 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
6 changes: 3 additions & 3 deletions kotlin/services/ecs/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ buildscript {
maven("https://plugins.gradle.org/m2/")
}
dependencies {
classpath("org.jlleitschuh.gradle:ktlint-gradle:10.3.0")
classpath("org.jlleitschuh.gradle:ktlint-gradle:11.3.1")
}
}

Expand All @@ -27,8 +27,8 @@ repositories {
}
apply(plugin = "org.jlleitschuh.gradle.ktlint")
dependencies {
implementation("aws.sdk.kotlin:ecs:1.0.0")
implementation("aws.sdk.kotlin:secretsmanager:1.0.0")
implementation("aws.sdk.kotlin:ecs: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")
testImplementation("org.junit.jupiter:junit-jupiter:5.9.0")
Expand Down
140 changes: 140 additions & 0 deletions kotlin/services/ecs/src/test/kotlin/ESCTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// 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.google.gson.Gson
import com.kotlin.ecs.createGivenCluster
import com.kotlin.ecs.createNewService
import com.kotlin.ecs.deleteSpecificService
import com.kotlin.ecs.descCluster
import com.kotlin.ecs.getAllTasks
import com.kotlin.ecs.listAllClusters
import com.kotlin.ecs.updateSpecificService
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.UUID

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(OrderAnnotation::class)
class ESCTest {
var clusterName = ""
var clusterARN = ""
var securityGroups: String = ""
var taskId: String = ""
var subnet: String = ""
var serviceName: String = ""
var serviceArn: String = ""
var taskDefinition: String = ""
var clusterArn: String = "arn:aws:ecs:us-east-1:814548047983:cluster/ScottCluste11"

@BeforeAll
fun setup() = runBlocking {
// Get the values to run these tests from AWS Secrets Manager.
val gson = Gson()
val json: String = getSecretValues()
val values = gson.fromJson(json, SecretValues::class.java)
clusterName = values.clusterName.toString() + UUID.randomUUID()
taskId = values.taskId.toString()
subnet = values.subnet.toString()
securityGroups = values.securityGroups.toString()
serviceName = values.serviceName.toString() + UUID.randomUUID()
taskDefinition = values.taskDefinition.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()

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

// Populate the data members required for all tests
// clusterName = prop.getProperty("clusterName")
// taskId = prop.getProperty("taskId")
// subnet = prop.getProperty("subnet")
// securityGroups = prop.getProperty("securityGroups")
// serviceName = prop.getProperty("serviceName")
// taskDefinition = prop.getProperty("taskDefinition")
}

@Test
@Order(1)
fun createClusterTest() = runBlocking {
clusterARN = createGivenCluster(clusterName).toString()
println("Test 1 passed")
}

@Test
@Order(2)
fun createServiceTest() = runBlocking {
serviceArn = createNewService(clusterArn, serviceName, securityGroups, subnet, taskDefinition).toString()
println("Test 2 passed")
}

@Test
@Order(3)
fun listClustersTest() = runBlocking {
listAllClusters()
println("Test 3 passed")
}

@Test
@Order(4)
fun describeClustersTest() = runBlocking {
descCluster(clusterArn)
println("Test 4 passed")
}

@Test
@Order(5)
fun listTaskDefinitionsTest() = runBlocking {
getAllTasks(clusterArn, taskId)
println("Test 5 passed")
}

@Test
@Order(6)
fun updateServiceTest() = runBlocking {
updateSpecificService(clusterArn, serviceArn)
println("Test 6 passed")
}

@Test
@Order(7)
fun deleteServiceTest() = runBlocking {
deleteSpecificService(clusterArn, serviceArn)
println("Test 7 passed")
}

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

@Nested
@DisplayName("A class used to get test values from test/ecs (an AWS Secrets Manager secret)")
internal class SecretValues {
val clusterName: String? = null
val securityGroups: String? = null
val subnet: String? = null
val taskId: String? = null
val serviceName: String? = null
val taskDefinition: String? = null
}
}
6 changes: 3 additions & 3 deletions kotlin/services/elasticbeanstalk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ buildscript {
maven("https://plugins.gradle.org/m2/")
}
dependencies {
classpath("org.jlleitschuh.gradle:ktlint-gradle:10.3.0")
classpath("org.jlleitschuh.gradle:ktlint-gradle:11.3.1")
}
}

Expand All @@ -28,8 +28,8 @@ repositories {

apply(plugin = "org.jlleitschuh.gradle.ktlint")
dependencies {
implementation("aws.sdk.kotlin:elasticbeanstalk:1.0.0")
implementation("aws.sdk.kotlin:secretsmanager:1.0.0")
implementation("aws.sdk.kotlin:elasticbeanstalk: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")
testImplementation("org.junit.jupiter:junit-jupiter:5.9.2")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,47 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import aws.sdk.kotlin.services.elasticbeanstalk.ElasticBeanstalkClient
import com.aws.example.*
import com.aws.example.createApp
import com.aws.example.createEBEnvironment
import com.aws.example.deleteApp
import com.aws.example.describeApps
import com.aws.example.describeEnv
import com.aws.example.getOptions
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.*
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation
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.IOException
import java.net.URISyntaxException
import java.util.*
import java.util.Random
import java.util.concurrent.TimeUnit

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

lateinit var beanstalkClient: ElasticBeanstalkClient
var appName: String = ""
var envName: String = ""
var appName: String = "TestApp"
var envName: String = "TestEnv"
var appArn: String = ""
var envArn: String = ""

@BeforeAll
@Throws(IOException::class, URISyntaxException::class)
fun setUp() {
beanstalkClient = ElasticBeanstalkClient{ region = "us-east-1" }

try {
ElasticBeanstalkTest::class.java.classLoader.getResourceAsStream("config.properties").use { input ->
val prop = Properties()
if (input == null) {
println("Sorry, unable to find config.properties")
return
}

prop.load(input)
appName = prop.getProperty("appName")
envName = prop.getProperty("envName")
}
} catch (ex: IOException) {
ex.printStackTrace()
}
val random = Random()
val randomNum = random.nextInt(10000 - 1 + 1) + 1
appName = appName + randomNum
envName = envName + randomNum
}

@Test
@Order(1)
fun whenInitializingAWSService_thenNotNull() {
Assertions.assertNotNull(beanstalkClient)
Assertions.assertNotNull(appName)
println("Test 1 passed")
}

Expand All @@ -62,7 +56,7 @@ class ElasticBeanstalkTest {
@Test
@Order(3)
fun CreateEnvironment() = runBlocking {
envArn = createEBEnvironment( envName, appName)
envArn = createEBEnvironment(envName, appName)
assertTrue(!envArn.isEmpty())
println("Test 3 passed")
}
Expand Down
6 changes: 3 additions & 3 deletions kotlin/services/emr/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ buildscript {
maven("https://plugins.gradle.org/m2/")
}
dependencies {
classpath("org.jlleitschuh.gradle:ktlint-gradle:10.3.0")
classpath("org.jlleitschuh.gradle:ktlint-gradle:11.3.1")
}
}

Expand All @@ -27,8 +27,8 @@ repositories {
}
apply(plugin = "org.jlleitschuh.gradle.ktlint")
dependencies {
implementation("aws.sdk.kotlin:emr:1.0.0")
implementation("aws.sdk.kotlin:secretsmanager:1.0.0")
implementation("aws.sdk.kotlin:emr: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
99 changes: 99 additions & 0 deletions kotlin/services/emr/src/test/kotlin/EMRTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// 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.google.gson.Gson
import com.kotlin.emr.listAllClusters
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.io.IOException

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(OrderAnnotation::class)
class EMRTest {
private var jar = ""
private var myClass = ""
private var keys = ""
private var logUri = ""
private var name = ""
private var jobFlowId = ""
private var existingClusterId = ""

@BeforeAll
@Throws(IOException::class)
fun setUp() = runBlocking {
// Get the values to run these tests from AWS Secrets Manager.
val gson = Gson()
val json: String = getSecretValues()
val values = gson.fromJson(json, SecretValues::class.java)
jar = values.jar.toString()
myClass = values.myClass.toString()
keys = values.keys.toString()
logUri = values.logUri.toString()
name = values.name.toString()
existingClusterId = values.existingClusterId.toString()

/*
try {
EMRTest::class.java.classLoader.getResourceAsStream("config.properties").use { input ->
val prop = Properties()
if (input == null) {
println("Sorry, unable to find config.properties")
return
}

// load a properties file from class path, inside static method
prop.load(input)

// Populate the data members required for all tests
jar = prop.getProperty("jar")
myClass = prop.getProperty("myClass")
keys = prop.getProperty("keys")
logUri = prop.getProperty("logUri")
name = prop.getProperty("name")
existingClusterId = prop.getProperty("existingClusterId")
}
} catch (ex: IOException) {
ex.printStackTrace()
}
*/
}

@Test
@Order(1)
fun listClustersTest() = runBlocking {
listAllClusters()
println("Test 3 passed")
}

private suspend fun getSecretValues(): String {
val secretName = "text/emr"
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/emr (an AWS Secrets Manager secret)")
internal class SecretValues {
val existingClusterId: String? = null
val jar: String? = null
val myClass: String? = null
val keys: String? = null
val name: String? = null
val logUri: String? = null
}
}
Loading
Loading