|
| 1 | +package com.contentstack.sdk; |
| 2 | + |
| 3 | +import org.junit.Before; |
| 4 | +import org.junit.Test; |
| 5 | +import org.junit.runner.RunWith; |
| 6 | +import org.robolectric.RobolectricTestRunner; |
| 7 | + |
| 8 | +import static org.junit.Assert.*; |
| 9 | + |
| 10 | +/** |
| 11 | + * Advanced tests for Config class |
| 12 | + */ |
| 13 | +@RunWith(RobolectricTestRunner.class) |
| 14 | +public class TestConfigAdvanced { |
| 15 | + |
| 16 | + private Config config; |
| 17 | + |
| 18 | + @Before |
| 19 | + public void setUp() { |
| 20 | + config = new Config(); |
| 21 | + } |
| 22 | + |
| 23 | + // ==================== Host Tests ==================== |
| 24 | + |
| 25 | + @Test |
| 26 | + public void testSetHostValid() { |
| 27 | + config.setHost("custom-cdn.contentstack.io"); |
| 28 | + assertNotNull(config); |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + public void testSetHostNull() { |
| 33 | + config.setHost(null); |
| 34 | + assertNotNull(config); |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + public void testSetHostEmpty() { |
| 39 | + config.setHost(""); |
| 40 | + assertNotNull(config); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void testSetHostMultipleTimes() { |
| 45 | + config.setHost("host1.com"); |
| 46 | + config.setHost("host2.com"); |
| 47 | + config.setHost("host3.com"); |
| 48 | + assertNotNull(config); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + public void testSetHostWithProtocol() { |
| 53 | + config.setHost("https://cdn.contentstack.io"); |
| 54 | + config.setHost("http://cdn.contentstack.io"); |
| 55 | + assertNotNull(config); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void testSetHostWithPort() { |
| 60 | + config.setHost("cdn.contentstack.io:8080"); |
| 61 | + assertNotNull(config); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + public void testSetHostWithPath() { |
| 66 | + config.setHost("cdn.contentstack.io/path/to/api"); |
| 67 | + assertNotNull(config); |
| 68 | + } |
| 69 | + |
| 70 | + @Test |
| 71 | + public void testSetHostLongString() { |
| 72 | + StringBuilder longHost = new StringBuilder(); |
| 73 | + for (int i = 0; i < 1000; i++) { |
| 74 | + longHost.append("subdomain."); |
| 75 | + } |
| 76 | + longHost.append("contentstack.io"); |
| 77 | + config.setHost(longHost.toString()); |
| 78 | + assertNotNull(config); |
| 79 | + } |
| 80 | + |
| 81 | + // ==================== Region Tests ==================== |
| 82 | + |
| 83 | + @Test |
| 84 | + public void testSetRegionUS() { |
| 85 | + config.setRegion(Config.ContentstackRegion.US); |
| 86 | + assertNotNull(config); |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | + public void testSetRegionEU() { |
| 91 | + config.setRegion(Config.ContentstackRegion.EU); |
| 92 | + assertNotNull(config); |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + public void testSetRegionAZURE_NA() { |
| 97 | + config.setRegion(Config.ContentstackRegion.AZURE_NA); |
| 98 | + assertNotNull(config); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + public void testSetRegionAZURE_EU() { |
| 103 | + config.setRegion(Config.ContentstackRegion.AZURE_EU); |
| 104 | + assertNotNull(config); |
| 105 | + } |
| 106 | + |
| 107 | + @Test |
| 108 | + public void testSetRegionGCP_NA() { |
| 109 | + config.setRegion(Config.ContentstackRegion.GCP_NA); |
| 110 | + assertNotNull(config); |
| 111 | + } |
| 112 | + |
| 113 | + @Test |
| 114 | + public void testSetRegionNull() { |
| 115 | + config.setRegion(null); |
| 116 | + assertNotNull(config); |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + public void testSetRegionMultipleTimes() { |
| 121 | + config.setRegion(Config.ContentstackRegion.US); |
| 122 | + config.setRegion(Config.ContentstackRegion.EU); |
| 123 | + config.setRegion(Config.ContentstackRegion.AZURE_NA); |
| 124 | + assertNotNull(config); |
| 125 | + } |
| 126 | + |
| 127 | + @Test |
| 128 | + public void testSetRegionAllValues() { |
| 129 | + Config.ContentstackRegion[] regions = Config.ContentstackRegion.values(); |
| 130 | + for (Config.ContentstackRegion region : regions) { |
| 131 | + Config testConfig = new Config(); |
| 132 | + testConfig.setRegion(region); |
| 133 | + assertNotNull(testConfig); |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + // ==================== Branch Tests ==================== |
| 138 | + |
| 139 | + @Test |
| 140 | + public void testSetBranchValid() { |
| 141 | + config.setBranch("development"); |
| 142 | + assertNotNull(config); |
| 143 | + } |
| 144 | + |
| 145 | + @Test |
| 146 | + public void testSetBranchNull() { |
| 147 | + config.setBranch(null); |
| 148 | + assertNotNull(config); |
| 149 | + } |
| 150 | + |
| 151 | + @Test |
| 152 | + public void testSetBranchEmpty() { |
| 153 | + config.setBranch(""); |
| 154 | + assertNotNull(config); |
| 155 | + } |
| 156 | + |
| 157 | + @Test |
| 158 | + public void testSetBranchMultiple() { |
| 159 | + config.setBranch("main"); |
| 160 | + config.setBranch("development"); |
| 161 | + config.setBranch("staging"); |
| 162 | + config.setBranch("production"); |
| 163 | + assertNotNull(config); |
| 164 | + } |
| 165 | + |
| 166 | + @Test |
| 167 | + public void testSetBranchWithSpecialCharacters() { |
| 168 | + config.setBranch("feature/new-feature"); |
| 169 | + config.setBranch("bugfix/issue-123"); |
| 170 | + config.setBranch("release-v1.0.0"); |
| 171 | + assertNotNull(config); |
| 172 | + } |
| 173 | + |
| 174 | + // setEarlyAccess method doesn't exist in Config, skipping these tests |
| 175 | + |
| 176 | + // ==================== Combined Configuration Tests ==================== |
| 177 | + |
| 178 | + @Test |
| 179 | + public void testCompleteConfiguration() { |
| 180 | + config.setHost("custom-cdn.contentstack.io"); |
| 181 | + config.setRegion(Config.ContentstackRegion.EU); |
| 182 | + config.setBranch("development"); |
| 183 | + assertNotNull(config); |
| 184 | + } |
| 185 | + |
| 186 | + @Test |
| 187 | + public void testMultipleConfigInstances() { |
| 188 | + Config config1 = new Config(); |
| 189 | + config1.setHost("host1.com"); |
| 190 | + config1.setRegion(Config.ContentstackRegion.US); |
| 191 | + |
| 192 | + Config config2 = new Config(); |
| 193 | + config2.setHost("host2.com"); |
| 194 | + config2.setRegion(Config.ContentstackRegion.EU); |
| 195 | + |
| 196 | + Config config3 = new Config(); |
| 197 | + config3.setHost("host3.com"); |
| 198 | + config3.setRegion(Config.ContentstackRegion.AZURE_NA); |
| 199 | + |
| 200 | + assertNotNull(config1); |
| 201 | + assertNotNull(config2); |
| 202 | + assertNotNull(config3); |
| 203 | + assertNotEquals(config1, config2); |
| 204 | + } |
| 205 | + |
| 206 | + @Test |
| 207 | + public void testConfigurationOverwrite() { |
| 208 | + config.setHost("initial-host.com"); |
| 209 | + config.setHost("updated-host.com"); |
| 210 | + |
| 211 | + config.setRegion(Config.ContentstackRegion.US); |
| 212 | + config.setRegion(Config.ContentstackRegion.EU); |
| 213 | + |
| 214 | + config.setBranch("branch1"); |
| 215 | + config.setBranch("branch2"); |
| 216 | + |
| 217 | + assertNotNull(config); |
| 218 | + } |
| 219 | + |
| 220 | + @Test |
| 221 | + public void testConfigurationReset() { |
| 222 | + config.setHost("host.com"); |
| 223 | + config.setRegion(Config.ContentstackRegion.US); |
| 224 | + config.setBranch("main"); |
| 225 | + |
| 226 | + // Reset by setting to null/empty |
| 227 | + config.setHost(null); |
| 228 | + config.setRegion(null); |
| 229 | + config.setBranch(null); |
| 230 | + |
| 231 | + assertNotNull(config); |
| 232 | + } |
| 233 | + |
| 234 | + // ==================== Edge Cases ==================== |
| 235 | + |
| 236 | + @Test |
| 237 | + public void testHostWithIPAddress() { |
| 238 | + config.setHost("192.168.1.1"); |
| 239 | + config.setHost("10.0.0.1:8080"); |
| 240 | + config.setHost("127.0.0.1"); |
| 241 | + assertNotNull(config); |
| 242 | + } |
| 243 | + |
| 244 | + @Test |
| 245 | + public void testHostWithIPv6() { |
| 246 | + config.setHost("[2001:db8::1]"); |
| 247 | + config.setHost("[::1]"); |
| 248 | + assertNotNull(config); |
| 249 | + } |
| 250 | + |
| 251 | + @Test |
| 252 | + public void testBranchWithUnicode() { |
| 253 | + config.setBranch("分支"); |
| 254 | + config.setBranch("ブランチ"); |
| 255 | + config.setBranch("가지"); |
| 256 | + assertNotNull(config); |
| 257 | + } |
| 258 | + |
| 259 | + @Test |
| 260 | + public void testBranchWithEmoji() { |
| 261 | + config.setBranch("feature-🚀"); |
| 262 | + config.setBranch("bugfix-🐛"); |
| 263 | + assertNotNull(config); |
| 264 | + } |
| 265 | + |
| 266 | + @Test |
| 267 | + public void testVeryLongBranchName() { |
| 268 | + StringBuilder longBranch = new StringBuilder(); |
| 269 | + for (int i = 0; i < 1000; i++) { |
| 270 | + longBranch.append("branch"); |
| 271 | + } |
| 272 | + config.setBranch(longBranch.toString()); |
| 273 | + assertNotNull(config); |
| 274 | + } |
| 275 | + |
| 276 | + // Removed setEarlyAccess edge case tests - method doesn't exist |
| 277 | + |
| 278 | + @Test |
| 279 | + public void testSequentialConfigurations() { |
| 280 | + for (int i = 0; i < 10; i++) { |
| 281 | + Config testConfig = new Config(); |
| 282 | + testConfig.setHost("host" + i + ".com"); |
| 283 | + testConfig.setBranch("branch" + i); |
| 284 | + assertNotNull(testConfig); |
| 285 | + } |
| 286 | + } |
| 287 | + |
| 288 | + @Test |
| 289 | + public void testConfigWithAllNullValues() { |
| 290 | + Config nullConfig = new Config(); |
| 291 | + nullConfig.setHost(null); |
| 292 | + nullConfig.setRegion(null); |
| 293 | + nullConfig.setBranch(null); |
| 294 | + assertNotNull(nullConfig); |
| 295 | + } |
| 296 | + |
| 297 | + @Test |
| 298 | + public void testConfigWithAllEmptyValues() { |
| 299 | + Config emptyConfig = new Config(); |
| 300 | + emptyConfig.setHost(""); |
| 301 | + emptyConfig.setBranch(""); |
| 302 | + assertNotNull(emptyConfig); |
| 303 | + } |
| 304 | + |
| 305 | + // ==================== Region Enum Tests ==================== |
| 306 | + |
| 307 | + @Test |
| 308 | + public void testRegionEnumValues() { |
| 309 | + Config.ContentstackRegion[] regions = Config.ContentstackRegion.values(); |
| 310 | + assertTrue(regions.length >= 5); |
| 311 | + assertNotNull(regions); |
| 312 | + } |
| 313 | + |
| 314 | + @Test |
| 315 | + public void testRegionEnumValueOf() { |
| 316 | + Config.ContentstackRegion region = Config.ContentstackRegion.valueOf("US"); |
| 317 | + assertNotNull(region); |
| 318 | + assertEquals(Config.ContentstackRegion.US, region); |
| 319 | + } |
| 320 | + |
| 321 | + @Test |
| 322 | + public void testAllRegionEnumsAssignable() { |
| 323 | + config.setRegion(Config.ContentstackRegion.US); |
| 324 | + config.setRegion(Config.ContentstackRegion.EU); |
| 325 | + config.setRegion(Config.ContentstackRegion.AZURE_NA); |
| 326 | + config.setRegion(Config.ContentstackRegion.AZURE_EU); |
| 327 | + config.setRegion(Config.ContentstackRegion.GCP_NA); |
| 328 | + assertNotNull(config); |
| 329 | + } |
| 330 | +} |
| 331 | + |
0 commit comments