5
5
import static cloud .eppo .helpers .TestUtils .mockHttpError ;
6
6
import static cloud .eppo .helpers .TestUtils .mockHttpResponse ;
7
7
import static cloud .eppo .helpers .TestUtils .setBaseClientHttpClientOverrideField ;
8
- import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
9
- import static org .junit .jupiter .api .Assertions .assertEquals ;
10
- import static org .junit .jupiter .api .Assertions .assertFalse ;
11
- import static org .junit .jupiter .api .Assertions .assertThrows ;
12
- import static org .junit .jupiter .api .Assertions .assertTrue ;
8
+ import static org .junit .jupiter .api .Assertions .*;
13
9
import static org .mockito .Mockito .*;
14
10
15
11
import cloud .eppo .api .*;
22
18
import com .fasterxml .jackson .databind .ObjectMapper ;
23
19
import java .io .File ;
24
20
import java .io .IOException ;
21
+ import java .net .URL ;
25
22
import java .util .*;
26
23
import java .util .concurrent .CompletableFuture ;
27
24
import java .util .concurrent .CompletionException ;
28
25
import java .util .stream .Stream ;
26
+ import okhttp3 .mockwebserver .MockResponse ;
27
+ import okhttp3 .mockwebserver .MockWebServer ;
28
+ import okhttp3 .mockwebserver .RecordedRequest ;
29
29
import org .apache .commons .io .FileUtils ;
30
30
import org .junit .jupiter .api .BeforeEach ;
31
31
import org .junit .jupiter .api .Test ;
@@ -42,10 +42,10 @@ public class BaseEppoClientTest {
42
42
43
43
// Use branch if specified by env variable `TEST_DATA_BRANCH`.
44
44
private static final String TEST_BRANCH = System .getenv ("TEST_DATA_BRANCH" );
45
- private static final String TEST_HOST_BASE =
45
+ private static final String TEST_API_CLOUD_FUNCTION_URL =
46
46
"https://us-central1-eppo-qa.cloudfunctions.net/serveGitHubRacTestFile" ;
47
- private static final String TEST_HOST =
48
- TEST_HOST_BASE + (TEST_BRANCH != null ? "/b/" + TEST_BRANCH : "" );
47
+ private static final String TEST_BASE_URL =
48
+ TEST_API_CLOUD_FUNCTION_URL + (TEST_BRANCH != null ? "/b/" + TEST_BRANCH : "" ) + "/api" ;
49
49
50
50
private final ObjectMapper mapper =
51
51
new ObjectMapper ().registerModule (AssignmentTestCase .assignmentTestCaseModule ());
@@ -73,7 +73,8 @@ private void initClientWithData(
73
73
DUMMY_FLAG_API_KEY ,
74
74
isConfigObfuscated ? "android" : "java" ,
75
75
"100.1.0" ,
76
- TEST_HOST ,
76
+ null ,
77
+ TEST_BASE_URL ,
77
78
mockAssignmentLogger ,
78
79
null ,
79
80
null ,
@@ -93,7 +94,8 @@ private void initClient(boolean isGracefulMode, boolean isConfigObfuscated) {
93
94
DUMMY_FLAG_API_KEY ,
94
95
isConfigObfuscated ? "android" : "java" ,
95
96
"100.1.0" ,
96
- TEST_HOST ,
97
+ null ,
98
+ TEST_BASE_URL ,
97
99
mockAssignmentLogger ,
98
100
null ,
99
101
null ,
@@ -117,7 +119,8 @@ private CompletableFuture<Void> initClientAsync(
117
119
DUMMY_FLAG_API_KEY ,
118
120
isConfigObfuscated ? "android" : "java" ,
119
121
"100.1.0" ,
120
- TEST_HOST ,
122
+ null ,
123
+ TEST_BASE_URL ,
121
124
mockAssignmentLogger ,
122
125
null ,
123
126
null ,
@@ -139,7 +142,8 @@ private void initClientWithAssignmentCache(IAssignmentCache cache) {
139
142
DUMMY_FLAG_API_KEY ,
140
143
"java" ,
141
144
"100.1.0" ,
142
- TEST_HOST ,
145
+ null ,
146
+ TEST_BASE_URL ,
143
147
mockAssignmentLogger ,
144
148
null ,
145
149
null ,
@@ -180,6 +184,49 @@ private static Stream<Arguments> getAssignmentTestData() {
180
184
return AssignmentTestCase .getAssignmentTestData ();
181
185
}
182
186
187
+ @ Test
188
+ public void testBaseUrlBackwardsCompatibility () throws IOException , InterruptedException {
189
+ // Base client must be buildable with a HOST (i.e. no `/api` postfix)
190
+ mockAssignmentLogger = mock (AssignmentLogger .class );
191
+
192
+ MockWebServer mockWebServer = new MockWebServer ();
193
+ URL mockServerBaseUrl = mockWebServer .url ("" ).url (); // get base url of mockwebserver
194
+
195
+ // Remove trailing slash to mimic typical "host" parameter of "https://fscdn.eppo.cloud"
196
+ String testHost = mockServerBaseUrl .toString ().replaceAll ("/$" , "" );
197
+
198
+ mockWebServer .enqueue (new MockResponse ().setResponseCode (200 ).setBody ("{}" ));
199
+
200
+ eppoClient =
201
+ new BaseEppoClient (
202
+ DUMMY_FLAG_API_KEY ,
203
+ "java" ,
204
+ "100.1.0" ,
205
+ testHost ,
206
+ null ,
207
+ mockAssignmentLogger ,
208
+ null ,
209
+ null ,
210
+ false ,
211
+ false ,
212
+ true ,
213
+ null ,
214
+ null ,
215
+ null );
216
+
217
+ eppoClient .loadConfiguration ();
218
+
219
+ // Test what path the call was sent to
220
+ RecordedRequest request = mockWebServer .takeRequest ();
221
+ assertNotNull (request );
222
+ assertEquals ("GET" , request .getMethod ());
223
+
224
+ // The "/api" part comes from appending it on to a "host" parameter but not a base URL param.
225
+ assertEquals (
226
+ "/api/flag-config/v1/config?apiKey=dummy-flags-api-key&sdkName=java&sdkVersion=100.1.0" ,
227
+ request .getPath ());
228
+ }
229
+
183
230
@ Test
184
231
public void testErrorGracefulModeOn () throws JsonProcessingException {
185
232
initClient (true , false );
@@ -287,7 +334,7 @@ public void testErrorGracefulModeOff() {
287
334
@ Test
288
335
public void testInvalidConfigJSON () {
289
336
290
- mockHttpResponse (TEST_HOST , "{}" );
337
+ mockHttpResponse (TEST_BASE_URL , "{}" );
291
338
292
339
initClient (false , false );
293
340
0 commit comments