Skip to content

Commit 7fa185f

Browse files
authored
Create AWSAthenaServiceIntegrationTest.java
1 parent 63bec3a commit 7fa185f

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import aws.example.athena.*;
2+
import org.junit.jupiter.api.*;
3+
import software.amazon.awssdk.regions.Region;
4+
import software.amazon.awssdk.services.athena.AthenaClient;
5+
import software.amazon.awssdk.services.athena.model.AthenaException;
6+
import java.io.*;
7+
import java.util.Properties;
8+
9+
import static org.junit.jupiter.api.Assertions.*;
10+
11+
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
12+
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
13+
public class AWSAthenaServiceIntegrationTest {
14+
15+
private static AthenaClient athenaClient;
16+
private static String nameQuery;
17+
18+
@BeforeAll
19+
public static void setUp() throws IOException {
20+
athenaClient = AthenaClient.builder()
21+
.region(Region.US_WEST_2)
22+
.build();
23+
24+
try (InputStream input = AWSAthenaServiceIntegrationTest.class.getClassLoader().getResourceAsStream("config.properties")) {
25+
26+
Properties prop = new Properties();
27+
28+
if (input == null) {
29+
System.out.println("Sorry, unable to find config.properties");
30+
return;
31+
}
32+
33+
//load a properties file from class path, inside static method
34+
prop.load(input);
35+
36+
// Populate the data members required for all tests
37+
nameQuery = prop.getProperty("nameQuery");
38+
39+
40+
} catch (IOException ex) {
41+
ex.printStackTrace();
42+
}
43+
}
44+
@Test
45+
@Order(1)
46+
public void whenInitializingAWSAthenaService_thenNotNull() {
47+
assertNotNull(athenaClient);
48+
System.out.println("Test 1 passed");
49+
}
50+
51+
@Test
52+
@Order(2)
53+
public void CreateNamedQueryExample() {
54+
55+
CreateNamedQueryExample.createNamedQuery(athenaClient, nameQuery);
56+
System.out.println("Test 2 passed");
57+
}
58+
59+
@Test
60+
@Order(3)
61+
public void ListNamedQueryExample() {
62+
63+
ListNamedQueryExample.listNamedQueries(athenaClient);
64+
System.out.println("Test 3 passed");
65+
}
66+
67+
@Test
68+
@Order(4)
69+
public void ListQueryExecutionsExample() {
70+
71+
ListQueryExecutionsExample.listQueryIds(athenaClient);
72+
System.out.println("Test 4 passed");
73+
}
74+
75+
@Test
76+
@Order(5)
77+
public void DeleteNamedQueryExample()
78+
{
79+
String sampleNamedQueryId = DeleteNamedQueryExample.getNamedQueryId(athenaClient, nameQuery);
80+
DeleteNamedQueryExample.deleteQueryName(athenaClient, sampleNamedQueryId);
81+
System.out.println("Test 5 passed");
82+
83+
}
84+
85+
86+
@Test
87+
@Order(6)
88+
public void StartQueryExample() {
89+
90+
try {
91+
String queryExecutionId = StartQueryExample.submitAthenaQuery(athenaClient);
92+
StartQueryExample.waitForQueryToComplete(athenaClient, queryExecutionId);
93+
StartQueryExample.processResultRows(athenaClient, queryExecutionId);
94+
System.out.println("Test 6 passed");
95+
96+
}catch (InterruptedException e) {
97+
e.getMessage();
98+
}
99+
}
100+
101+
@Test
102+
@Order(7)
103+
public void StopQueryExecutionExample() {
104+
105+
String sampleQueryExecutionId = StopQueryExecutionExample.submitAthenaQuery(athenaClient);
106+
StopQueryExecutionExample.stopAthenaQuery(athenaClient, sampleQueryExecutionId);
107+
System.out.println("Test 7 passed");
108+
}
109+
}
110+

0 commit comments

Comments
 (0)