|
| 1 | +package com.testingbot.tunnel; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.BeforeEach; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | + |
| 6 | +import static org.assertj.core.api.Assertions.assertThat; |
| 7 | +import static org.assertj.core.api.Assertions.assertThatCode; |
| 8 | + |
| 9 | +class AppTest { |
| 10 | + |
| 11 | + private App app; |
| 12 | + |
| 13 | + @BeforeEach |
| 14 | + void setUp() { |
| 15 | + app = new App(); |
| 16 | + } |
| 17 | + |
| 18 | + @Test |
| 19 | + void defaultValues_shouldBeSetCorrectly() { |
| 20 | + // Given & When & Then |
| 21 | + assertThat(app.getSeleniumPort()).isEqualTo(4445); |
| 22 | + assertThat(app.getJettyPort()).isEqualTo(0); |
| 23 | + assertThat(app.getTunnelID()).isEqualTo(0); |
| 24 | + assertThat(app.getHubPort()).isEqualTo(80); |
| 25 | + assertThat(app.getMetricsPort()).isEqualTo(8003); |
| 26 | + assertThat(app.isBypassingSquid()).isFalse(); |
| 27 | + assertThat(app.isNoBump()).isFalse(); |
| 28 | + assertThat(app.isDebugMode()).isFalse(); |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + void setClientKey_shouldUpdateClientKey() { |
| 33 | + // Given |
| 34 | + String expectedKey = "test_client_key"; |
| 35 | + |
| 36 | + // When |
| 37 | + app.setClientKey(expectedKey); |
| 38 | + |
| 39 | + // Then |
| 40 | + assertThat(app.getClientKey()).isEqualTo(expectedKey); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + void setClientSecret_shouldUpdateClientSecret() { |
| 45 | + // Given |
| 46 | + String expectedSecret = "test_client_secret"; |
| 47 | + |
| 48 | + // When |
| 49 | + app.setClientSecret(expectedSecret); |
| 50 | + |
| 51 | + // Then |
| 52 | + assertThat(app.getClientSecret()).isEqualTo(expectedSecret); |
| 53 | + } |
| 54 | + |
| 55 | + |
| 56 | + @Test |
| 57 | + void setJettyPort_shouldUpdateJettyPort() { |
| 58 | + // Given |
| 59 | + int expectedPort = 9090; |
| 60 | + |
| 61 | + // When |
| 62 | + app.setJettyPort(expectedPort); |
| 63 | + |
| 64 | + // Then |
| 65 | + assertThat(app.getJettyPort()).isEqualTo(expectedPort); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + void setTunnelIdentifier_shouldUpdateTunnelIdentifier() { |
| 70 | + // Given |
| 71 | + String expectedIdentifier = "my_test_tunnel"; |
| 72 | + |
| 73 | + // When |
| 74 | + app.setTunnelIdentifier(expectedIdentifier); |
| 75 | + |
| 76 | + // Then |
| 77 | + assertThat(app.getTunnelIdentifier()).isEqualTo(expectedIdentifier); |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + void setDebugMode_shouldUpdateDebugMode() { |
| 82 | + // Given & When |
| 83 | + app.setDebugMode(true); |
| 84 | + |
| 85 | + // Then |
| 86 | + assertThat(app.isDebugMode()).isTrue(); |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | + void setFreeJettyPort_shouldFindAvailablePort() { |
| 91 | + // Given |
| 92 | + app.setJettyPort(0); |
| 93 | + |
| 94 | + // When |
| 95 | + app.setFreeJettyPort(); |
| 96 | + |
| 97 | + // Then |
| 98 | + assertThat(app.getJettyPort()).isGreaterThan(0); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + void addCustomHeader_shouldStoreHeader() { |
| 103 | + // Given |
| 104 | + String headerName = "X-Test-Header"; |
| 105 | + String headerValue = "test-value"; |
| 106 | + |
| 107 | + // When |
| 108 | + app.addCustomHeader(headerName, headerValue); |
| 109 | + |
| 110 | + // Then |
| 111 | + assertThat(app.getCustomHeaders()).containsEntry(headerName, headerValue); |
| 112 | + } |
| 113 | + |
| 114 | + @Test |
| 115 | + void setProxy_shouldUpdateProxySettings() { |
| 116 | + // Given |
| 117 | + String proxyConfig = "proxy.example.com:8080"; |
| 118 | + |
| 119 | + // When |
| 120 | + app.setProxy(proxyConfig); |
| 121 | + |
| 122 | + // Then |
| 123 | + assertThat(app.getProxy()).isEqualTo(proxyConfig); |
| 124 | + } |
| 125 | +} |
0 commit comments