Skip to content

Commit 705d3f8

Browse files
feat: Separate unit/API tests and enhance integration test coverage
- Configure Surefire to run API tests (*IT.java) by default - Add 25+ new integration tests (GcpRegion, GlobalFields, Taxonomy) - Update send-report.sh for automated Slack reporting - Add maven-surefire-report-plugin for HTML reports API tests: mvn clean test Unit tests: mvn clean test -Dtest='Test*' jacoco:report
1 parent 9b43007 commit 705d3f8

23 files changed

+1267
-69
lines changed

pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,16 @@
271271
</executions>
272272
</plugin>
273273

274+
<!-- Surefire Plugin for API Tests -->
274275
<plugin>
275276
<groupId>org.apache.maven.plugins</groupId>
276277
<artifactId>maven-surefire-plugin</artifactId>
277278
<version>2.22.2</version>
278279
<configuration>
280+
<!-- Run only API tests (*IT.java) by default -->
281+
<includes>
282+
<include>**/*IT.java</include>
283+
</includes>
279284
<skipTests>true</skipTests>
280285
</configuration>
281286
</plugin>
@@ -294,6 +299,10 @@
294299
<groupId>org.apache.maven.plugins</groupId>
295300
<artifactId>maven-gpg-plugin</artifactId>
296301
<version>1.6</version>
302+
<configuration>
303+
<!-- Allow skipping via -Dgpg.skip=true -->
304+
<skip>${gpg.skip}</skip>
305+
</configuration>
297306
<executions>
298307
<execution>
299308
<id>sign-artifacts</id>

src/test/java/com/contentstack/sdk/TestAsset.java renamed to src/test/java/com/contentstack/sdk/AssetIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
1010
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
11-
class TestAsset {
11+
class AssetIT {
1212

13-
private final Logger logger = Logger.getLogger(TestAsset.class.getName());
13+
private final Logger logger = Logger.getLogger(AssetIT.class.getName());
1414
private String assetUid;
1515
private final Stack stack = Credentials.getStack();
1616

src/test/java/com/contentstack/sdk/TestAssetLibrary.java renamed to src/test/java/com/contentstack/sdk/AssetLibraryIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
1111
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
12-
class TestAssetLibrary {
13-
private final Logger logger = Logger.getLogger(TestAssetLibrary.class.getName());
12+
class AssetLibraryIT {
13+
private final Logger logger = Logger.getLogger(AssetLibraryIT.class.getName());
1414
private final Stack stack = Credentials.getStack();
1515

1616

src/test/java/com/contentstack/sdk/TestAzureRegion.java renamed to src/test/java/com/contentstack/sdk/AzureRegionIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.junit.jupiter.api.Assertions;
44
import org.junit.jupiter.api.Test;
55

6-
class TestAzureRegion {
6+
class AzureRegionIT {
77

88
@Test
99
void testAzureRegionBehaviourUS() {

src/test/java/com/contentstack/sdk/TestContentType.java renamed to src/test/java/com/contentstack/sdk/ContentTypeIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
1010
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
11-
class TestContentType {
11+
class ContentTypeIT {
1212

13-
private final Logger logger = Logger.getLogger(TestContentType.class.getName());
13+
private final Logger logger = Logger.getLogger(ContentTypeIT.class.getName());
1414
private final Stack stack = Credentials.getStack();
1515

1616
@Test

src/test/java/com/contentstack/sdk/TestContentstack.java renamed to src/test/java/com/contentstack/sdk/ContentstackIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import java.util.logging.Logger;
99

1010
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
11-
class TestContentstack {
11+
class ContentstackIT {
1212

1313
private String API_KEY, DELIVERY_TOKEN, ENV;
14-
private final Logger logger = Logger.getLogger(TestContentstack.class.getName());
14+
private final Logger logger = Logger.getLogger(ContentstackIT.class.getName());
1515

1616
@BeforeAll
1717
public void initBeforeTests() {

src/test/java/com/contentstack/sdk/TestEntry.java renamed to src/test/java/com/contentstack/sdk/EntryIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
1212
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
13-
class TestEntry {
13+
class EntryIT {
1414

15-
private final Logger logger = Logger.getLogger(TestEntry.class.getName());
15+
private final Logger logger = Logger.getLogger(EntryIT.class.getName());
1616
private String entryUid = Credentials.ENTRY_UID;
1717
private final Stack stack = Credentials.getStack();
1818
private Entry entry;
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package com.contentstack.sdk;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
6+
public class GcpRegionIT {
7+
@Test
8+
void testGcpRegionBehaviourGcpNA() {
9+
Config config = new Config();
10+
Config.ContentstackRegion region = Config.ContentstackRegion.GCP_NA;
11+
config.setRegion(region);
12+
Assertions.assertFalse(config.region.name().isEmpty());
13+
Assertions.assertEquals("GCP_NA", config.region.name());
14+
}
15+
16+
@Test
17+
void testGcpNaRegionBehaviourGcpStack() throws IllegalAccessException {
18+
Config config = new Config();
19+
Config.ContentstackRegion region = Config.ContentstackRegion.GCP_NA;
20+
config.setRegion(region);
21+
Stack stack = Contentstack.stack("fakeApiKey", "fakeDeliveryToken", "fakeEnvironment", config);
22+
Assertions.assertFalse(config.region.name().isEmpty());
23+
Assertions.assertEquals("GCP_NA", stack.config.region.name());
24+
}
25+
26+
@Test
27+
void testGcpNARegionBehaviourGcpStackHost() throws IllegalAccessException {
28+
Config config = new Config();
29+
Config.ContentstackRegion region = Config.ContentstackRegion.GCP_NA;
30+
config.setRegion(region);
31+
Stack stack = Contentstack.stack("fakeApiKey", "fakeDeliveryToken", "fakeEnvironment", config);
32+
Assertions.assertFalse(config.region.name().isEmpty());
33+
Assertions.assertEquals("gcp-na-cdn.contentstack.com", stack.config.host);
34+
35+
}
36+
37+
@Test
38+
void testGcpEURegionBehaviourGcpStack() throws IllegalAccessException {
39+
Config config = new Config();
40+
Config.ContentstackRegion region = Config.ContentstackRegion.GCP_EU;
41+
config.setRegion(region);
42+
Stack stack = Contentstack.stack("fakeApiKey", "fakeDeliveryToken", "fakeEnvironment", config);
43+
Assertions.assertFalse(config.region.name().isEmpty());
44+
Assertions.assertEquals("GCP_EU", stack.config.region.name());
45+
Assertions.assertEquals("gcp-eu-cdn.contentstack.com", stack.config.host);
46+
}
47+
48+
@Test
49+
void testGcpRegionWithMultipleConfigs() throws IllegalAccessException {
50+
// Test NA region
51+
Config configNA = new Config();
52+
configNA.setRegion(Config.ContentstackRegion.GCP_NA);
53+
Stack stackNA = Contentstack.stack("apiKey1", "token1", "env1", configNA);
54+
Assertions.assertEquals("GCP_NA", stackNA.config.region.name());
55+
Assertions.assertEquals("gcp-na-cdn.contentstack.com", stackNA.config.host);
56+
57+
// Test EU region
58+
Config configEU = new Config();
59+
configEU.setRegion(Config.ContentstackRegion.GCP_EU);
60+
Stack stackEU = Contentstack.stack("apiKey2", "token2", "env2", configEU);
61+
Assertions.assertEquals("GCP_EU", stackEU.config.region.name());
62+
Assertions.assertEquals("gcp-eu-cdn.contentstack.com", stackEU.config.host);
63+
}
64+
65+
@Test
66+
void testGcpRegionConfigNotNull() {
67+
Config config = new Config();
68+
Config.ContentstackRegion region = Config.ContentstackRegion.GCP_NA;
69+
config.setRegion(region);
70+
Assertions.assertNotNull(config.region);
71+
Assertions.assertNotNull(config.region.name());
72+
}
73+
74+
@Test
75+
void testGcpNARegionHostFormat() throws IllegalAccessException {
76+
Config config = new Config();
77+
config.setRegion(Config.ContentstackRegion.GCP_NA);
78+
Stack stack = Contentstack.stack("testKey", "testToken", "testEnv", config);
79+
String host = stack.config.host;
80+
Assertions.assertTrue(host.contains("gcp"));
81+
Assertions.assertTrue(host.contains("contentstack.com"));
82+
Assertions.assertTrue(host.endsWith(".com"));
83+
}
84+
85+
@Test
86+
void testGcpEURegionHostFormat() throws IllegalAccessException {
87+
Config config = new Config();
88+
config.setRegion(Config.ContentstackRegion.GCP_EU);
89+
Stack stack = Contentstack.stack("testKey", "testToken", "testEnv", config);
90+
String host = stack.config.host;
91+
Assertions.assertTrue(host.contains("gcp"));
92+
Assertions.assertTrue(host.contains("eu"));
93+
Assertions.assertTrue(host.contains("contentstack.com"));
94+
}
95+
96+
@Test
97+
void testRegionNameNotEmpty() {
98+
Config.ContentstackRegion gcpNA = Config.ContentstackRegion.GCP_NA;
99+
Config.ContentstackRegion gcpEU = Config.ContentstackRegion.GCP_EU;
100+
Assertions.assertFalse(gcpNA.name().isEmpty());
101+
Assertions.assertFalse(gcpEU.name().isEmpty());
102+
Assertions.assertNotEquals(gcpNA.name(), gcpEU.name());
103+
}
104+
}

src/test/java/com/contentstack/sdk/TestGlobalFields.java renamed to src/test/java/com/contentstack/sdk/GlobalFieldsIT.java

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.junit.jupiter.api.Test;
77
import static org.junit.jupiter.api.Assertions.*;
88

9-
public class TestGlobalFields {
9+
public class GlobalFieldsIT {
1010

1111
private GlobalFieldsModel globalFieldsModel;
1212
private final Stack stack = Credentials.getStack();
@@ -65,4 +65,51 @@ public void onCompletion(GlobalFieldsModel globalFieldsModel, Error error) {
6565
}
6666
});
6767
}
68+
69+
@Test
70+
void testGlobalFieldSetHeader() throws IllegalAccessException {
71+
GlobalField globalField = stack.globalField("test_uid");
72+
globalField.setHeader("custom-header", "custom-value");
73+
assertNotNull(globalField.headers);
74+
assertTrue(globalField.headers.containsKey("custom-header"));
75+
assertEquals("custom-value", globalField.headers.get("custom-header"));
76+
}
77+
78+
@Test
79+
void testGlobalFieldRemoveHeader() throws IllegalAccessException {
80+
GlobalField globalField = stack.globalField("test_uid");
81+
globalField.setHeader("test-header", "test-value");
82+
assertTrue(globalField.headers.containsKey("test-header"));
83+
84+
globalField.removeHeader("test-header");
85+
assertFalse(globalField.headers.containsKey("test-header"));
86+
}
87+
88+
@Test
89+
void testGlobalFieldIncludeBranch() throws IllegalAccessException {
90+
GlobalField globalField = stack.globalField("test_uid");
91+
globalField.includeBranch();
92+
assertNotNull(globalField.params);
93+
assertTrue(globalField.params.has("include_branch"));
94+
assertEquals(true, globalField.params.get("include_branch"));
95+
}
96+
97+
@Test
98+
void testGlobalFieldIncludeSchema() throws IllegalAccessException {
99+
GlobalField globalField = stack.globalField();
100+
globalField.includeGlobalFieldSchema();
101+
assertNotNull(globalField.params);
102+
assertTrue(globalField.params.has("include_global_field_schema"));
103+
assertEquals(true, globalField.params.get("include_global_field_schema"));
104+
}
105+
106+
@Test
107+
void testGlobalFieldChainedMethods() throws IllegalAccessException {
108+
GlobalField globalField = stack.globalField();
109+
globalField.includeBranch().includeGlobalFieldSchema();
110+
111+
assertTrue(globalField.params.has("include_branch"));
112+
assertTrue(globalField.params.has("include_global_field_schema"));
113+
assertEquals(2, globalField.params.length());
114+
}
68115
}

src/test/java/com/contentstack/sdk/TestLivePreview.java renamed to src/test/java/com/contentstack/sdk/LivePreviewIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
/**
1818
* The type Config testcase.
1919
*/
20-
public class TestLivePreview {
20+
public class LivePreviewIT {
2121

22-
private static final Logger logger = Logger.getLogger(TestLivePreview.class.getName());
22+
private static final Logger logger = Logger.getLogger(LivePreviewIT.class.getName());
2323
private static Config config;
2424

2525
/**

0 commit comments

Comments
 (0)