6
6
import org .junit .Before ;
7
7
import org .junit .Test ;
8
8
9
+ import java .io .*;
9
10
import java .lang .reflect .Field ;
10
- import java .net .URI ;
11
- import java .net .http .HttpClient ;
12
- import java .net .http .HttpRequest ;
13
- import java .net .http .HttpResponse ;
11
+ import java .net .*;
12
+ import java .nio .charset .StandardCharsets ;
14
13
import java .util .HashMap ;
15
14
import java .util .List ;
16
15
import java .util .Map ;
17
16
import java .util .concurrent .Future ;
17
+ import java .util .stream .Collectors ;
18
18
19
19
import static org .junit .Assert .assertEquals ;
20
20
@@ -32,17 +32,34 @@ public void setUp() throws Exception {
32
32
}
33
33
}
34
34
35
+ private String postRequestRulesetsTest (String api ) throws Exception {
36
+ URL url = new URL (api + "/rulesets_e2e_test" );
37
+ URLConnection con = url .openConnection ();
38
+ HttpURLConnection http = (HttpURLConnection )con ;
39
+ http .setRequestMethod ("POST" );
40
+ http .setDoOutput (true );
41
+
42
+ byte [] out = "{}" .getBytes (StandardCharsets .UTF_8 );
43
+ int length = out .length ;
44
+
45
+ http .setFixedLengthStreamingMode (length );
46
+ http .setRequestProperty ("STATSIG-API-KEY" , secret );
47
+ http .setRequestProperty ("Content-Type" , "application/json; charset=UTF-8" );
48
+ http .connect ();
49
+ try (OutputStream os = http .getOutputStream ()) {
50
+ os .write (out );
51
+ }
52
+ try (InputStream in = http .getInputStream ()) {
53
+ String result = new BufferedReader (new InputStreamReader (in ))
54
+ .lines ().collect (Collectors .joining ("\n " ));
55
+ return result ;
56
+ }
57
+ }
58
+
35
59
public void testConsistency (String api ) throws Exception {
36
60
System .out .println ("Testing for " + api );
37
- HttpClient httpClient = HttpClient .newHttpClient ();
38
- HttpRequest request = HttpRequest .newBuilder ()
39
- .uri (URI .create (api + "/rulesets_e2e_test" ))
40
- .headers ("STATSIG-API-KEY" , secret , "Content-Type" , "application/json; charset=UTF-8" )
41
- .POST (HttpRequest .BodyPublishers .ofString ("{}" ))
42
- .build ();
43
- HttpResponse <String > response = httpClient .send (request , HttpResponse .BodyHandlers .ofString ());
44
-
45
- APITestDataSet [] data = gson .fromJson (response .body (), APIEvaluationConsistencyTestData .class ).getData ();
61
+ String response = this .postRequestRulesetsTest (api );
62
+ APITestDataSet [] data = gson .fromJson (response , APIEvaluationConsistencyTestData .class ).getData ();
46
63
StatsigServer driver = StatsigServer .create (secret , new StatsigOptions (api ));
47
64
Future initFuture = driver .initializeAsync ();
48
65
initFuture .get ();
0 commit comments