|
| 1 | +package com.contentstack.sdk; |
| 2 | + |
| 3 | +import okhttp3.ConnectionPool; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | +import java.util.concurrent.TimeUnit; |
| 6 | +import static org.junit.jupiter.api.Assertions.*; |
| 7 | + |
| 8 | +/** |
| 9 | + * Unit tests for CSConnectionPool class. |
| 10 | + * Tests connection pool creation with various configurations. |
| 11 | + */ |
| 12 | +public class TestCSConnectionPool { |
| 13 | + |
| 14 | + @Test |
| 15 | + void testCreateDefaultConnectionPool() { |
| 16 | + CSConnectionPool csConnectionPool = new CSConnectionPool(); |
| 17 | + ConnectionPool pool = csConnectionPool.create(); |
| 18 | + |
| 19 | + assertNotNull(pool); |
| 20 | + } |
| 21 | + |
| 22 | + @Test |
| 23 | + void testCreateConnectionPoolWithParameters() { |
| 24 | + CSConnectionPool csConnectionPool = new CSConnectionPool(); |
| 25 | + int maxIdleConnections = 5; |
| 26 | + long keepAliveDuration = 300; |
| 27 | + TimeUnit timeUnit = TimeUnit.SECONDS; |
| 28 | + |
| 29 | + ConnectionPool pool = csConnectionPool.create(maxIdleConnections, keepAliveDuration, timeUnit); |
| 30 | + |
| 31 | + assertNotNull(pool); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + void testCreateConnectionPoolWithMinimalParameters() { |
| 36 | + CSConnectionPool csConnectionPool = new CSConnectionPool(); |
| 37 | + ConnectionPool pool = csConnectionPool.create(1, 1, TimeUnit.MILLISECONDS); |
| 38 | + |
| 39 | + assertNotNull(pool); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + void testCreateConnectionPoolWithLargeValues() { |
| 44 | + CSConnectionPool csConnectionPool = new CSConnectionPool(); |
| 45 | + ConnectionPool pool = csConnectionPool.create(100, 3600, TimeUnit.SECONDS); |
| 46 | + |
| 47 | + assertNotNull(pool); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + void testCreateConnectionPoolWithDifferentTimeUnits() { |
| 52 | + CSConnectionPool csConnectionPool = new CSConnectionPool(); |
| 53 | + |
| 54 | + ConnectionPool poolSeconds = csConnectionPool.create(5, 60, TimeUnit.SECONDS); |
| 55 | + assertNotNull(poolSeconds); |
| 56 | + |
| 57 | + ConnectionPool poolMinutes = csConnectionPool.create(5, 5, TimeUnit.MINUTES); |
| 58 | + assertNotNull(poolMinutes); |
| 59 | + |
| 60 | + ConnectionPool poolHours = csConnectionPool.create(5, 1, TimeUnit.HOURS); |
| 61 | + assertNotNull(poolHours); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + void testMultipleConnectionPoolCreation() { |
| 66 | + CSConnectionPool csConnectionPool = new CSConnectionPool(); |
| 67 | + |
| 68 | + ConnectionPool pool1 = csConnectionPool.create(); |
| 69 | + ConnectionPool pool2 = csConnectionPool.create(); |
| 70 | + ConnectionPool pool3 = csConnectionPool.create(10, 300, TimeUnit.SECONDS); |
| 71 | + |
| 72 | + assertNotNull(pool1); |
| 73 | + assertNotNull(pool2); |
| 74 | + assertNotNull(pool3); |
| 75 | + assertNotSame(pool1, pool2); |
| 76 | + assertNotSame(pool2, pool3); |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + void testCSConnectionPoolInstantiation() { |
| 81 | + CSConnectionPool csConnectionPool1 = new CSConnectionPool(); |
| 82 | + CSConnectionPool csConnectionPool2 = new CSConnectionPool(); |
| 83 | + |
| 84 | + assertNotNull(csConnectionPool1); |
| 85 | + assertNotNull(csConnectionPool2); |
| 86 | + assertNotSame(csConnectionPool1, csConnectionPool2); |
| 87 | + } |
| 88 | +} |
| 89 | + |
0 commit comments