Skip to content

Commit 79d1413

Browse files
Merge pull request #89 from alexanderjordanbaker/XcodeAppStoreServerAPIClient
Use placeholder URL when LOCAL_TESTING environment option is provided
2 parents 6aa5f6f + 32a3e16 commit 79d1413

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/main/java/com/apple/itunes/storekit/client/AppStoreServerAPIClient.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
public class AppStoreServerAPIClient {
4545
private static final String PRODUCTION_URL = "https://api.storekit.itunes.apple.com";
4646
private static final String SANDBOX_URL = "https://api.storekit-sandbox.itunes.apple.com";
47+
private static final String LOCAL_TESTING_URL = "https://local-testing-base-url";
4748
private static final String USER_AGENT = "app-store-server-library/java/2.0.0";
4849
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
4950

@@ -64,7 +65,22 @@ public AppStoreServerAPIClient(String signingKey, String keyId, String issuerId,
6465
this.bearerTokenAuthenticator = new BearerTokenAuthenticator(signingKey, keyId, issuerId, bundleId);
6566
OkHttpClient.Builder builder = new OkHttpClient.Builder();
6667
this.httpClient = builder.build();
67-
this.urlBase = HttpUrl.parse(environment.equals(Environment.SANDBOX) ? SANDBOX_URL : PRODUCTION_URL);
68+
switch (environment) {
69+
case XCODE:
70+
throw new IllegalArgumentException("Xcode is not a supported environment for an AppStoreServerAPIClient");
71+
case PRODUCTION:
72+
this.urlBase = HttpUrl.parse(PRODUCTION_URL);
73+
break;
74+
case LOCAL_TESTING:
75+
this.urlBase = HttpUrl.parse(LOCAL_TESTING_URL);
76+
break;
77+
case SANDBOX:
78+
this.urlBase = HttpUrl.parse(SANDBOX_URL);
79+
break;
80+
default:
81+
// This switch statement is exhaustive
82+
throw new IllegalStateException();
83+
}
6884
this.objectMapper = new ObjectMapper();
6985
objectMapper.setVisibility(objectMapper.getSerializationConfig().getDefaultVisibilityChecker()
7086
.withFieldVisibility(JsonAutoDetect.Visibility.ANY)

src/main/java/com/apple/itunes/storekit/model/Environment.java

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public enum Environment {
1414
SANDBOX("Sandbox"),
1515
PRODUCTION("Production"),
1616
XCODE("Xcode"),
17+
// Used for unit testing
1718
LOCAL_TESTING("LocalTesting");
1819

1920
private final String value;

src/test/java/com/apple/itunes/storekit/client/AppStoreServerAPIClientTest.java

+11
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,17 @@ public void testDecodingWithMalformedJson() throws IOException {
562562
Assertions.fail();
563563
}
564564

565+
@Test
566+
public void testXcodeEnvironmentNotSupportedError() throws IOException {
567+
try (InputStream key = this.getClass().getClassLoader().getResourceAsStream("certs/testSigningKey.p8")) {
568+
new AppStoreServerAPIClient(new String(key.readAllBytes()), "keyId", "issuerId", "com.example", Environment.XCODE);
569+
} catch (IllegalArgumentException e) {
570+
Assertions.assertEquals("Xcode is not a supported environment for an AppStoreServerAPIClient", e.getMessage());
571+
return;
572+
}
573+
Assertions.fail();
574+
}
575+
565576
public AppStoreServerAPIClient getClientWithBody(String path, Consumer<Request> requestVerifier) throws IOException {
566577
String body = TestingUtility.readFile(path);
567578
return getAppStoreServerAPIClient(body, requestVerifier);

0 commit comments

Comments
 (0)