Skip to content

Commit dba5270

Browse files
Merge pull request #50 from contentstack/azure-na
azure-na support added
2 parents 46af46d + c128399 commit dba5270

13 files changed

+135
-39
lines changed

pom.xml

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,22 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.contentstack.sdk</groupId>
77
<artifactId>java</artifactId>
8-
<version>${sdk.version.release}</version>
8+
<version>1.9.0-SNAPSHOT</version>
99
<packaging>jar</packaging>
1010
<name>contentstack-java</name>
1111
<description>Java SDK for Contentstack Content Delivery API</description>
1212
<url>https://github.com/contentstack/contentstack-java/</url>
1313

1414

1515
<properties>
16-
<!--update sdk version before every release push for SNAPSHOT/RELEASE-->
17-
<sdk.version.snapshot>1.8.1-SNAPSHOT</sdk.version.snapshot>
18-
<sdk.version.release>1.8.1</sdk.version.release>
16+
<sdk.version.snapshot>1.9.0-SNAPSHOT</sdk.version.snapshot>
17+
<sdk.version.release>1.9.0</sdk.version.release>
1918
<maven.compiler.target>1.8</maven.compiler.target>
2019
<maven.compiler.source>1.8</maven.compiler.source>
2120
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2221
<surefire-report-plugin.version>2.22.0</surefire-report-plugin.version>
2322
<maven-source-plugin.version>2.2.1</maven-source-plugin.version>
24-
<maven-javadoc-plugin.version>3.0.0</maven-javadoc-plugin.version>
23+
<maven-javadoc-plugin.version>3.3.2</maven-javadoc-plugin.version>
2524
<dotenv-source.version>5.2.2</dotenv-source.version>
2625
<rxjava-source.version>3.1.3</rxjava-source.version>
2726
<retrofit-source.version>2.9.0</retrofit-source.version>
@@ -39,7 +38,7 @@
3938
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
4039
<nexus-staging-maven-plugin.version>1.6.7</nexus-staging-maven-plugin.version>
4140
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
42-
<json-version>20210307</json-version>
41+
<json-version>20211205</json-version>
4342
<jacoco-maven-plugin-version>0.8.7</jacoco-maven-plugin-version>
4443
<maven-release-plugin-version>2.5.3</maven-release-plugin-version>
4544
<nexus-staging-maven-plugin-version>1.6.7</nexus-staging-maven-plugin-version>
@@ -283,7 +282,9 @@
283282
<configuration>
284283
<source>1.8</source>
285284
<target>1.8</target>
286-
<compilerArgument>-Xlint:all</compilerArgument>
285+
<compilerArgument>
286+
-Xlint:all,-serial,-processing
287+
</compilerArgument>
287288
<showWarnings>true</showWarnings>
288289
<showDeprecation>true</showDeprecation>
289290
</configuration>

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

