-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathGatewayTest.java
More file actions
62 lines (53 loc) · 1.66 KB
/
GatewayTest.java
File metadata and controls
62 lines (53 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import org.junit.jupiter.api.Test;
import org.opentest4j.AssertionFailedError;
public class GatewayTest {
Gateway getGateway() {
Gateway gateway = new Gateway();
boolean connectionInitialized =
gateway.initializeConnection("localhost", 9200, "http", null, null, false);
if (!connectionInitialized) {
throw new AssertionError("failed to initialize connection");
}
return gateway;
}
void assertSuccessfulPPL(Gateway gateway, String ppl) {
String result = gateway.queryExecution(ppl, true, false, "table");
System.out.println("Result is: " + result);
if (result.contains("Exception")) {
throw new AssertionFailedError(
String.format("expected successful response string but got Exception:\n> %s", result));
}
}
@Test
void pplSelectAll() {
Gateway gateway = getGateway();
assertSuccessfulPPL(gateway, "source = accounts;");
}
@Test
void pplSelectHead() {
Gateway gateway = getGateway();
assertSuccessfulPPL(gateway, "source = accounts | head 10;");
}
@Test
void pplSelectOffsetHead() {
Gateway gateway = getGateway();
assertSuccessfulPPL(gateway, "source = accounts | head 200 from 9900;");
}
@Test
void pplNumericStats() {
Gateway gateway = getGateway();
assertSuccessfulPPL(
gateway,
"source = accounts | stats max(balance) as max_balance, avg(balance) as avg_balance by"
+ " city");
}
@Test
void pplValuesStats() {
Gateway gateway = getGateway();
assertSuccessfulPPL(gateway, "source = accounts | stats values(email) as emails");
}
}