From 0952831b74ea71fb338fc9a054aecb65c20e2217 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Wed, 1 Jun 2022 12:51:51 +0530 Subject: [PATCH] :lady_beetle: pom and version --- pom.xml | 2 +- .../contentstack/sdk/CSHttpConnection.java | 3 +- .../java/com/contentstack/sdk/Constants.java | 16 ++++------ .../contentstack/sdk/TestAssetLibrary.java | 1 - .../com/contentstack/sdk/TestContentType.java | 4 +-- .../java/com/contentstack/sdk/TestEntry.java | 2 +- .../java/com/contentstack/sdk/TestQuery.java | 31 ++++++------------- 7 files changed, 21 insertions(+), 38 deletions(-) diff --git a/pom.xml b/pom.xml index 139a6156..9cf6d252 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ 0.8.7 2.5.3 1.6.7 - 1.1.0 + 1.1.1 diff --git a/src/main/java/com/contentstack/sdk/CSHttpConnection.java b/src/main/java/com/contentstack/sdk/CSHttpConnection.java index 65216388..0636fe16 100644 --- a/src/main/java/com/contentstack/sdk/CSHttpConnection.java +++ b/src/main/java/com/contentstack/sdk/CSHttpConnection.java @@ -181,7 +181,8 @@ public void send() { } private void getService(String requestUrl) throws IOException { - this.headers.put(X_USER_AGENT, CLIENT_USER_AGENT); + this.headers.put(X_USER_AGENT_KEY, "contentstack-java/" + SDK_VERSION); + this.headers.put(USER_AGENT_KEY, USER_AGENT); this.headers.put(CONTENT_TYPE, APPLICATION_JSON); Response response = this.service.getRequest(requestUrl, this.headers).execute(); if (response.isSuccessful()) { diff --git a/src/main/java/com/contentstack/sdk/Constants.java b/src/main/java/com/contentstack/sdk/Constants.java index 984aeba9..fa64ae5f 100644 --- a/src/main/java/com/contentstack/sdk/Constants.java +++ b/src/main/java/com/contentstack/sdk/Constants.java @@ -2,10 +2,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.TimeZone; +import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; @@ -24,11 +21,12 @@ public class Constants { protected static final String ERROR_MESSAGE = "error_message"; protected static final String ERRORS = "errors"; // User-Agents - protected static final String X_USER_AGENT = "X-User-Agent"; + protected static final String X_USER_AGENT_KEY = "X-User-Agent"; + protected static final String USER_AGENT_KEY = "User-Agent"; + protected static final String USER_AGENT = userAgent(); protected static final String CONTENT_TYPE = "Content-Type"; protected static final String APPLICATION_JSON = "application/json"; - protected static final String CLIENT_USER_AGENT = userAgent(); - // Query + protected static final String QUERY = "query"; protected static final String EXCEPT = "except"; protected static final String EXISTS = "$exists"; @@ -58,10 +56,7 @@ public enum REQUEST_CONTROLLER { public static final String FETCHSYNC = "getSync"; public static final String FETCHCONTENTTYPES = "getContentTypes"; - // ERROR MESSAGE BLOCK - public static final String JSON_NOT_PROPER = "Please provide valid JSON."; public static final String CONTENT_TYPE_NAME = "Please set contentType name."; - public static final String HEADER_IS_MISSING_TO_PROCESS_THE_DATA = "Header is missing to process the data"; public static final String QUERY_EXCEPTION = "Please provide valid params."; /** @@ -137,4 +132,5 @@ protected static String userAgent() { agentStr = agentStr + "/" + SDK_VERSION; return agentStr; } + } diff --git a/src/test/java/com/contentstack/sdk/TestAssetLibrary.java b/src/test/java/com/contentstack/sdk/TestAssetLibrary.java index de23631f..8de98f16 100644 --- a/src/test/java/com/contentstack/sdk/TestAssetLibrary.java +++ b/src/test/java/com/contentstack/sdk/TestAssetLibrary.java @@ -42,7 +42,6 @@ public void onCompletion(ResponseType responseType, List assets, Error er Assertions.assertTrue(model.getCreatedBy().startsWith("blt")); assertEquals("gregory", model.getUpdateAt().getCalendarType()); Assertions.assertTrue(model.getUpdatedBy().startsWith("sys")); - Assertions.assertNull(model.getDeleteAt()); assertEquals("", model.getDeletedBy()); logger.info("passed..."); } diff --git a/src/test/java/com/contentstack/sdk/TestContentType.java b/src/test/java/com/contentstack/sdk/TestContentType.java index b1e8c8ff..b80e95a5 100644 --- a/src/test/java/com/contentstack/sdk/TestContentType.java +++ b/src/test/java/com/contentstack/sdk/TestContentType.java @@ -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(5, entry.headers.size()); + Assertions.assertEquals(6, entry.headers.size()); logger.info("passed..."); } @@ -78,7 +78,7 @@ void testQueryInstance() { ContentType contentType = stack.contentType("product"); Query query = contentType.query(); Assertions.assertEquals("product", query.getContentType()); - Assertions.assertEquals(5, query.headers.size()); + Assertions.assertEquals(6, query.headers.size()); logger.info("passed..."); } diff --git a/src/test/java/com/contentstack/sdk/TestEntry.java b/src/test/java/com/contentstack/sdk/TestEntry.java index 5d9148f7..c95662d6 100644 --- a/src/test/java/com/contentstack/sdk/TestEntry.java +++ b/src/test/java/com/contentstack/sdk/TestEntry.java @@ -84,7 +84,7 @@ public void onCompletion(ResponseType responseType, Error error) { @Test @Order(4) void entryCalling() { - Assertions.assertEquals(5, entry.headers.size()); + Assertions.assertEquals(6, entry.headers.size()); logger.info("passed..."); } diff --git a/src/test/java/com/contentstack/sdk/TestQuery.java b/src/test/java/com/contentstack/sdk/TestQuery.java index b259e82c..03de7fa5 100644 --- a/src/test/java/com/contentstack/sdk/TestQuery.java +++ b/src/test/java/com/contentstack/sdk/TestQuery.java @@ -133,7 +133,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err @Test @Order(5) void testNotContainedInField() { - String[] containArray = new String[] { "Roti Maker", "kids dress" }; + String[] containArray = new String[]{"Roti Maker", "kids dress"}; query.notContainedIn("title", containArray); query.find(new QueryResultsCallBack() { @Override @@ -151,7 +151,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err @Test @Order(6) void testContainedInField() { - String[] containArray = new String[] { "Roti Maker", "kids dress" }; + String[] containArray = new String[]{"Roti Maker", "kids dress"}; query.containedIn("title", containArray); query.find(new QueryResultsCallBack() { @Override @@ -262,7 +262,7 @@ void testEntriesWithOr() { query.lessThan("price", 90); Query subQuery = ct.query(); - subQuery.containedIn("discount", new Integer[] { 20, 45 }); + subQuery.containedIn("discount", new Integer[]{20, 45}); ArrayList array = new ArrayList<>(); array.add(query); @@ -294,7 +294,7 @@ void testEntriesWithAnd() { query.lessThan("price", 90); Query subQuery = ct.query(); - subQuery.containedIn("discount", new Integer[] { 20, 45 }); + subQuery.containedIn("discount", new Integer[]{20, 45}); ArrayList array = new ArrayList<>(); array.add(query); @@ -404,7 +404,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err String previous = entries.get(i).getTitle(); // get first string String next = entries.get(i + 1).getTitle(); // get second string if (previous.compareTo(next) < 0) { // compare both if less than Zero then Ascending else - // descending + // descending Assertions.assertTrue(true); } else { Assertions.fail("expected descending, found ascending"); @@ -430,7 +430,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err String previous = entries.get(i).getTitle(); // get first string String next = entries.get(i + 1).getTitle(); // get second string if (previous.compareTo(next) < 0) { // compare both if less than Zero then Ascending else - // descending + // descending Assertions.fail("expected descending, found ascending"); } else { Assertions.assertTrue(true); @@ -480,7 +480,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err @Test @Order(22) void testOnly() { - query.only(new String[] { "price" }); + query.only(new String[]{"price"}); query.find(new QueryResultsCallBack() { @Override public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) { @@ -497,7 +497,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err @Test @Order(23) void testExcept() { - query.except(new String[] { "price" }); + query.except(new String[]{"price"}); query.find(new QueryResultsCallBack() { @Override public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) { @@ -583,7 +583,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err @Test @Order(28) void testTags() { - query.tags(new String[] { "pink" }); + query.tags(new String[]{"pink"}); query.find(new QueryResultsCallBack() { @Override public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) { @@ -877,17 +877,4 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err logger.info("passed..."); } - // @Test @Order(53) - // void testIncludeBranchAPI() throws IllegalAccessException { - // Dotenv dotenv = Dotenv.load(); - // String apiKey = dotenv.get("apiKey"); - // String deliveryToken = dotenv.get("deliveryToken"); - // String env = dotenv.get("env"); - // Config config = new Config(); - // config.setHost("development"); - // Stack stack = Contentstack.stack(apiKey, deliveryToken, env, config); - // query = stack.contentType("menu").query(); - // query.includeBranch().find(null); - // } - } \ No newline at end of file