Skip to content

Commit 5adb323

Browse files
committed
updated Kotlin MediaConvert code
1 parent 3f6feba commit 5adb323

File tree

4 files changed

+129
-3
lines changed

4 files changed

+129
-3
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import com.example.comprehend.*;
5+
import com.google.gson.Gson;
6+
import org.junit.jupiter.api.*;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
10+
import software.amazon.awssdk.regions.Region;
11+
import software.amazon.awssdk.services.comprehend.ComprehendClient;
12+
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
13+
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest;
14+
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse;
15+
import java.io.*;
16+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
17+
18+
/**
19+
* To run these integration tests, you must set the required values
20+
* in the config.properties file or AWS Secrets Manager.
21+
*/
22+
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
23+
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
24+
public class AmazonComprehendTest {
25+
private static final Logger logger = LoggerFactory.getLogger(AmazonComprehendTest.class);
26+
private static ComprehendClient comClient;
27+
private static String text = "Amazon.com, Inc. is located in Seattle, WA and was founded July 5th, 1994 by Jeff Bezos, allowing customers to buy everything from books to blenders. Seattle is north of Portland and south of Vancouver, BC. Other notable Seattle - based companies are Starbucks and Boeing";
28+
private static String frText = "Il pleut aujourd'hui à Seattle";
29+
private static String dataAccessRoleArn;
30+
private static String s3Uri;
31+
private static String documentClassifierName;
32+
33+
@BeforeAll
34+
public static void setUp() throws IOException {
35+
comClient = ComprehendClient.builder()
36+
.region(Region.US_EAST_1)
37+
.build();
38+
39+
// Get the values to run these tests from AWS Secrets Manager.
40+
Gson gson = new Gson();
41+
String json = getSecretValues();
42+
SecretValues values = gson.fromJson(json, SecretValues.class);
43+
dataAccessRoleArn = values.getDataAccessRoleArn();
44+
s3Uri = values.getS3Uri();
45+
documentClassifierName = values.getDocumentClassifier();
46+
}
47+
48+
@Test
49+
@Tag("weathertop2")
50+
@Tag("IntegrationTest")
51+
@Order(1)
52+
public void testDetectEntities() {
53+
assertDoesNotThrow(() -> DetectEntities.detectAllEntities(comClient, text));
54+
logger.info("Test 1 passed");
55+
}
56+
57+
@Test
58+
@Tag("weathertop")
59+
@Tag("IntegrationTest")
60+
@Order(2)
61+
public void testDetectKeyPhrases() {
62+
assertDoesNotThrow(() -> DetectKeyPhrases.detectAllKeyPhrases(comClient, text));
63+
logger.info("Test 2 passed");
64+
}
65+
66+
@Test
67+
@Tag("weathertop")
68+
@Tag("IntegrationTest")
69+
@Order(3)
70+
public void testDetectLanguage() {
71+
assertDoesNotThrow(() -> DetectLanguage.detectTheDominantLanguage(comClient, frText));
72+
logger.info("Test 3 passed");
73+
}
74+
75+
@Test
76+
@Tag("weathertop")
77+
@Tag("IntegrationTest")
78+
@Order(4)
79+
public void testDetectSentiment() {
80+
assertDoesNotThrow(() -> DetectSentiment.detectSentiments(comClient, text));
81+
logger.info("Test 4 passed");
82+
}
83+
84+
@Test
85+
@Tag("weathertop")
86+
@Tag("IntegrationTest")
87+
@Order(5)
88+
public void testDetectSyntax() {
89+
assertDoesNotThrow(() -> DetectSyntax.detectAllSyntax(comClient, text));
90+
logger.info("Test 5 passed");
91+
}
92+
93+
private static String getSecretValues() {
94+
SecretsManagerClient secretClient = SecretsManagerClient.builder()
95+
.region(Region.US_EAST_1)
96+
.build();
97+
String secretName = "test/comprehend";
98+
99+
GetSecretValueRequest valueRequest = GetSecretValueRequest.builder()
100+
.secretId(secretName)
101+
.build();
102+
103+
GetSecretValueResponse valueResponse = secretClient.getSecretValue(valueRequest);
104+
return valueResponse.secretString();
105+
}
106+
107+
@Nested
108+
@DisplayName("A class used to get test values from test/comprehend (an AWS Secrets Manager secret)")
109+
class SecretValues {
110+
private String dataAccessRoleArn;
111+
private String s3Uri;
112+
private String documentClassifier;
113+
114+
public String getDataAccessRoleArn() {
115+
return dataAccessRoleArn;
116+
}
117+
118+
public String getS3Uri() {
119+
return s3Uri;
120+
}
121+
122+
public String getDocumentClassifier() {
123+
return documentClassifier;
124+
}
125+
}
126+
}

kotlin/services/mediaconvert/src/main/kotlin/com/kotlin/mediaconvert/CreateJob.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ suspend fun main(args: Array<String>) {
5757

5858
val mcRoleARN = args[0]
5959
val fileInput = args[1]
60-
val mcClient = MediaConvertClient { region = "us-west-2" }
60+
val mcClient = MediaConvertClient.fromEnvironment { region = "us-west-2" }
6161
val id = createMediaJob(mcClient, mcRoleARN, fileInput)
6262
println("MediaConvert job $id was successfully created!")
6363
}

kotlin/services/mediaconvert/src/main/kotlin/com/kotlin/mediaconvert/GetJob.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ suspend fun main(args: Array<String>) {
3131
}
3232

3333
val jobId = args[0]
34-
val mcClient = MediaConvertClient { region = "us-west-2" }
34+
val mcClient = MediaConvertClient.fromEnvironment { region = "us-west-2" }
3535
getSpecificJob(mcClient, jobId)
3636
}
3737

kotlin/services/mediaconvert/src/main/kotlin/com/kotlin/mediaconvert/ListJobs.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ For more information, see the following documentation topic:
2121
https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html
2222
*/
2323
suspend fun main() {
24-
val mcClient = MediaConvertClient { region = "us-west-2" }
24+
val mcClient = MediaConvertClient.fromEnvironment { region = "us-west-2" }
2525
listCompleteJobs(mcClient)
2626
}
2727

0 commit comments

Comments
 (0)