-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
116 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/test/java/net/lacnic/portal/auth/client/PortalHttpClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package net.lacnic.portal.auth.client; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.DefaultHttpClient; | ||
import org.apache.http.params.HttpParams; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class PortalHttpClientTest { | ||
|
||
@Test | ||
void testGetNewHttpClient_returnsConfiguredHttpClient() { | ||
// Call the method | ||
HttpClient httpClient = PortalHttpClient.getNewHttpClient(); | ||
|
||
// Verify that HttpClient is not null | ||
assertNotNull(httpClient); | ||
assertTrue(httpClient instanceof DefaultHttpClient, "Expected instance of DefaultHttpClient"); | ||
|
||
// Check if parameters were set correctly | ||
HttpParams httpParams = httpClient.getParams(); | ||
assertEquals(40000, httpParams.getIntParameter("http.connection.timeout", 0)); | ||
assertEquals(40000, httpParams.getIntParameter("http.socket.timeout", 0)); | ||
assertEquals(40000L, httpParams.getLongParameter("http.conn-manager.timeout", 0)); | ||
} | ||
|
||
@Test | ||
void testGetCloseableHttpClient_returnsConfiguredHttpClient() { | ||
// Call the method | ||
HttpClient httpClient = PortalHttpClient.getCloseableHttpClient(); | ||
|
||
// Verify that HttpClient is not null and is an instance of CloseableHttpClient | ||
assertNotNull(httpClient); | ||
assertTrue(httpClient instanceof CloseableHttpClient, "Expected instance of CloseableHttpClient"); | ||
|
||
// Check if parameters were set correctly | ||
HttpParams httpParams = httpClient.getParams(); | ||
assertEquals(40000, httpParams.getIntParameter("http.connection.timeout", 0)); | ||
assertEquals(40000, httpParams.getIntParameter("http.socket.timeout", 0)); | ||
assertEquals(40000L, httpParams.getLongParameter("http.conn-manager.timeout", 0)); | ||
} | ||
|
||
@Test | ||
void testGetNewHttpClient_fallbackOnException() { | ||
HttpClient httpClient = null; | ||
try { | ||
httpClient = PortalHttpClient.getNewHttpClient(); | ||
} catch (Exception ignored) { | ||
} | ||
|
||
// Verify that HttpClient is not null even if exceptions occur | ||
assertNotNull(httpClient); | ||
assertTrue(httpClient instanceof DefaultHttpClient); | ||
} | ||
|
||
@Test | ||
void testGetCloseableHttpClient_fallbackOnException() { | ||
HttpClient httpClient = null; | ||
try { | ||
httpClient = PortalHttpClient.getCloseableHttpClient(); | ||
} catch (Exception ignored) { | ||
} | ||
|
||
// Verify that HttpClient is not null even if exceptions occur | ||
assertNotNull(httpClient); | ||
assertTrue(httpClient instanceof CloseableHttpClient); | ||
} | ||
} |