Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.contentstack.sdk</groupId>
<artifactId>java</artifactId>
<version>${sdk.version.release}</version>
<version>1.9.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>contentstack-java</name>
<description>Java SDK for Contentstack Content Delivery API</description>
<url>https://github.com/contentstack/contentstack-java/</url>


<properties>
<!--update sdk version before every release push for SNAPSHOT/RELEASE-->
<sdk.version.snapshot>1.8.1-SNAPSHOT</sdk.version.snapshot>
<sdk.version.release>1.8.1</sdk.version.release>
<sdk.version.snapshot>1.9.0-SNAPSHOT</sdk.version.snapshot>
<sdk.version.release>1.9.0</sdk.version.release>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<surefire-report-plugin.version>2.22.0</surefire-report-plugin.version>
<maven-source-plugin.version>2.2.1</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.0.0</maven-javadoc-plugin.version>
<maven-javadoc-plugin.version>3.3.2</maven-javadoc-plugin.version>
<dotenv-source.version>5.2.2</dotenv-source.version>
<rxjava-source.version>3.1.3</rxjava-source.version>
<retrofit-source.version>2.9.0</retrofit-source.version>
Expand All @@ -39,7 +38,7 @@
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<nexus-staging-maven-plugin.version>1.6.7</nexus-staging-maven-plugin.version>
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
<json-version>20210307</json-version>
<json-version>20211205</json-version>
<jacoco-maven-plugin-version>0.8.7</jacoco-maven-plugin-version>
<maven-release-plugin-version>2.5.3</maven-release-plugin-version>
<nexus-staging-maven-plugin-version>1.6.7</nexus-staging-maven-plugin-version>
Expand Down Expand Up @@ -283,7 +282,9 @@
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-Xlint:all</compilerArgument>
<compilerArgument>
-Xlint:all,-serial,-processing
</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/contentstack/sdk/CSHttpConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ public void send() {
private void getService(String requestUrl) throws IOException {
Retrofit retrofit = new Retrofit.Builder().baseUrl(this.endpoint).build();
APIService service = retrofit.create(APIService.class);
this.headers.remove(Constants.ENVIRONMENT);
this.headers.put(X_USER_AGENT, CLIENT_USER_AGENT);
this.headers.put(CONTENT_TYPE, APPLICATION_JSON);
Response<ResponseBody> response = service.getRequest(requestUrl, this.headers).execute();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/contentstack/sdk/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,11 @@ public Config setManagementToken(@NotNull String managementToken) {
}

/**
* The enum Contentstack region.
* The enum Contentstack region. for now contentstack supports
* [US, EU, AZURE_NA]
*/
public enum ContentstackRegion {
US, EU
US, EU, AZURE_NA
}

}
2 changes: 1 addition & 1 deletion src/main/java/com/contentstack/sdk/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class Constants {

private static final Logger logger = Logger.getLogger(Constants.class.getSimpleName());
protected static final String SDK_VERSION = "1.8.1";
protected static final String SDK_VERSION = "1.9.0";
protected static final String ENVIRONMENT = "environment";
protected static final String CONTENT_TYPE_UID = "content_type_uid";
protected static final String SYNCHRONISATION = "stacks/sync";
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/contentstack/sdk/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -647,10 +647,6 @@ public List<Asset> getAssets(String key) {
}

/**
* @param key
*
*
* Get a group from entry.
*
* @param key field_uid as key. <br>
* <br>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/contentstack/sdk/EntryModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class EntryModel {
protected String createdBy = null;
protected Boolean isDirectory = false;
protected String[] tags = null;
protected String description = null;
protected Object description = null;
protected String environment = null;
protected JSONArray images = null;
protected String locale = null;
Expand Down Expand Up @@ -57,7 +57,7 @@ public EntryModel(JSONObject response) {
this.url = (String) this.jsonObject.opt(urlKey);
}
if (this.jsonObject.has("description")) {
this.description = (String) this.jsonObject.opt("description");
this.description = this.jsonObject.opt("description");
}

this.images = (JSONArray) this.jsonObject.opt("images");
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/com/contentstack/sdk/Stack.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@ protected Stack(@NotNull String apiKey) {
protected void setConfig(Config config) {
this.config = config;
String urlDomain = config.host;

if (!config.region.name().isEmpty()) {
String region = config.region.name().toLowerCase();
if (!region.equalsIgnoreCase("us")) {
if (region.equalsIgnoreCase("eu")) {
if (urlDomain.equalsIgnoreCase("cdn.contentstack.io")) {
urlDomain = "cdn.contentstack.com";
}
config.host = region + "-" + urlDomain;
} else if (region.equalsIgnoreCase("azure_na")) {
if (urlDomain.equalsIgnoreCase("cdn.contentstack.io")) {
urlDomain = "cdn.contentstack.com";
}
config.host = "azure-na" + "-" + urlDomain;
}
}

Expand Down Expand Up @@ -191,9 +197,9 @@ public String getApplicationKey() {
}

/**
* @deprecated accessToken of particular stack
*
* @return {@link Stack} accessToken
* @deprecated This method is no longer acceptable to get access token.
* <p> Use getDeliveryToken instead.
*/
@Deprecated
public String getAccessToken() {
Expand Down Expand Up @@ -481,8 +487,8 @@ public void syncPublishType(PublishType publishType, SyncResultCallBack syncCall
*
*
*/
public void sync(String contentType, Date fromDate, String localeCode, PublishType publishType,
SyncResultCallBack syncCallBack) {
public void sync(
String contentType, Date fromDate, String localeCode, PublishType publishType, SyncResultCallBack syncCallBack) {
String newDate = convertUTCToISO(fromDate);
this.sync(null);
syncParams.put("start_from", newDate);
Expand Down
91 changes: 91 additions & 0 deletions src/test/java/com/contentstack/sdk/TestAzureRegion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.contentstack.sdk;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class TestAzureRegion {

@Test
void testAzureRegion() {
Assertions.assertTrue(true);
}

@Test
void testAzureRegionBehaviourUS() {
Config config = new Config();
Config.ContentstackRegion region = Config.ContentstackRegion.US;
config.setRegion(region);
Assertions.assertFalse(config.region.name().isEmpty());
Assertions.assertEquals("US", config.region.name());
}

@Test
void testAzureRegionBehaviourEU() {
Config config = new Config();
Config.ContentstackRegion region = Config.ContentstackRegion.EU;
config.setRegion(region);
Assertions.assertFalse(config.region.name().isEmpty());
Assertions.assertEquals("EU", config.region.name());
}

@Test
void testAzureRegionBehaviourAzure() {
Config config = new Config();
Config.ContentstackRegion region = Config.ContentstackRegion.AZURE_NA;
config.setRegion(region);
Assertions.assertFalse(config.region.name().isEmpty());
Assertions.assertEquals("AZURE_NA", config.region.name());
}

@Test
void testAzureRegionBehaviourAzureStack() throws IllegalAccessException {
Config config = new Config();
Config.ContentstackRegion region = Config.ContentstackRegion.AZURE_NA;
config.setRegion(region);
Stack stack = Contentstack.stack("fakeApiKey", "fakeDeliveryToken", "fakeEnvironment", config);
Assertions.assertFalse(config.region.name().isEmpty());
Assertions.assertEquals("AZURE_NA", stack.config.region.name());
}

@Test
void testAzureRegionBehaviourAzureStackHost() throws IllegalAccessException {
Config config = new Config();
Config.ContentstackRegion region = Config.ContentstackRegion.AZURE_NA;
config.setRegion(region);
Stack stack = Contentstack.stack("fakeApiKey", "fakeDeliveryToken", "fakeEnvironment", config);
Assertions.assertFalse(config.region.name().isEmpty());
Assertions.assertEquals("azure-na-cdn.contentstack.com", stack.config.host);
}

@Test
void testAzureRegionBehaviourAzureStackInit() throws IllegalAccessException {
Config config = new Config();
Config.ContentstackRegion region = Config.ContentstackRegion.AZURE_NA;
config.setRegion(region);
Stack stack = Contentstack.stack("fakeApiKey", "fakeDeliveryToken", "fakeEnvironment", config);
Query query = stack.contentType("fakeCT").query();
query.find(new QueryResultsCallBack() {
@Override
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
System.out.println("So something here...");
}
});
Assertions.assertEquals("azure-na-cdn.contentstack.com", stack.config.host);
}

@Test
void testAzureRegionBehaviourEUStack() throws IllegalAccessException {
Config config = new Config();
Config.ContentstackRegion region = Config.ContentstackRegion.EU;
config.setRegion(region);
Stack stack = Contentstack.stack("fakeApiKey", "fakeDeliveryToken", "fakeEnvironment", config);
Query query = stack.contentType("fakeCT").query();
query.find(new QueryResultsCallBack() {
@Override
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
System.out.println("So something here...");
}
});
Assertions.assertEquals("eu-cdn.contentstack.com", stack.config.host);
}
}
4 changes: 2 additions & 2 deletions src/test/java/com/contentstack/sdk/TestContentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void testEntryInstance() {
Entry entry = contentType.entry("just-fake-it");
Assertions.assertEquals("product", entry.getContentType());
Assertions.assertEquals("just-fake-it", entry.uid);
Assertions.assertEquals(4, entry.headers.size());
Assertions.assertEquals(5, entry.headers.size());
logger.info("passed...");
}

Expand All @@ -78,7 +78,7 @@ void testQueryInstance() {
ContentType contentType = stack.contentType("product");
Query query = contentType.query();
Assertions.assertEquals("product", query.getContentType());
Assertions.assertEquals(4, query.headers.size());
Assertions.assertEquals(5, query.headers.size());
logger.info("passed...");
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/contentstack/sdk/TestEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void onCompletion(ResponseType responseType, Error error) {
@Test
@Order(4)
void entryCalling() {
Assertions.assertEquals(4, entry.headers.size());
Assertions.assertEquals(5, entry.headers.size());
logger.info("passed...");
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/contentstack/sdk/TestQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -797,12 +797,12 @@ void testIncludeFallback() {
@Override
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
if (error == null) {
assertEquals(9, queryresult.getResultObjects().size());
assertEquals(0, queryresult.getResultObjects().size());
queryFallback.includeFallback().locale("hi-in");
queryFallback.find(new QueryResultsCallBack() {
@Override
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
assertEquals(9, queryresult.getResultObjects().size());
assertEquals(8, queryresult.getResultObjects().size());
}
});
}
Expand All @@ -818,7 +818,7 @@ void testWithoutIncludeFallback() {
@Override
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
if (error == null) {
assertEquals(9, queryresult.getResultObjects().size());
assertEquals(0, queryresult.getResultObjects().size());
} else {
Assertions.fail("Failing, Verify credentials");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class QueryTestCase {
class TestQueryCase {

private final Logger logger = Logger.getLogger(QueryTestCase.class.getName());
private final Logger logger = Logger.getLogger(TestQueryCase.class.getName());
private Stack stack;
private Query query;
private String entryUid;
Expand Down Expand Up @@ -826,12 +826,12 @@ void testIncludeFallback() {
@Override
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
if (error == null) {
assertEquals(9, queryresult.getResultObjects().size());
assertEquals(0, queryresult.getResultObjects().size());
queryFallback.includeFallback().locale("hi-in");
queryFallback.find(new QueryResultsCallBack() {
@Override
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
assertEquals(9, queryresult.getResultObjects().size());
assertEquals(8, queryresult.getResultObjects().size());
}
});
}
Expand All @@ -847,7 +847,7 @@ void testWithoutIncludeFallback() {
@Override
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
if (error == null) {
assertEquals(9, queryresult.getResultObjects().size());
assertEquals(0, queryresult.getResultObjects().size());
} else {
Assertions.fail("Failing, Verify credentials");
}
Expand Down
14 changes: 8 additions & 6 deletions src/test/java/com/contentstack/sdk/TestStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,13 @@ void testConfigGetHost() {
}

@Test
@Disabled
@Order(41)
void testSynchronizationAPIRequest() throws IllegalAccessException {
Dotenv dotenv = Dotenv.load();
String apiKey = dotenv.get("apiKey");
String deliveryToken = dotenv.get("deliveryToken");
String env = dotenv.get("env");
String apiKey = dotenv.get("API_KEY");
String deliveryToken = dotenv.get("DELIVERY_TOKEN");
String env = dotenv.get("ENVIRONMENT");
Stack stack = Contentstack.stack(apiKey, deliveryToken, env);
stack.sync(new SyncResultCallBack() {
@Override
Expand All @@ -395,12 +396,13 @@ public void onCompletion(SyncStack response, Error error) {
}

@Test
@Disabled
@Order(42)
void testSyncPaginationToken() throws IllegalAccessException {
Dotenv dotenv = Dotenv.load();
String apiKey = dotenv.get("apiKey");
String deliveryToken = dotenv.get("deliveryToken");
String env = dotenv.get("env");
String apiKey = dotenv.get("API_KEY");
String deliveryToken = dotenv.get("DELIVERY_TOKEN");
String env = dotenv.get("ENVIRONMENT");
Stack stack = Contentstack.stack(apiKey, deliveryToken, env);
stack.syncPaginationToken(paginationToken, new SyncResultCallBack() {
@Override
Expand Down