Skip to content

Commit 0c7c5ed

Browse files
committed
fix: update Stack class to set URL from config and enhance TestStack with region-specific URL tests
1 parent 0dc4096 commit 0c7c5ed

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

contentstack/src/main/java/com/contentstack/sdk/Stack.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ protected void setConfig(Config config) {
9898
}
9999
}
100100
String endpoint = config.PROTOCOL + config.URL;
101+
URL = config.URL;
101102
this.config.setEndpoint(endpoint);
102103
client(endpoint);
103104

contentstack/src/test/java/com/contentstack/sdk/TestStack.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
import org.robolectric.annotation.Config;
1414

1515
import java.util.Date;
16+
import java.util.HashMap;
1617
import java.util.LinkedHashMap;
18+
import java.util.Map;
1719

1820
import static org.junit.Assert.*;
1921

@@ -360,7 +362,7 @@ public void testStackWithCustomConfig() throws Exception {
360362
@Test
361363
public void testStackWithDifferentRegions() throws Exception {
362364
com.contentstack.sdk.Config.ContentstackRegion[] regions = com.contentstack.sdk.Config.ContentstackRegion.values();
363-
365+
364366
for (com.contentstack.sdk.Config.ContentstackRegion region : regions) {
365367
com.contentstack.sdk.Config config = new com.contentstack.sdk.Config();
366368
config.setRegion(region);
@@ -369,6 +371,36 @@ public void testStackWithDifferentRegions() throws Exception {
369371
}
370372
}
371373

374+
@Test
375+
public void testAzureNaRegionSetsCorrectURL() throws Exception {
376+
com.contentstack.sdk.Config config = new com.contentstack.sdk.Config();
377+
config.setRegion(com.contentstack.sdk.Config.ContentstackRegion.AZURE_NA);
378+
Stack regionalStack = Contentstack.stack(mockContext, "api_key", "token", "env", config);
379+
assertEquals("azure-na-cdn.contentstack.com", regionalStack.URL);
380+
}
381+
382+
@Test
383+
public void testNonUsRegionsSetsCorrectStackURL() throws Exception {
384+
Map<com.contentstack.sdk.Config.ContentstackRegion, String> expectedHosts = new HashMap<>();
385+
expectedHosts.put(com.contentstack.sdk.Config.ContentstackRegion.EU, "eu-cdn.contentstack.io");
386+
expectedHosts.put(com.contentstack.sdk.Config.ContentstackRegion.AU, "au-cdn.contentstack.com");
387+
expectedHosts.put(com.contentstack.sdk.Config.ContentstackRegion.AZURE_NA, "azure-na-cdn.contentstack.com");
388+
expectedHosts.put(com.contentstack.sdk.Config.ContentstackRegion.AZURE_EU, "azure-eu-cdn.contentstack.com");
389+
expectedHosts.put(com.contentstack.sdk.Config.ContentstackRegion.GCP_NA, "gcp-na-cdn.contentstack.com");
390+
expectedHosts.put(com.contentstack.sdk.Config.ContentstackRegion.GCP_EU, "gcp-eu-cdn.contentstack.com");
391+
392+
for (Map.Entry<com.contentstack.sdk.Config.ContentstackRegion, String> entry : expectedHosts.entrySet()) {
393+
com.contentstack.sdk.Config config = new com.contentstack.sdk.Config();
394+
config.setRegion(entry.getKey());
395+
Stack regionalStack = Contentstack.stack(mockContext, "api_key", "token", "env", config);
396+
assertEquals(
397+
"Stack.URL mismatch for region " + entry.getKey(),
398+
entry.getValue(),
399+
regionalStack.URL
400+
);
401+
}
402+
}
403+
372404
@Test
373405
public void testContentTypeEntryCreation() {
374406
ContentType contentType = stack.contentType("products");

0 commit comments

Comments
 (0)