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+ }
0 commit comments