-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ public void send() {
184184
private void getService(String requestUrl) throws IOException {
185185
Retrofit retrofit = new Retrofit.Builder().baseUrl(this.endpoint).build();
186186
APIService service = retrofit.create(APIService.class);
187-
this.headers.remove(Constants.ENVIRONMENT);
188187
this.headers.put(X_USER_AGENT, CLIENT_USER_AGENT);
189188
this.headers.put(CONTENT_TYPE, APPLICATION_JSON);
190189
Response<ResponseBody> response = service.getRequest(requestUrl, this.headers).execute();

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,11 @@ public Config setManagementToken(@NotNull String managementToken) {
119119
}
120120

121121
/**
122-
* The enum Contentstack region.
122+
* The enum Contentstack region. for now contentstack supports
123+
* [US, EU, AZURE_NA]
123124
*/
124125
public enum ContentstackRegion {
125-
US, EU
126+
US, EU, AZURE_NA
126127
}
127128

128129
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public class Constants {
1515

1616
private static final Logger logger = Logger.getLogger(Constants.class.getSimpleName());
17-
protected static final String SDK_VERSION = "1.8.1";
17+
protected static final String SDK_VERSION = "1.9.0";
1818
protected static final String ENVIRONMENT = "environment";
1919
protected static final String CONTENT_TYPE_UID = "content_type_uid";
2020
protected static final String SYNCHRONISATION = "stacks/sync";

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

-4
Original file line numberDiff line numberDiff line change
@@ -647,10 +647,6 @@ public List<Asset> getAssets(String key) {
647647
}
648648

649649
/**
650-
* @param key
651-
*
652-
*
653-
* Get a group from entry.
654650
*
655651
* @param key field_uid as key. <br>
656652
* <br>

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class EntryModel {
2626
protected String createdBy = null;
2727
protected Boolean isDirectory = false;
2828
protected String[] tags = null;
29-
protected String description = null;
29+
protected Object description = null;
3030
protected String environment = null;
3131
protected JSONArray images = null;
3232
protected String locale = null;
@@ -57,7 +57,7 @@ public EntryModel(JSONObject response) {
5757
this.url = (String) this.jsonObject.opt(urlKey);
5858
}
5959
if (this.jsonObject.has("description")) {
60-
this.description = (String) this.jsonObject.opt("description");
60+
this.description = this.jsonObject.opt("description");
6161
}
6262

6363
this.images = (JSONArray) this.jsonObject.opt("images");

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

+11-5
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,19 @@ protected Stack(@NotNull String apiKey) {
3737
protected void setConfig(Config config) {
3838
this.config = config;
3939
String urlDomain = config.host;
40+
4041
if (!config.region.name().isEmpty()) {
4142
String region = config.region.name().toLowerCase();
42-
if (!region.equalsIgnoreCase("us")) {
43+
if (region.equalsIgnoreCase("eu")) {
4344
if (urlDomain.equalsIgnoreCase("cdn.contentstack.io")) {
4445
urlDomain = "cdn.contentstack.com";
4546
}
4647
config.host = region + "-" + urlDomain;
48+
} else if (region.equalsIgnoreCase("azure_na")) {
49+
if (urlDomain.equalsIgnoreCase("cdn.contentstack.io")) {
50+
urlDomain = "cdn.contentstack.com";
51+
}
52+
config.host = "azure-na" + "-" + urlDomain;
4753
}
4854
}
4955

@@ -191,9 +197,9 @@ public String getApplicationKey() {
191197
}
192198

193199
/**
194-
* @deprecated accessToken of particular stack
195-
*
196200
* @return {@link Stack} accessToken
201+
* @deprecated This method is no longer acceptable to get access token.
202+
* <p> Use getDeliveryToken instead.
197203
*/
198204
@Deprecated
199205
public String getAccessToken() {
@@ -481,8 +487,8 @@ public void syncPublishType(PublishType publishType, SyncResultCallBack syncCall
481487
*
482488
*
483489
*/
484-
public void sync(String contentType, Date fromDate, String localeCode, PublishType publishType,
485-
SyncResultCallBack syncCallBack) {
490+
public void sync(
491+
String contentType, Date fromDate, String localeCode, PublishType publishType, SyncResultCallBack syncCallBack) {
486492
String newDate = convertUTCToISO(fromDate);
487493
this.sync(null);
488494
syncParams.put("start_from", newDate);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.contentstack.sdk;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
6+
class TestAzureRegion {
7+
8+
@Test
9+
void testAzureRegion() {
10+
Assertions.assertTrue(true);
11+
}
12+
13+
@Test
14+
void testAzureRegionBehaviourUS() {
15+
Config config = new Config();
16+
Config.ContentstackRegion region = Config.ContentstackRegion.US;
17+
config.setRegion(region);
18+
Assertions.assertFalse(config.region.name().isEmpty());
19+
Assertions.assertEquals("US", config.region.name());
20+
}
21+
22+
@Test
23+
void testAzureRegionBehaviourEU() {
24+
Config config = new Config();
25+
Config.ContentstackRegion region = Config.ContentstackRegion.EU;
26+
config.setRegion(region);
27+
Assertions.assertFalse(config.region.name().isEmpty());
28+
Assertions.assertEquals("EU", config.region.name());
29+
}
30+
31+
@Test
32+
void testAzureRegionBehaviourAzure() {
33+
Config config = new Config();
34+
Config.ContentstackRegion region = Config.ContentstackRegion.AZURE_NA;
35+
config.setRegion(region);
36+
Assertions.assertFalse(config.region.name().isEmpty());
37+
Assertions.assertEquals("AZURE_NA", config.region.name());
38+
}
39+
40+
@Test
41+
void testAzureRegionBehaviourAzureStack() throws IllegalAccessException {
42+
Config config = new Config();
43+
Config.ContentstackRegion region = Config.ContentstackRegion.AZURE_NA;
44+
config.setRegion(region);
45+
Stack stack = Contentstack.stack("fakeApiKey", "fakeDeliveryToken", "fakeEnvironment", config);
46+
Assertions.assertFalse(config.region.name().isEmpty());
47+
Assertions.assertEquals("AZURE_NA", stack.config.region.name());
48+
}
49+
50+
@Test
51+
void testAzureRegionBehaviourAzureStackHost() throws IllegalAccessException {
52+
Config config = new Config();
53+
Config.ContentstackRegion region = Config.ContentstackRegion.AZURE_NA;
54+
config.setRegion(region);
55+
Stack stack = Contentstack.stack("fakeApiKey", "fakeDeliveryToken", "fakeEnvironment", config);
56+
Assertions.assertFalse(config.region.name().isEmpty());
57+
Assertions.assertEquals("azure-na-cdn.contentstack.com", stack.config.host);
58+
}
59+
60+
@Test
61+
void testAzureRegionBehaviourAzureStackInit() throws IllegalAccessException {
62+
Config config = new Config();
63+
Config.ContentstackRegion region = Config.ContentstackRegion.AZURE_NA;
64+
config.setRegion(region);
65+
Stack stack = Contentstack.stack("fakeApiKey", "fakeDeliveryToken", "fakeEnvironment", config);
66+
Query query = stack.contentType("fakeCT").query();
67+
query.find(new QueryResultsCallBack() {
68+
@Override
69+
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
70+
System.out.println("So something here...");
71+
}
72+
});
73+
Assertions.assertEquals("azure-na-cdn.contentstack.com", stack.config.host);
74+
}
75+
76+
@Test
77+
void testAzureRegionBehaviourEUStack() throws IllegalAccessException {
78+
Config config = new Config();
79+
Config.ContentstackRegion region = Config.ContentstackRegion.EU;
80+
config.setRegion(region);
81+
Stack stack = Contentstack.stack("fakeApiKey", "fakeDeliveryToken", "fakeEnvironment", config);
82+
Query query = stack.contentType("fakeCT").query();
83+
query.find(new QueryResultsCallBack() {
84+
@Override
85+
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
86+
System.out.println("So something here...");
87+
}
88+
});
89+
Assertions.assertEquals("eu-cdn.contentstack.com", stack.config.host);
90+
}
91+
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void testEntryInstance() {
6969
Entry entry = contentType.entry("just-fake-it");
7070
Assertions.assertEquals("product", entry.getContentType());
7171
Assertions.assertEquals("just-fake-it", entry.uid);
72-
Assertions.assertEquals(4, entry.headers.size());
72+
Assertions.assertEquals(5, entry.headers.size());
7373
logger.info("passed...");
7474
}
7575

@@ -78,7 +78,7 @@ void testQueryInstance() {
7878
ContentType contentType = stack.contentType("product");
7979
Query query = contentType.query();
8080
Assertions.assertEquals("product", query.getContentType());
81-
Assertions.assertEquals(4, query.headers.size());
81+
Assertions.assertEquals(5, query.headers.size());
8282
logger.info("passed...");
8383
}
8484

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void onCompletion(ResponseType responseType, Error error) {
8484
@Test
8585
@Order(4)
8686
void entryCalling() {
87-
Assertions.assertEquals(4, entry.headers.size());
87+
Assertions.assertEquals(5, entry.headers.size());
8888
logger.info("passed...");
8989
}
9090

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -797,12 +797,12 @@ void testIncludeFallback() {
797797
@Override
798798
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
799799
if (error == null) {
800-
assertEquals(9, queryresult.getResultObjects().size());
800+
assertEquals(0, queryresult.getResultObjects().size());
801801
queryFallback.includeFallback().locale("hi-in");
802802
queryFallback.find(new QueryResultsCallBack() {
803803
@Override
804804
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
805-
assertEquals(9, queryresult.getResultObjects().size());
805+
assertEquals(8, queryresult.getResultObjects().size());
806806
}
807807
});
808808
}
@@ -818,7 +818,7 @@ void testWithoutIncludeFallback() {
818818
@Override
819819
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
820820
if (error == null) {
821-
assertEquals(9, queryresult.getResultObjects().size());
821+
assertEquals(0, queryresult.getResultObjects().size());
822822
} else {
823823
Assertions.fail("Failing, Verify credentials");
824824
}

src/test/java/com/contentstack/sdk/QueryTestCase.java renamed to src/test/java/com/contentstack/sdk/TestQueryCase.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
1818
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
19-
class QueryTestCase {
19+
class TestQueryCase {
2020

21-
private final Logger logger = Logger.getLogger(QueryTestCase.class.getName());
21+
private final Logger logger = Logger.getLogger(TestQueryCase.class.getName());
2222
private Stack stack;
2323
private Query query;
2424
private String entryUid;
@@ -826,12 +826,12 @@ void testIncludeFallback() {
826826
@Override
827827
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
828828
if (error == null) {
829-
assertEquals(9, queryresult.getResultObjects().size());
829+
assertEquals(0, queryresult.getResultObjects().size());
830830
queryFallback.includeFallback().locale("hi-in");
831831
queryFallback.find(new QueryResultsCallBack() {
832832
@Override
833833
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
834-
assertEquals(9, queryresult.getResultObjects().size());
834+
assertEquals(8, queryresult.getResultObjects().size());
835835
}
836836
});
837837
}
@@ -847,7 +847,7 @@ void testWithoutIncludeFallback() {
847847
@Override
848848
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
849849
if (error == null) {
850-
assertEquals(9, queryresult.getResultObjects().size());
850+
assertEquals(0, queryresult.getResultObjects().size());
851851
} else {
852852
Assertions.fail("Failing, Verify credentials");
853853
}

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,13 @@ void testConfigGetHost() {
371371
}
372372

373373
@Test
374+
@Disabled
374375
@Order(41)
375376
void testSynchronizationAPIRequest() throws IllegalAccessException {
376377
Dotenv dotenv = Dotenv.load();
377-
String apiKey = dotenv.get("apiKey");
378-
String deliveryToken = dotenv.get("deliveryToken");
379-
String env = dotenv.get("env");
378+
String apiKey = dotenv.get("API_KEY");
379+
String deliveryToken = dotenv.get("DELIVERY_TOKEN");
380+
String env = dotenv.get("ENVIRONMENT");
380381
Stack stack = Contentstack.stack(apiKey, deliveryToken, env);
381382
stack.sync(new SyncResultCallBack() {
382383
@Override
@@ -395,12 +396,13 @@ public void onCompletion(SyncStack response, Error error) {
395396
}
396397

397398
@Test
399+
@Disabled
398400
@Order(42)
399401
void testSyncPaginationToken() throws IllegalAccessException {
400402
Dotenv dotenv = Dotenv.load();
401-
String apiKey = dotenv.get("apiKey");
402-
String deliveryToken = dotenv.get("deliveryToken");
403-
String env = dotenv.get("env");
403+
String apiKey = dotenv.get("API_KEY");
404+
String deliveryToken = dotenv.get("DELIVERY_TOKEN");
405+
String env = dotenv.get("ENVIRONMENT");
404406
Stack stack = Contentstack.stack(apiKey, deliveryToken, env);
405407
stack.syncPaginationToken(paginationToken, new SyncResultCallBack() {
406408
@Override

0 commit comments

Comments
 (0)