From fc86f0619d0aeb20d55d5d5d19e1b88ff9076006 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Thu, 2 May 2024 10:41:26 +0530 Subject: [PATCH 1/5] feat: :sparkles: gcp support implementation --- .../java/com/contentstack/sdk/Config.java | 2 +- src/main/java/com/contentstack/sdk/Stack.java | 5 +++ .../com/contentstack/sdk/TestGcpRegion.java | 36 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/contentstack/sdk/TestGcpRegion.java diff --git a/src/main/java/com/contentstack/sdk/Config.java b/src/main/java/com/contentstack/sdk/Config.java index 5fec119d..e4567afc 100644 --- a/src/main/java/com/contentstack/sdk/Config.java +++ b/src/main/java/com/contentstack/sdk/Config.java @@ -196,7 +196,7 @@ public Config setManagementToken(@NotNull String managementToken) { * The enum Contentstack region. for now contentstack supports [US, EU, AZURE_NA] */ public enum ContentstackRegion { - US, EU, AZURE_NA, AZURE_EU + US, EU, AZURE_NA, AZURE_EU, GCP_NA } } diff --git a/src/main/java/com/contentstack/sdk/Stack.java b/src/main/java/com/contentstack/sdk/Stack.java index 512d9a92..8e54ff0a 100644 --- a/src/main/java/com/contentstack/sdk/Stack.java +++ b/src/main/java/com/contentstack/sdk/Stack.java @@ -63,6 +63,11 @@ protected void setConfig(Config config) { urlDomain = "cdn.contentstack.com"; } config.host = "azure-eu" + "-" + urlDomain; + } else if (region.equalsIgnoreCase("gcp_na")) { + if (urlDomain.equalsIgnoreCase("cdn.contentstack.io")) { + urlDomain = "cdn.contentstack.com"; + } + config.host = "gcp-na" + "-" + urlDomain; } } diff --git a/src/test/java/com/contentstack/sdk/TestGcpRegion.java b/src/test/java/com/contentstack/sdk/TestGcpRegion.java new file mode 100644 index 00000000..faa1b0b5 --- /dev/null +++ b/src/test/java/com/contentstack/sdk/TestGcpRegion.java @@ -0,0 +1,36 @@ +package com.contentstack.sdk; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class TestGcpRegion { + @Test + void testGcpRegionBehaviourGcpNA() { + Config config = new Config(); + Config.ContentstackRegion region = Config.ContentstackRegion.GCP_NA; + config.setRegion(region); + Assertions.assertFalse(config.region.name().isEmpty()); + Assertions.assertEquals("GCP_NA", config.region.name()); + } + + @Test + void testGcpNaRegionBehaviourGcpStack() throws IllegalAccessException { + Config config = new Config(); + Config.ContentstackRegion region = Config.ContentstackRegion.GCP_NA; + config.setRegion(region); + Stack stack = Contentstack.stack("fakeApiKey", "fakeDeliveryToken", "fakeEnvironment", config); + Assertions.assertFalse(config.region.name().isEmpty()); + Assertions.assertEquals("GCP_NA", stack.config.region.name()); + } + + @Test + void testGcpNARegionBehaviourGcpStackHost() throws IllegalAccessException { + Config config = new Config(); + Config.ContentstackRegion region = Config.ContentstackRegion.GCP_NA; + config.setRegion(region); + Stack stack = Contentstack.stack("fakeApiKey", "fakeDeliveryToken", "fakeEnvironment", config); + Assertions.assertFalse(config.region.name().isEmpty()); + Assertions.assertEquals("gcp-na-cdn.contentstack.com", stack.config.host); + + } +} \ No newline at end of file From ff06c271c53f429eaff530beca50c76fe766657c Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Thu, 2 May 2024 10:46:00 +0530 Subject: [PATCH 2/5] test: updated test cases --- src/test/java/com/contentstack/sdk/TestAsset.java | 8 ++++---- src/test/java/com/contentstack/sdk/TestAssetLibrary.java | 4 ++-- src/test/java/com/contentstack/sdk/TestEntry.java | 2 +- src/test/java/com/contentstack/sdk/TestQueryCase.java | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/contentstack/sdk/TestAsset.java b/src/test/java/com/contentstack/sdk/TestAsset.java index 0991b583..259efe83 100644 --- a/src/test/java/com/contentstack/sdk/TestAsset.java +++ b/src/test/java/com/contentstack/sdk/TestAsset.java @@ -39,13 +39,13 @@ public void onCompletion(ResponseType responseType, List assets, Error er assetUid = model.getAssetUid(); Assertions.assertTrue(model.getAssetUid().startsWith("blt")); Assertions.assertEquals("image/jpeg", model.getFileType()); - Assertions.assertEquals("482141", model.getFileSize()); + Assertions.assertEquals("1775299", model.getFileSize()); Assertions.assertEquals("phoenix2.jpg", model.getFileName()); Assertions.assertTrue(model.getUrl().endsWith("phoenix2.jpg")); Assertions.assertTrue(model.toJSON().has("created_at")); Assertions.assertTrue(model.getCreatedBy().startsWith("blt")); Assertions.assertEquals("gregory", model.getUpdateAt().getCalendarType()); - Assertions.assertTrue(model.getUpdatedBy().startsWith("sys")); + Assertions.assertTrue(model.getUpdatedBy().startsWith("blt")); Assertions.assertEquals("", model.getDeletedBy()); } }); @@ -61,13 +61,13 @@ void testNewAssetZOnlyForOrderByUid() { public void onCompletion(ResponseType responseType, Error error) { Assertions.assertTrue(asset.getAssetUid().startsWith("blt")); Assertions.assertEquals("image/jpeg", asset.getFileType()); - Assertions.assertEquals("482141", asset.getFileSize()); + Assertions.assertEquals("1775299", asset.getFileSize()); Assertions.assertEquals("phoenix2.jpg", asset.getFileName()); Assertions.assertTrue(asset.getUrl().endsWith("phoenix2.jpg")); Assertions.assertTrue(asset.toJSON().has("created_at")); Assertions.assertTrue(asset.getCreatedBy().startsWith("blt")); Assertions.assertEquals("gregory", asset.getUpdateAt().getCalendarType()); - Assertions.assertTrue(asset.getUpdatedBy().startsWith("sys")); + Assertions.assertTrue(asset.getUpdatedBy().startsWith("blt")); Assertions.assertNull(asset.getDeleteAt()); Assertions.assertEquals("gregory", asset.getCreateAt().getCalendarType()); Assertions.assertEquals("", asset.getDeletedBy()); diff --git a/src/test/java/com/contentstack/sdk/TestAssetLibrary.java b/src/test/java/com/contentstack/sdk/TestAssetLibrary.java index 6e49a061..937e82c0 100644 --- a/src/test/java/com/contentstack/sdk/TestAssetLibrary.java +++ b/src/test/java/com/contentstack/sdk/TestAssetLibrary.java @@ -24,13 +24,13 @@ public void onCompletion(ResponseType responseType, List assets, Error er Asset model = assets.get(0); Assertions.assertTrue(model.getAssetUid().startsWith("blt")); assertEquals("image/jpeg", model.getFileType()); - assertEquals("482141", model.getFileSize()); + assertEquals("1775299", model.getFileSize()); assertEquals("phoenix2.jpg", model.getFileName()); Assertions.assertTrue(model.getUrl().endsWith("phoenix2.jpg")); Assertions.assertTrue(model.toJSON().has("created_at")); Assertions.assertTrue(model.getCreatedBy().startsWith("blt")); assertEquals("gregory", model.getUpdateAt().getCalendarType()); - Assertions.assertTrue(model.getUpdatedBy().startsWith("sys")); + Assertions.assertTrue(model.getUpdatedBy().startsWith("blt")); assertEquals("", model.getDeletedBy()); logger.info("passed..."); } diff --git a/src/test/java/com/contentstack/sdk/TestEntry.java b/src/test/java/com/contentstack/sdk/TestEntry.java index 3cd0f4ff..d0fb1089 100644 --- a/src/test/java/com/contentstack/sdk/TestEntry.java +++ b/src/test/java/com/contentstack/sdk/TestEntry.java @@ -178,7 +178,7 @@ void entryGetBoolean() { @Test @Order(19) void entryGetJSONArray() { - Object image = entry.getJSONArray("image"); + Object image = entry.getJSONObject("image"); Assertions.assertNotNull(image); logger.info("passed..."); } diff --git a/src/test/java/com/contentstack/sdk/TestQueryCase.java b/src/test/java/com/contentstack/sdk/TestQueryCase.java index 05bdbf13..2943a567 100644 --- a/src/test/java/com/contentstack/sdk/TestQueryCase.java +++ b/src/test/java/com/contentstack/sdk/TestQueryCase.java @@ -542,7 +542,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err Assertions.assertEquals(1, entries.size()); // to add in the coverage code execution Group group = new Group(stack, entries.get(0).toJSON()); - doSomeBackgroundTask(group); +// doSomeBackgroundTask(group); } else { Assertions.fail("Failing, Verify credentials"); } From c0d1e2b6169e74ef316d38350e1c1e8fe8682ee8 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Thu, 2 May 2024 10:58:02 +0530 Subject: [PATCH 3/5] chore: :package: snyk upgrades --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 3863ceef..0a072aa2 100644 --- a/pom.xml +++ b/pom.xml @@ -21,10 +21,10 @@ 3.4.1 3.0.0 3.1.8 - 2.10.0 + 2.11.0 5.0.0-alpha.11 0.8.5 - 1.18.30 + 1.18.32 5.10.1 5.8.0-M1 2.8.8 @@ -36,7 +36,7 @@ 20240303 0.8.7 2.5.3 - 1.2.6 + 1.2.7 From 5227f0ee9a36c68bd080a96e81450a165f998d69 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Thu, 2 May 2024 11:06:49 +0530 Subject: [PATCH 4/5] Merge branch 'next' into feat/cx-72-gcp-support --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index 0a072aa2..71b17c6d 100644 --- a/pom.xml +++ b/pom.xml @@ -270,6 +270,12 @@ sign + + + --pinentry-mode + loopback + + From f5b7d3f07709306f0121b5ae83f48f0562fa27ac Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Thu, 2 May 2024 11:23:59 +0530 Subject: [PATCH 5/5] updated the mentioned change in comment --- src/test/java/com/contentstack/sdk/TestQueryCase.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/contentstack/sdk/TestQueryCase.java b/src/test/java/com/contentstack/sdk/TestQueryCase.java index 2943a567..427bb187 100644 --- a/src/test/java/com/contentstack/sdk/TestQueryCase.java +++ b/src/test/java/com/contentstack/sdk/TestQueryCase.java @@ -542,7 +542,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err Assertions.assertEquals(1, entries.size()); // to add in the coverage code execution Group group = new Group(stack, entries.get(0).toJSON()); -// doSomeBackgroundTask(group); + doSomeBackgroundTask(group); } else { Assertions.fail("Failing, Verify credentials"); } @@ -557,7 +557,7 @@ protected void doSomeBackgroundTask(Group group) { Object titleObj = group.get("title"); String titleStr = group.getString("title"); Boolean titleBool = group.getBoolean("in_stock"); - JSONArray titleJSONArray = group.getJSONArray("image"); + JSONObject titleImageJSONArray = group.getJSONObject("image"); JSONObject titleJSONObject = group.getJSONObject("publish_details"); Object versionNum = group.getNumber("_version"); Object versionInt = group.getInt("_version"); @@ -568,7 +568,7 @@ protected void doSomeBackgroundTask(Group group) { Assertions.assertNotNull(titleObj); Assertions.assertNotNull(titleStr); Assertions.assertNotNull(titleBool); - Assertions.assertNotNull(titleJSONArray); + Assertions.assertNotNull(titleImageJSONArray); Assertions.assertNotNull(titleJSONObject); Assertions.assertNotNull(versionNum); Assertions.assertNotNull(versionInt);