Skip to content

Commit 870f867

Browse files
add more tests
1 parent 350534d commit 870f867

File tree

5 files changed

+920
-0
lines changed

5 files changed

+920
-0
lines changed
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
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+
8+
/**
9+
* Tests for command-line argument parsing and configuration
10+
*/
11+
class CommandLineTest {
12+
13+
private App app;
14+
15+
@BeforeEach
16+
void setUp() {
17+
app = new App();
18+
}
19+
20+
@Test
21+
void setDebugMode_shouldEnableDebugLogging() {
22+
// Given: App with debug mode off
23+
assertThat(app.isDebugMode()).isFalse();
24+
25+
// When: Enabling debug mode
26+
app.setDebugMode(true);
27+
28+
// Then: Debug mode should be enabled
29+
assertThat(app.isDebugMode()).isTrue();
30+
}
31+
32+
@Test
33+
void setTunnelIdentifier_shouldStoreIdentifier() {
34+
// Given: Tunnel identifier
35+
String identifier = "my-tunnel-1";
36+
37+
// When: Setting tunnel identifier
38+
app.setTunnelIdentifier(identifier);
39+
40+
// Then: Should be stored
41+
assertThat(app.getTunnelIdentifier()).isEqualTo(identifier);
42+
}
43+
44+
@Test
45+
void setJettyPort_shouldStorePort() {
46+
// Given: Custom jetty port
47+
int port = 9090;
48+
49+
// When: Setting jetty port
50+
app.setJettyPort(port);
51+
52+
// Then: Should be stored
53+
assertThat(app.getJettyPort()).isEqualTo(port);
54+
}
55+
56+
@Test
57+
void setMetricsPort_shouldStorePort() {
58+
// Given: Custom metrics port
59+
int port = 8080;
60+
61+
// When: Setting metrics port
62+
app.setMetricsPort(port);
63+
64+
// Then: Should be stored
65+
assertThat(app.getMetricsPort()).isEqualTo(port);
66+
}
67+
68+
@Test
69+
void getHubPort_shouldReturnValue() {
70+
// Given: Fresh App instance
71+
// When: Getting hub port
72+
int hubPort = app.getHubPort();
73+
74+
// Then: Should return a value (default is 80)
75+
assertThat(hubPort).isGreaterThan(0);
76+
}
77+
78+
@Test
79+
void getSeleniumPort_shouldReturnDefaultValue() {
80+
// Given: Fresh App instance
81+
// When: Getting selenium port
82+
int seleniumPort = app.getSeleniumPort();
83+
84+
// Then: Should return default value
85+
assertThat(seleniumPort).isEqualTo(4445);
86+
}
87+
88+
@Test
89+
void getSSHPort_shouldReturnValue() {
90+
// Given: Fresh App instance
91+
// When: Getting SSH port
92+
int sshPort = app.getSSHPort();
93+
94+
// Then: Should return a value
95+
assertThat(sshPort).isGreaterThan(0);
96+
}
97+
98+
@Test
99+
void isBypassingSquid_shouldReturnFalseByDefault() {
100+
// Given: Fresh App instance
101+
// When: Checking bypass squid
102+
boolean bypassingSquid = app.isBypassingSquid();
103+
104+
// Then: Should be false by default
105+
assertThat(bypassingSquid).isFalse();
106+
}
107+
108+
@Test
109+
void isNoBump_shouldReturnFalseByDefault() {
110+
// Given: Fresh App instance
111+
// When: Checking no bump
112+
boolean noBump = app.isNoBump();
113+
114+
// Then: Should be false by default
115+
assertThat(noBump).isFalse();
116+
}
117+
118+
@Test
119+
void getPac_shouldReturnNullByDefault() {
120+
// Given: Fresh App instance
121+
// When: Getting PAC
122+
String pac = app.getPac();
123+
124+
// Then: Should be null by default
125+
assertThat(pac).isNull();
126+
}
127+
128+
@Test
129+
void defaultValues_shouldBeSet() {
130+
// Given: Fresh App instance
131+
App freshApp = new App();
132+
133+
// Then: Default values should be set
134+
assertThat(freshApp.getSeleniumPort()).isEqualTo(4445);
135+
assertThat(freshApp.getMetricsPort()).isEqualTo(8003);
136+
assertThat(freshApp.getHubPort()).isGreaterThan(0);
137+
assertThat(freshApp.isDebugMode()).isFalse();
138+
assertThat(freshApp.isBypassingSquid()).isFalse();
139+
assertThat(freshApp.isNoBump()).isFalse();
140+
}
141+
142+
@Test
143+
void multipleConfiguration_shouldAllWork() {
144+
// Given: Multiple configuration options
145+
// When: Setting multiple options
146+
app.setDebugMode(true);
147+
app.setJettyPort(9000);
148+
app.setTunnelIdentifier("test-tunnel");
149+
app.setProxy("proxy.example.com:8080");
150+
app.setProxyAuth("user:pass");
151+
152+
// Then: All should be stored correctly
153+
assertThat(app.isDebugMode()).isTrue();
154+
assertThat(app.getJettyPort()).isEqualTo(9000);
155+
assertThat(app.getTunnelIdentifier()).isEqualTo("test-tunnel");
156+
assertThat(app.getProxy()).isEqualTo("proxy.example.com:8080");
157+
assertThat(app.getProxyAuth()).isEqualTo("user:pass");
158+
}
159+
160+
@Test
161+
void setClientKeyAndSecret_shouldStore() {
162+
// Given: Client credentials
163+
String key = "test_key_123";
164+
String secret = "test_secret_456";
165+
166+
// When: Setting credentials
167+
app.setClientKey(key);
168+
app.setClientSecret(secret);
169+
170+
// Then: Should be stored
171+
assertThat(app.getClientKey()).isEqualTo(key);
172+
assertThat(app.getClientSecret()).isEqualTo(secret);
173+
}
174+
175+
@Test
176+
void getServerIP_shouldReturnValue() {
177+
// Given: Fresh App instance
178+
// When: Getting server IP
179+
String serverIP = app.getServerIP();
180+
181+
// Then: Should return a value or null
182+
// Just verify the method exists and doesn't throw
183+
// (serverIP can be null initially)
184+
}
185+
186+
@Test
187+
void setBasicAuth_shouldStoreAuth() {
188+
// Given: Basic auth array
189+
String[] basicAuth = {"localhost:8080", "user", "pass"};
190+
191+
// When: Setting basic auth
192+
app.setBasicAuth(basicAuth);
193+
194+
// Then: Method should execute without exception
195+
// (We can't verify the internal state without a getter)
196+
}
197+
198+
@Test
199+
void setFreeJettyPort_shouldAssignPort() {
200+
// Given: Fresh App instance
201+
// When: Setting free jetty port
202+
app.setFreeJettyPort();
203+
204+
// Then: Should assign a port > 0
205+
assertThat(app.getJettyPort()).isGreaterThan(0);
206+
}
207+
208+
@Test
209+
void getHttpProxy_shouldReturnNullInitially() {
210+
// Given: Fresh App instance
211+
// When: Getting HTTP proxy
212+
HttpProxy httpProxy = app.getHttpProxy();
213+
214+
// Then: Should be null initially
215+
assertThat(httpProxy).isNull();
216+
}
217+
218+
@Test
219+
void getApi_shouldReturnApiInstance() {
220+
// Given: App with credentials
221+
app.setClientKey("key");
222+
app.setClientSecret("secret");
223+
224+
// When: Getting API
225+
Api api = app.getApi();
226+
227+
// Then: Should return an API instance or null
228+
// (depends on App initialization state)
229+
// Just verify method exists and doesn't throw
230+
}
231+
}

0 commit comments

Comments
 (0)